Search code examples
plotgnuplotparametric-equations

How do I plot a function with different values of various parameters on gnuplot?


I want to plot this parametric funtion

 x(t)=a+(n/w)*(cos(w*t)-1)-((g/w**2)*sin(l)-m/w)*(sin(w*t)+(g*t/w)*sin(l))

 y(t)=b+((g/w**2)*sin(l)-m/w)*(cos(w*t)-1)+(n/w)*sin(w*t)  

But I have various parameters a,b,m,n,w,k,g y I want to vary a,b,m,n,w,k parameters. g=7

I don't know how do it.

However i intended:

plot for [a=1:0],[b=1:0],[n=0:1],[m=1:0],[g=7:7],[w=2*pi*3:2*pi*2] x(t),y(t)

I appreciate your help. thanks!


Solution

  • For what regards multiple for in a single plot command, the syntax is documented in the inline help of gnuplot

     Nested iteration is supported:
    
           set for [i=1:9] for [j=1:9] label i*10+j sprintf("%d",i*10+j) at i,j
    

    E.g.,

    gnuplot> plot for[a=0:1] for[b=0:1] 1+a*x+b*x*x
    

    plot for[a=0:1] for[b=0:1] 1+a*x+b*x*x


    You could do now what you want except for a further problem: in gnuplot numeric loops variables have only integer values, e.g.,

    gnuplot> plot for [s=3.2:9.3:2.9] x title sprintf("%f", s)
    

    plot for [s=3.2:9.3:2.9] x title sprintf("%f", s)

    so your loop on w is impossible, you have to devise a different strategy.

    With the provision that I don't know what value you want to assign to l (I've used l=1) and also that I don't know the step on w, here it is a possible implementation where the tricks are ❶ define a function that gives you the values of w in terms of an integer variable and ❷ define x and y also in terms of this auxiliary variable

    gnuplot> set parametric
    gnuplot> w(k) = 2*pi*k
    gnuplot> x(t, k)=a+(n/w(k))*(cos(w(k)*t)-1)-((g/w(k)**2)*sin(l)-m/w(k))*(sin(w(k)*t)+(g*t/w(k))*sin(l))
    gnuplot> y(t, k) = b + ((g/w(k)**2)*sin(l)-m/w(k))*(cos(w(k)*t)-1)+(n/w(k))*sin(w(k)*t)
    gnuplot> g = 7 ; l = 1
    gnuplot> plot for[a=0:1] for[b=0:1] for[m=0:1] for[n=0:1] for[k=2:3] x(t,k), y(t,k) title sprintf("%d,%d,%d,%d,%d", a,b,n,m,k)
    

    strange plots