I want to plot multiple functions using for loop, but it always fails to load all of them and could not plot any functions.
For example:
set multiplot layout 2,2
set xrange [-pi:pi]
set yrange [-1:1]
f1(x)=sin(x)
f2(x)=cos(x)
f3(x)=sinh(x)
f4(x)=cosh(x)
plot for [i=1:4] sprintf("f%d(x)",i)
unset multiplot
and it says:
"data.plt" line 11: warning: Cannot find or open file "f1(x)"
"data.plt" line 11: warning: Cannot find or open file "f2(x)"
"data.plt" line 11: warning: Cannot find or open file "f3(x)"
"data.plt" line 11: warning: Cannot find or open file "f4(x)"
"data.plt" line 11: warning: Cannot find or open file "f5(x)"
"data.plt" line 11: warning: Cannot find or open file "f6(x)"
"data.plt" line 11: No data in plot
However, if I try to plot all of the funcitons one by one, it somehow works. For example:
set multiplot layout 3,2
set xrange [-pi:pi]
set yrange [-1:1]
f1(x)=sin(x)
f2(x)=cos(x)
f3(x)=sinh(x)
f4(x)=cosh(x)
plot f1(x)
plot f2(x)
plot f3(x)
plot f4(x)
unset multiplot
This can load all of functions without getting any errors.
Why does this happen, and how can I plot multiple functions using for loop? Since I use a string data when I write the name of the functions, that might be causing the problem, but even if so, I don't know any other ways.