Hey all!
Im doing a porject where i find the projectile motion of a object in the air and im having several issues.
- i want my time to not be going from 0 to 10,000 with an interval of .01. This takes up space but im not sure how else i could do this.
- I want the user when they input air resistance to be able to just click enter and it'll automatically set air=.5
- the code with the fprint works well but im having some problems making the plot . Height3 kept on giving me an array error and that was only fixed when I changed 0 to .01.
- Also with the previous problem, height3 (which is supposed to be the vertical height when the object is above height 0) has an error and doesnt become a matrix. Im trying to plot it with time2 and they both have to be the same size matrix.
I guess my biggest problem is I want my code to work for small and large velocities and with smaller velocities my code will not work so I'm trying to make it work. Im guessing a For function will work better, but i just learned those so im not super confident.
clear , clcg=9.8;ang=input('Enter incident angle: ');if (ang<=0) disp('Illegal Input')endv=input('Enter speed(m/s): ');if (v<=0) disp('Illegal Input')endair=input('Enter air resitiance (Will otherwise be .5): ');if air<=0,' '; air=.5;endvx0=v*cosd(ang);vy0=v*sind(ang);t=(0:.01:10000);height=vy0*t-.5*g*t.^2;land=find(height>=0);time=(land(end)-1)/100;dist=vx0*time;height2=vy0*time-.5*g*time.^2;fprintf('Distance is %g m \n',dist);fprintf('Max Height is %g m \n',height2);fprintf('Time was %g sec \n ',time);time2=(0:.001:time);height3=height(.01:time2);plot(height3,time2)
Best Answer