0
votes

I am trying to dispaly multiple graphs using scilab but it is not working at all My code is python based Python: import matplotlib.pyplot as plt import numpy as np

g = 9.81; v0 = 30; ax = 0; x0 = 0; az = -g; z0 = 0;
for i in np.linspace(0.5,9,20):
  theta = i*10*np.pi/180
  vx0 = v0*np.cos(theta)
  vz0 = v0*np.sin(theta)
  t=np.linspace(0,2*vz0/g,100)
  x =vx0*t+x0
  z =0.5*az*t**2+vz0*t+z0
  plt.plot(x,z)

This is scilab code:

g = 9.81; v0 = 30; ax = 0; x0 = 0; az = -g; z0 = 0;
for i=0.5:9:20 t=linspace(0,2*v0*sin(i*10*%pi/180)/g,100) 
    x=v0*cos(i*10*%pi/180)*t+x0 
    z=0.5*az*t**2+v0*sin(i*10*%pi/180)*t+z0 
    plot(x,z) 
    ;end 

My goal is to obtain this: https://imgur.com/dlDIKNx

2
What do you mean by "not working" : it plots something, thus, I guess it's not what you are expecting. Can you describe what you expect? If you want multiple graph ,you need subplot (to subdivise your figure), or scf() top open a plot at each occurence of your loop - Marvin

2 Answers

2
votes

Scilab syntax is very close to you python syntax.

A few fixes to you python code will get you a suited scilab code :

g = 9.81; v0 = 30; ax = 0; x0 = 0; az = -g; z0 = 0;
colorindex=1;
for i=linspace(0.5,9,20)
      theta = i*10*%pi/180
  vx0 = v0*cos(theta)
  vz0 = v0*sin(theta)
  t=linspace(0,2*vz0/g,100)
  x =vx0*t+x0
  z =0.5*az*t**2+vz0*t+z0
  plot2d(x,z,colorindex)
  colorindex=colorindex+1;
end 

There is still little issue with the 'enveloppe' (or whatever you call it), but I think you have now clues to fix it.

1
votes

You can get the 'enveloppe' by adding at the end of the @Marvin 's code:

vx0 = v0
vz0 = 0
t=linspace(0,sqrt(-(-v0/az)**2+2*v0**2/az^2),100)
x =vx0*t+x0
z =0.5*az*t**2 + 0.5*az*(-v0/az)**2-v0*(v0/az)
plot2d(x,z,colorindex)