Reputation: 29
I would like to know how to manipulate parametric 1-D functions. For instance I want to plot the gaussian for differente values of the parameter a: f(x)=exp(-a*(x-1)**2)
I know that I can create different functions f(x) for many values of a, but I wonder if there is a way to plot this function for a=1,2,3, etc.
Thanks.
Upvotes: 0
Views: 1011
Reputation: 25093
Using the following commands
gnuplot> f(x) = a*x
gnuplot> plot for [a = 1:3:1] f(x) title sprintf("a=%d",a)
I get the following plot
You may want to read the descriptions you can get by the following commands
gnuplot> help for
The `plot`, `splot`, `set` and `unset` commands may optionally contain an
iteration for clause. This has the effect of [...]
and
gnuplot> help sprintf
`sprintf("format",var1,var2,...)` applies standard C-language format specifiers
to multiple arguments and returns the resulting string. If you want to
use gnuplot's own format specifiers, you must instead call `gprintf()`.
For information on sprintf format specifiers, please see standard C-language
documentation or the unix sprintf man page.
HTH
Upvotes: 1
Reputation: 7627
Yes, just define your function so that it takes the variable parameter as input:
f(x,a)=exp(-a*(x-1)**2)
And then loop over it. It can be done in a sequence ("a from 1 to 3 at intervals of 1"):
plot for [a=1:3:1] f(x,a) t "a = ".a
Or using a list of values:
plot for [a in "1 2 3"] f(x,a) t "a = ".a
Upvotes: 3