0

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.

1
  • Be careful to distinguish "parametric functions" from "functions with parameters". The first refers to plots such as x = cos(t), y = sin(t) (plotted with set parametric), the second is of the type you ask about. Commented Feb 10, 2015 at 8:29

2 Answers 2

3

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

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

enter image description here

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.