I can't understand why the following lines (in gnuplot 5.0, under fedora) :
set samples 1000
f(x) = ( 1e-1 + 1/100 - sqrt( (1e-1 + 1/100)2 - 4x(1-x)*1e-2 ) )/2
set xrange [0:1]
plot f(x) w l ls 3 lw 2 title 'f'
lead to a linear plot when it should be curved (these same lines work perfectly fine with scilab, for instance).
I've been trying to solve that for a couple of days now, without success... when
f(x) = x(1-x)
or
f(x) = sqrt(x(1-x))
it works fine: no linear segment but curved stuff as expected...
Do I do something wrong or is there a bug somewhere ??
Thanks for any help !!
Marc
PS - all double star used as power operator seem to be erased in the message : the syntax is actually correct...
Last edit: marc bletry 2018-09-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On Wednesday, 19 September 2018 12:11:18 marc bletry wrote:
Hi,
I can't understand why the following lines :
set samples 1000
f(x) = ( 1e-1 + 1/100 - sqrt( (1e-1 + 1/100)2 - 4x(1-x)*1e-2 ) )/2
set xrange [0:1]
plot f(x) w l ls 3 lw 2 title 'f'
lead to a linear plot when it should be curved (these same lines work perfectly fine with scilab, for instance).
Gnuplot uses integer arithmetic for integer values.
So 1/100 is 0.
You want real-valued arithmetic so you must place decimal points
after your constants:
Note: integers are promoted to reals in a mixed operation so
strictly speaking not all of the added decimal points are
necessary. But it's a good idea to get in the habit.
Ethan
Do I do something wrong or is there a bug somewhere ??
Thanks for any help !!
Marc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I can't understand why the following lines (in gnuplot 5.0, under fedora) :
set samples 1000
f(x) = ( 1e-1 + 1/100 - sqrt( (1e-1 + 1/100)2 - 4x(1-x)*1e-2 ) )/2
set xrange [0:1]
plot f(x) w l ls 3 lw 2 title 'f'
lead to a linear plot when it should be curved (these same lines work perfectly fine with scilab, for instance).
I've been trying to solve that for a couple of days now, without success... when
f(x) = x(1-x)
or
f(x) = sqrt(x(1-x))
it works fine: no linear segment but curved stuff as expected...
Do I do something wrong or is there a bug somewhere ??
Thanks for any help !!
Marc
PS - all double star used as power operator seem to be erased in the message : the syntax is actually correct...
Last edit: marc bletry 2018-09-19
On Wednesday, 19 September 2018 12:11:18 marc bletry wrote:
Gnuplot uses integer arithmetic for integer values.
So 1/100 is 0.
You want real-valued arithmetic so you must place decimal points
after your constants:
f(x) = ( 1e-1 + 1./100. - sqrt( (1e-1 + 1./100.)2 - 4.x(1-x)*1e-2 ) )/2.
Note: integers are promoted to reals in a mixed operation so
strictly speaking not all of the added decimal points are
necessary. But it's a good idea to get in the habit.
Hi Ethan,
It worked ! Thank you so much !!
Regards,
Marc