Chart of function exponential - delphi-2010

I am trying to create a line graph of an exponential function:
j:=IWcmbxCriterionName.ItemIndex;
p1a:=(-5000)*0.001;
p1c:= -(Exp(P1a * Min[j])) / (Exp(P1a * Max[j]) - Exp(P1a * Min[j]));
p1b := (1 - P1c) / Exp(P1a * Max[j]);
k1 := Max[j];
i1 := Min[j];
while i1 <= k1 do
begin
Serie1.AddXY(i1, P1b * Exp(p1a * (i1)) + p1c,'',clWebBLUE);
i1 := i1 + 0.01;
end;
chart1.BottomAxis.Maximum:=k1;
chart1.BottomAxis.Minimum:= min[j];
chart1.UndoZoom;
but the serie1 not appear on the graph! Can someone can help me?

Remove the lines where you set bottom axis min. and max. and try to set i to automatic just in case those values are wrong:
Chart1.BottomAxis.Automatic:=True;
If the problem persists please send us a simple example project we can run "as-is" to reproduce the problem here. You can post your files at our upload page.

Related

Mathematica's ListLinePlot in wxMaxima

I have the following functions:
P[t_] := P[t] = P[t-1] +a*ED[t-1];
ED[t_] := ED[t] = DF[t] + DC[t];
DF[t_] := DF[t] = b (F - P[t]);
DC[t_] := DC[t] = c (P[t] - F);
And the following parameters:
a=1;
c=0.2;
b = 0.75;
F=100;
In Mathematica I use the function "ListLinePlot" in order to plot P[t] and F:
ListLinePlot[{Table[P[t], {t, 0, 25}], Table[F, {t, 0, 25}]}, PlotStyle → {Black, Red},Frame → True, FrameLabel → {"time", "price"}, AspectRatio → 0.4, PlotRange → All]
How can I do this in wxMaxima? Is there a similar function or an alternative to ListLinePlot?
This is my attempt in wxMaxima:
P[t] := P[t-1] + a * ED[t-1];
ED[t] := DF[t] + DC[t];
DF[t] := b*[F-P[t]];
DC[t] := c*[P[t]-F];
a=1;
c=0.2;
b=0.75;
F=100;
And then I tried:
draw2d(points(P[t], [t,0,25]))
The plotted function should look like this:
OK, I've adapted the code you showed above. This works for me. I'm working with Maxima 5.44 on macOS.
P[t] := P[t-1] + a * ED[t-1];
ED[t] := DF[t] + DC[t];
DF[t] := b*(F-P[t]);
DC[t] := c*(P[t]-F);
a:1;
c:0.2;
b:0.75;
F:100;
P[0]: F + 1;
Pt_list: makelist (P[t], t, 0, 25);
load (draw);
set_draw_defaults (terminal = qt);
draw2d (points_joined = true, points(Pt_list));
Notes. (1) There needs to be a base case for the recursion on P. I put P[0]: F + 1. (2) Assignments are : instead of =. Note that x = y is a symbolic equation instead of an assignment. (3) Square brackets [ ] are only for subscripts and lists. Use parentheses ( ) for grouping expressions. (4) Syntax for draw2d is a little different, I fixed it up. (I put a default for terminal since the built-in value is incorrect for Maxima on macOS; if you are working on Linux or Windows, you can omit that.)
EDIT: Try this to draw a horizontal line as well.
draw2d (points_joined = true, points(Pt_list),
color = red, points([[0, F], [25, F]]),
yrange = [F - 1, P[0] + 1]);

Calculation of sound level in dB

I was never good in math, so I need help how to convert linear value to dB.
First I show you how I calculated the linear value from -24dB.
var dB, linearLevel: integer;
begin
dB := -24;
linearLevel := Round( 1/exp( 2.30258509299 * (abs(dB)/20) ) *32767);
end;
Where 1/exp( 2.30258509299 * (abs(-24)/20) ) ; is normalized value.
For conversion to sample value I use 1/exp(...)*32767
My problem is here: conversion back
I was told to use formula 20*log10(linearLevel). So I tried to create it but my result is 18 instead 24 (or -24) dB.
linearValue := 2067; // the result of the formula above
db := round( exp( 20*2.30258509299*(linearLevel / 32767) ) );
How to calculate the dB?
If
linearLevel := Round( 1/exp( 2.30258509299 * (abs(dB)/20) ) * 32767);
we lose information due to the rounding (in the language of mathematics, the Round function is not injective). So given a linearLevel value, it is impossible to get back the original dB value. Therefore, let us consider
linearLevel := 1/exp( 2.30258509299 * (abs(dB)/20) ) * 32767;
instead. This implies
linearLevel / 32767 := 1/exp( 2.30258509299 * (abs(dB)/20) )
and
32767 / linearLevel := exp( 2.30258509299 * (abs(dB)/20) )
and
ln(32767 / linearLevel) := 2.30258509299 * (abs(dB)/20)
and
ln(32767 / linearLevel) / 2.30258509299 := abs(dB)/20
and
20 * ln(32767 / linearLevel) / 2.30258509299 := abs(dB).
Here we again have an issue, since the absolute value function is not injective. If abs(dB) is 7, we cannot possibly tell if dB is 7 or -7.
But if we assume that dB is non-positive, we finally have
dB = -20 * ln(32767 / linearLevel) / 2.30258509299.
Simplifications
Since 2.30258509299 is ln(10), this is
dB = -20 * ln(32767 / linearLevel) / ln(10).
But log10(x) = ln(x) / ln(10), so we can write
dB = -20 * Log10(32767 / linearLevel)
where the Log10 function is found in the Math unit.
Also, using the law a log(b) = log(b^a) in the case a = -1, we can even write
dB = 20 * Log10(linearLevel / 32767).

Delphi FormatFloat

I have an output txtfile with some float numbers and I like to print in different formats, y try with:
FormatFloat('00000;000.0;00.00', val)
FormatFloat('00.00;000.0;00000', val)
But I take wrong outputs. What I need is:
If val < 10 then output like '00.00'
If 10 < val < 100 then output like '000.0'
If val > 100 then output like '00000'
It's a huge amount of float values, so, I need a low processing solution and I think more conditionals will slow down the application. ¿Any advice?
Thank you
Using conditional tests to sort the values into separate outputs is not going to affect performance in a significant way. The format process is far more elaborate. One important thing about optimization is to only walk that path if you can measure a performance hit in the actual code.
if (val < 10) then
s := FormatFloat('00.00',val)
else
if (val < 100) then
s := FormatFloat('000.0',val)
else
s := FormatFloat('00000',val);
Also consider using the thread-safe FormatFloat with a supplied FormatSettings variable.
I suppose that conditionals would work faster, but consider this sketch (care about out-of-range values):
const
FormatString: array[-1..2] of string = ('0.000', '0.00', '0.0', '0');
var
x: Double;
i: integer;
begin
x := 0.314;
for i := 1 to 4 do begin
Memo1.Lines.Add(FormatFloat(FormatString[Floor(Log10(x))], x));
x := x * 10;
end;
0.314
3.14
31.4
314

Generate random number in a float range

How we can generate randomize number between a range in the Float numbers (in delphi xe3) ?
For example, randomize number between [0.10 to 0.90].
I need give results like:
[ 0.20 , 0.32 , 0.10 , 0.50 ]
Thanks for solutions....
Another option is to use RandomRange (returns: AFrom <= r < ATo) as follow:
RandomRange(10, 90 + 1) / 100
or
RandomRange(10, 90 + 1) * 0.01
will return numbers in the range of 0.10 to 0.90 (including 0.90)
var
float : Double;
float := Random; // Random float in range: 0 <= float < 1
float := 0.1 + float*0.8 // 0.1 <= float < 0.9
To initialize the Random number generator, make a single call to Randomizeor set the RandSeed parameter before calling the Random function for the first time.
Not doing so, generates the same sequence every time you run the program. Note however, that this sequence is not guaranteed when recompiling for another compiler version.
Try this:
function RandomRangeF(min, max: single): single;
begin
result := min + Random * (max - min);
end;
This is a bit cheeky but here goes: Depends how many numbers you want after the floating point. For example, if you want 1 number, you could generate in the 100 - 999 range and then divide by 10. Or 1000 - 9999 and divide by 100.

How to use Condition in Delphi Breakpoint properties

I found that a nested loop fails when some particular condition is reached, somehow when I = 1, J = 3 and k = 5
I tried to right click on the breakpoint and in the condition I set
(I = 1) and (J = 3) AND (K = 5)
anyway the breakpoint doesn't stop...
What is wrong?
I've just tried that in D2007 and it works fine. what version are you using?
procedure TForm85.FormClick(Sender: TObject);
var i,j,k : integer;
z:integer;
begin
for i := 0 to 10 do
for j := 0 to 10 do
for k := 0 to 10 do
BEGIN
z := z + i * j * k; // breakpoint on this line.
END;
ShowMessage(IntToStr(z));
end;
Have you considered that the breakpoint may not be reached because the condition is not being met?
You did add the breakpoint as a Breaking breakpoint I assume.
To verify this
open the Breakpoint properties window
click on Advanced
make sure the Break checkbox is checked.
May be according to your code
(I = 1) and (J = 3) AND (K = 5)
may never get this values at same time
Set breakpoint on a line of code before the condition is met and step through with F8?

Resources