2

I have written a code where i am trying to simulate n numbers of bubbles but my problem is that i have to hard code my function as you can see that i am using fx, fy, fz then fx1, fy1, fz1 and fx2, fy2, fz2.

Instead of that i want to create my functions using a loop and also want to plot them using a loop.Is there any way to do that.

Here is the code :

w=1.0
set isosample 50
set parametric
set urange [0:2*pi]
set vrange [-pi/2:pi/2]
do for [w=1:50]  {
  fx(v,u,w)  = w*cos(v)*cos(u)
  fy(v,u,w)  = w*cos(v)*sin(u)
  fz(v,w)    = w*sin(v) 
  fx1(v,u,w) = 20+w*cos(v)*cos(u)
  fy1(v,u,w) = 30+w*cos(v)*sin(u)
  fz1(v,w)   = 30+w*sin(v) 
  fx2(v,u,w) = 40+w*cos(v)*cos(u)
  fy2(v,u,w) = 60+w*cos(v)*sin(u)
  fz2(v,w)   = 60+w*sin(v) 
  splot fx(v,u,w), fy(v,u,w), fz(v,w), fx1(v,u,w), fy1(v,u,w), fz1(v,w), fx2(v,u,w), fy2(v,u,w), fz2(v,w)  with pm3d
}
2
  • Can you be a bit clearer about what you are trying to achieve? It seems like you want to generate the functions on the fly, in that case eval might be helpful. This question/answer shows an example of this Commented Feb 23, 2018 at 8:50
  • I am trying to give loop while plotting my functions. Commented Feb 26, 2018 at 5:50

1 Answer 1

3

You can use the splot for syntax of gnuplot:

set isosample 50
set parametric
set urange [0:2*pi]
set vrange [-pi/2:pi/2]

fx(v,u)  = 2.0*d + w*cos(v)*cos(u)
fy(v,u)  = 3.0*d + w*cos(v)*sin(u)
fz(v)    = 3.0*d + w*sin(v)   

do for [w=1:50]  {
  splot for [d = 0:20:10] fx(v,u), fy(v,u), fz(v) with pm3d
}

I think you want to read these gnuplot help pages: help for and help for loops. Depending on your needs, you might also want to read help word and for example this question or help array if you are on gnuplot 5.2.

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

2 Comments

Thank you very much for the reply.it has solved my problem.
@RajneeshSharma: Please accept the answer that best solves your issue (click the checkmark beside the answer)

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.