Thursday, November 1, 2012

SciLab - Projectile Motion


//********************** Projectile motion *************************
//************************ By Mahesha MG ***************************
v0=100;            //Initial velocity  in m/s
a= 10;            //Angle of projection(in degrees)
h= 0.01;          //Time step (in seconds)
a=a*3.14/180;    //Conversion to radian
g=9.8;          //acceleration due to gravity in m/s^2
xmax=v0^2*sin(2*a)/g;
ymax=v0^2*sin(a)^2/(2*g);
td=2*v0*sin(a)/g;           //total time
x1(1)=0;
y1(1)=0;
i=2;
for t=0:h:td
    x1(i)=x1(i-1)+h*v0*cos(a);      //Euler's method for x
    y1(i)=y1(i-1)+h*(v0*sin(a)-g*t);//Euler's method for y
    i=i+1;
end
plot(x1,y1)

1 comment:

  1. i want to make the target bounce (when y=0)
    can you help me with the algorithm?

    ReplyDelete