Question: I have the following code below. I can run the code and shot at the target just fine with how it is. I am using

I have the following code below. I can run the code and shot at the target just fine with how it is. I am using MATLAB. I cannot figure out how to incorporate the random "wind" in the x direction and drag coefficient "cd" in the x and y direction without breaking the code. I have to use Euler's method. Any help would be great. Thanks

%Euler's Method

%Initial conditions and setup

%Projectile motion

v0= input('Initial velocity(m/s): ');

a= input('Angle of projection(in degrees): ');

h=.01;

a=a*pi/180;

cd=.1;

m=1.5;

wind= (-10 + 20*rand(1));

g=9.8; %acceleration due to gravity in m/s^2

x=randi(3);

y=randi(3);

% plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)

% hold all;

td=2*v0*sin(a)/g; %total time

x1=0;

y1=0;

figure('color','white');

for t=0:h:td+h

plot(x,y,'bo')

plot(x1,y1,'o','MarkerFaceColor','b','MarkerSize',8)

hold all

xlim([0 6]);

ylim([0 6]);

xlabel('Distance in meter');

ylabel('Height in meter');

getframe;

x1=x1+(h*v0*cos(a)); %Euler's method for x

y1=y1+h*(v0*sin(a)-g*t); %Euler's method for y

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!