Problem A crossbow bolt is shot straight upward from the ground with an initial
ID: 3210101 • Letter: P
Question
Problem A crossbow bolt is shot straight upward from the ground with an initial velocity of 49m/s. Because of linear air resistance, its velocity function u = satisfies the initial value problem =-0.01,-9.8, u(0) = 49. (a) Use Euler's method to approximate u(t) for 0 t 10 using both N = 100 and N = 200 subintervals. Display the results at intervals of 1 second. Do the two approximations each rounded to four decimal places agree both with the exact solution? (b) Redo (a) using the Runge-Kutta method. Note: The absolute error is defined to be lerct Bapprorl The absolute relative error is The percentage relative error is Unmu-arer"! × 100. To submit a) Your work showing how you generated at least one table from (a) or (b). b) The four tables showing comparisons and errors committed using these methods.
Explanation / Answer
clc;
clear all;
f=@(t,y)-0.04*y-9.8;
a=0;% lower limit
b=10;% upper limit
N=1000; % umber pf steps
h=(b-a)/N; % step size
t=a:h:b;
y0=49 %initila condition
y_eul(1)=y0;
% Euler method
for i=1:N
y_eul(i+1)=y_eul(i)+h*f(t(i),y_eul(i));
end
%RK4
y_rk4(1)=y0;
for i=1:N
k1=h*f(t(i),y_rk4(i));
k2=h*f(t(i)+(h/2),y_rk4(i)+(k1/2));
k3=h*f(t(i)+(h/2),y_rk4(i)+(k2/2));
k4=h*f(t(i)+(h),y_rk4(i)+(k3));
y_rk4(i+1)=y_rk4(i)+(1/6)*(k1+2*k2+2*k3+k4);
end
plot(t,y_eul)
hold on
plot(t,y_rk4)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.