Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Example code provided function systemEuler() % sample code f % given y\'\' + p(t

ID: 3769806 • Letter: E

Question

Example code provided

function systemEuler()

% sample code f

% given y'' + p(t)y' + q(t)y = f(t,y), approximate y
% -- --------------------------------------------------------------------

t_0 = 0; % set initial time
t_f = 100; % set final time
y_0 = [2,3]; % set initial condition

% set stepsize h
h = 0.01;

y(:,1) = y_0; %initialize y to y_0
t = t_0: h : t_f; % create a vector of t-values

% -- Euler method
for j = 1:length(t)-1
y(:,j+1) = y(:,j) + h*f1(t(j),y(:,j)); % update y
end % end for

Yh = y(1,end); %%% save the last value of $y$
figure(1), plot(t,y(1,:)) %%% plot y from t = 0 to t = t_f
xlabel('t'), ylabel('y'), title('y(t), Euler method')
% -- --------------------------------------
function f = f1(t,y) % specify function f here

f = [0 1; -5/4 -1]*y + [0;3*cos(t)]; %% test problem

2.1. Test problem. First run the code systemEuler.m for the IVP y'' + y' + (5/4) y = 3 cos(t), y(0) = 2, y'(0) = 3, from t = 0 to t = 100. (4) Solve the second order IVP by hand and write down why the numerical solution with h = 1/100 does or does not agree with the analytical solution you found.

2.2. Improved Euler. Now implement an improved Euler method to approximate the solution to (4), and verify your results agree with the Euler method. Describe how you chose to verify the results agree.

2.3. Beats and resonance. Consider the second order IVP y 00 + 4y = cos(t), y(0) = 0, y0 (0) = 0, from t = 0 to t = 100. (5) Solve the second order IVP by hand for 6= 0. You should determine the natural frequency 0 from your analytical solution. (1) Run your Euler and improved Euler codes with = 1.7, 1.8, 1.9, 1.95, 1.99 and discuss your findings. You should include in your report plots of whichever solutions you find relevant. (2) Experiment to find the largest value of h for which Euler and improved Euler produce qualitatively similar results for = 1.7. What is the largest value of h for which the two methods give similar results for = 1.9? Discuss the relative advantages of the two methods.

Explanation / Answer

The characteristic equation is: r 2 + 2 0 = 0, or r = ±0i. Therefore, uh = C1 cos(0t) + C2 sin(0t) Using the Method of Undetermined Coefficients, up = A cos(t) + B sin(t), and we put that into the DE: 2 0u = A2 0 cos(t) +B2 0 sin(t) u 00 = A2 cos(t) B2 sin(t) F0 cos(t) = A( 2 0 2 ) cos(t) +B( 2 0 2 ) sin(t)

Therefore, A = F0 2 0 2 B = 0 so that the overall solution is: u(t) = C1 cos(0t) + C2 sin(0t) + F0 2 0 2 cos(t) Put in the initial conditions u(0) = 0 and u 0 (0) = 0 to see that C1 = F0 2 02 and C2 = 0.

The part that changes is the particular part of the solution- We have to multiply by t: Let up = At cos(0t) + Btsin(0t). Then: 2 0up = (A2 0 t ) cos(0t) +(B2 0 t ) sin(0t) u 00 p = (A2 0 t + 2B0) cos(0t) +(B2 0 t 2Aw) sin(0t) F0 cos(0t) = 2B0 cos(0t) 2A0 sin(0t) Therefore, B = F0 20 and A = 0, so that u(t) = C1 cos(0t) + C2 sin(0t) + F0 20 tsin(0t)

Taking into account the initial conditions, we get C1 = C2 = 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote