thyme
thyme

Reputation: 428

Using "plot for" in gnuplot to vary parameters

I want to use the plot for feature in gnuplot to plot functions with varying parameters. Here an example

par = "1 2" #two values for the parameter
f(x,a) = sin(a*x)
g(x,a) = cos(a*x)
plot for [i=1:words(par)]  g(x, word(par,i)), f(x, word(par,i))

What I expect is the plotting of the four functions g(x,1), g(x,2, f(x,1), and f(x,2).

But for whatever reason only three functions are plotted, namely: g(x,1), g(x,2, and f(x,2).

This seems completely arbitrary to me.

Can someone help me out?

Upvotes: 1

Views: 111

Answers (1)

Sébastien Guarnay
Sébastien Guarnay

Reputation: 126

You have to repeat the for condition:

plot for [i=1:words(par)]  g(x, word(par,i)), for [i=1:words(par)] f(x, word(par,i))

Upvotes: 1

Related Questions