I am trying to plot a gaussian wave cos((0.1*x)*exp(-sqrt(x)/2*sqrt(t)))
in gnuplot. I define a range for t
by:
set trange [0.1:2]
plot cos((0.1*x)*exp(-sqrt(x)/2*sqrt(t)))
but it stops with undefined variable t
error. What should I do?
The plot command works with functions of a single variable. Thus it will fill in the x
value, but when it encounters t
, it doesn't know what to do with that.
If you had previously defined t
, it would use that value. Thus
t = 0.5
plot cos((0.1*x)*exp(-sqrt(x)/2*sqrt(t)))
will work just fine, using a value of 0.5 for t.
If you wish to plot multiple curves for a range of t values, you can use the plot for
syntax doing something like
plot for [t=0:10] cos((0.1*x)*exp(-sqrt(x)/2*sqrt(0.1+t*0.19)))
which will plot the curve for a range of values. As the for syntax works with integers, we need to use an integer value for the loop and then calculate the value for the formula (0.1+t*0.19
ranges from 0.1 to 2 as required when t ranges from 0 to 10). You can label the key using
plot for [t=0:10] cos((0.1*x)*exp(-sqrt(x)/2*sqrt(0.1+t*0.19))) title sprintf("t=%f",0.1+t*0.19)
Setting a range will only work with variables that the plot command understands. As t
isn't one of them (except in parametric mode), the range command doesn't do anything in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With