Using Euler's Method for projectile motion

57 次查看(过去 30 天)
Problem statement: Write a program that employs the Euler method to compute the solution to the freely falling object. That is, calculate 𝑣 as a function of time. Consider different starting velocities over a time range from 𝑡 = 0 to 𝑡 = 10 s.
I'm not sure how to set up my time interval from 0-10 sec. I'm guessing "for j = t(1):dt:tf ". But not fully sure how to proceed. Any help would be appreciated. Thnak you.
What I have so far:
clear;
N = 100; % points to be taken
g = 9.8; % acceleration due to gravity (m/s^2)
dt = 0.01; % time step for time range of 1-10 sec.
theta = input('Angle of projection(in degrees): '); % Allows user to input
h = input('Initial height (in meters): ');
v_0 = input('Initial velocity (in m/s): ');
% Initial conditions below
x(1) = 0; % intial x position (m)
y(1) = h; % intial y position (m)
t(1) = 0; % inital time (s)
tf = 10; % final time (s)
v(1) = v_0; % initial velocity (m/s)
v_x = v_0*cos(theta); % "x" component of the velocity
v_y = v_0*sin(theta); % "y" component of the velocity
v_x(1) = v_x;
v_y(1) = v_y;
n = 1;
while n < N
% for statement here?
v(n+1)=sqrt((v_x(n)^2)+(v_y(n)^2));
v_x(n+1) = v_x(n);
v_y(n+1) = v_y(n) - g*dt;
x(n+1) = x(n) + v_x(n)*dt;
y(n+1) = y(n) + v_y(n)*dt;
if y(n+1)<0
n = N;
else
n = n+1;
end
end

采纳的回答

Alan Stevens
Alan Stevens 2022-11-2
A little more like this? (I've used arbitrary values for initial conditions etc.)
N = 200; % points to be taken
g = 9.8; % acceleration due to gravity (m/s^2)
dt = 0.01; % time step for time range of 1-10 sec.
theta = 45; %input('Angle of projection(in degrees): '); % Allows user to input
h = 1; %input('Initial height (in meters): ');
v_0 = 5; %input('Initial velocity (in m/s): ');
% Initial conditions below
x(1) = 0; % intial x position (m)
y(1) = h; % intial y position (m)
t(1) = 0; % inital time (s)
tf = N*dt; % final time (s)
v(1) = v_0; % initial velocity (m/s)
v_x = v_0*cos(theta); % "x" component of the velocity
v_y = v_0*sin(theta); % "y" component of the velocity
v_x(1) = v_x;
v_y(1) = v_y;
n = 1;
for n = 1:N
v(n+1)=sqrt((v_x(n)^2)+(v_y(n)^2));
v_x(n+1) = v_x(n);
v_y(n+1) = v_y(n) - g*dt;
x(n+1) = x(n) + v_x(n)*dt;
y(n+1) = y(n) + v_y(n)*dt;
t(n+1) = t(n) + dt;
if y(n+1)<0
break
end
end
plot(x,y),grid
xlabel('x'),ylabel('y')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assembly 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by