Question: I need the following program edited and finished in MatLab, thank you. % Eulers, Heun, Midpoint R-K (Second Order) and Ralston R-K (Second Order) method

I need the following program edited and finished in MatLab, thank you.

I need the following program edited and finished in MatLab, thank you.

% Eulers, Heun, Midpoint R-K (Second Order) and Ralston R-K (Second Order)

% Eulers, Heun, Midpoint R-K (Second Order) and Ralston R-K (Second Order) method clear variables %clears the workspace(RAM) clc %clear commans window close all %close any figures % First Order ODE: dy/dt = ? % Step size and create grid values for t %user input for h h = input('Enter Step Size, h= '); %h = 1; t = ?:h:?; % Fill in the ? %Initial Condition y_e(1) = ?; % Fill in the ? y_h(1)=y_e(1); y_Mid_RK(1)=y_e(1); y_Rals_RK(1)=y_e(1); exact(1)=y_e(1); %Initial output (plot) variables y_e = zeros(size(t)); y_h = zeros(size(t)); y_Mid_RK = zeros(size(t)); y_Rals_RK = zeros(size(t)); exact = zeros(size(t)); dy_dt=0; % for i = 1:(length(t)-1) %Calculate derivative t_i=t(i); %Euler Solution %Evaluation of slope at current time t_i and y_e(i), fill the code below dy_dt= %Write the Euler Equation for next y, fill the code below y_e(i+1) = y_e(i)+ ; %---------------------------------------------------------------------------- %Once Euler solution above is ok, remove %{ line 36 below and %} line 52 down %below to make Heun code active %{ % Heun Solution %Evaluation of slope dy_dt at current time t_i and y_h(i), fill the code below dy_dt_start=; %Predict next y using Euler Equation. Need to use dy_dt_start in below %equation, fill the code below y_next_euler= y_h(i) + ; %Next time t_next=t_i+h; %Evaluate slope dy_dt_next at next y using Euler solution above, %y_next_euler, and next time, t_next, in the equation below, fill the code below dy_dt_end = ?; %Correct next y usng Heun solution on the basis of dy_dt_start and %dy_dt_end slopes obtained above, in the equation below, fill the code below y_h(i+1) = y_h(i) + ; % Remove %} below to Make Heun code active %} %------------------------------------------------------------------------- %Once Heun solution above is ok, remove %{ line 56 below and %} line 69 down below %to make MidPoint code active %{ % Second Order R-K: Midpoint Method %Evaluate k1 at current time t_i and y_Mid_RK(i), fill the code below k1=?; %Time at half way between current time and next time t1=t_i+(h/2); %Evaluate y=y1 at time t1, fill the code below y1=y_Mid_RK(i)+; %Evaluate k2 at t1 and y1, fill the code below k2=; % Next y by Midpoint Method, fill the code below y_Mid_RK(i+1)=y_Mid_RK(i)+; % Remove %} below to Make MidPoint code active %} %------------------------------------------------------------------------- %Once Midpoint solution above is ok, remove %{ line 73 below and %} line 86 down %below to make Ralston code active %{ %Second Order R-K: Ralston Method %Evaluate k1 at current time t_i and y_Rals_RK(i), fill the code below k1=; %Time at (3/4)rth between current time and next time t1=t_i+(0.75*h); %Evaluate y=y1 at time t1, fill the code below y1=y_Rals_RK(i)+; %Evaluate k2 at t1 and y1, fill the code below k2=?; % fill the code below y_Rals_RK(i+1)=y_Rals_RK(i)+; % Remove %} below to Make Ralston code active %} %------------------------------------------------------------------------ %Once Ralston solution above is ok, remove %{ line 90 below and %} line 97 down %below to make exact solution calculation active %{ %Exact Solution %Evaluate your analytical y solution at time t_e=t_i+h te=t_i+h; %Plug te for time in your exact (analytical) equation below exact(i+1) = ; % Remove %} below to Make exact solution calculation active %} %--------------------------------------------------------------------- %Once exact solution above is ok, remove %{ line 101 below and %} line 111 down %below to make absolute error calculation active %{ %Absolute Euler Error in percentage based on y_e(i+1) and y_e(i) E_e(i+1)=; %Absolute Heun Error in percentage based on y_h(i+1) and y_h(i) E_h(i+1)=; %Absolute Midpoint Error in percentage based on y_Mid_RK(i+1) and y_Mid_RK(i) E_mid(i+1)=; %Absolute Ralston Error in percentage based on y_Rals(i+1) and y_Rals(i) E_rals(i+1)=; % Remove %} below to make error calculation active %} %----------------------------------------------------------------------- %End of time loop end %------------------------------------------------------------------------ %Plotting starts %Once error calculations above is ok, remove %{ line 119 below %to make plotting codes active %{ %disp(num2str(y),num2str(y_h),num2str(exact)) dispstr = 'Numerical Solution for h= '; disp(dispstr); disp(num2str(h)); disp(num2str(exact)) disp(num2str(y_e)) disp(num2str(y_h)) disp(num2str(y_Mid_RK)) disp(num2str(y_Rals_RK)) figure(1) plot(t,exact,t,y_e,'-*',t,y_h,'-o',t,y_Mid_RK,'--*',t,y_Rals_RK,'--o') grid on xlabel('distance x in inch') ylabel('y') title('Numerical Solution of First Order ODE') gtext('Exact') %gtext('Euler') gtext('Heun') gtext('MP_RK') gtext('Rals_RK') %plot(t,y) %display errors dispstr1 = 'Numerical Errors '; disp(dispstr1); disp(num2str(E_e)) disp(num2str(E_h)) disp(num2str(E_mid)) disp(num2str(E_rals)) figure(2) plot(t,E_h,t,E_mid,'-.',t,E_rals,'-o') grid on xlabel('distance x in inch') ylabel('% Numerical Errors') title('% Numerical Errors in ODE Solutions') gtext('Heun') gtext('MP_RK') gtext('Rals_RK') figure(3) plot(t,E_e) grid on xlabel('distance x in inch') ylabel('% Numerical Errors') title('% Numerical Errors in Euler Solutions') %

Problem#2-33 points (a) Use my Matlab (template) program to solve the following first order ODE by the following Numerical Methods (a) Euler (b) Heun (c) 2nd Order Midpoint Runge-Kutta (R-K) (d) 2nd Order Ralston Runge-Kutta (R-K). Submit your Matlab program and command line output (Matlab results) in MS-Word or pdf format in iLearn. Program accecpts command line user input for step size, h. Vary the step size, h Ax-0.2, 0.1 and 0.01 over 0sxs 2. Initial condition, y(x-0) 1 dy ?? (b) Obtain the closed form or analytical solution of above first ODE (c) Calculate the % numerical error, E, in Matlab based on analytical solution. (d) Your Matlab program must be able to plot the results for (i) all the 4 numerical methods, analytical solution in one window (figure 1) (ii) % numerical errors (in another window (figure 2)). E, when h-02. 0.1 and 0.01 over 0sxs 2. Problem#2-33 points (a) Use my Matlab (template) program to solve the following first order ODE by the following Numerical Methods (a) Euler (b) Heun (c) 2nd Order Midpoint Runge-Kutta (R-K) (d) 2nd Order Ralston Runge-Kutta (R-K). Submit your Matlab program and command line output (Matlab results) in MS-Word or pdf format in iLearn. Program accecpts command line user input for step size, h. Vary the step size, h Ax-0.2, 0.1 and 0.01 over 0sxs 2. Initial condition, y(x-0) 1 dy ?? (b) Obtain the closed form or analytical solution of above first ODE (c) Calculate the % numerical error, E, in Matlab based on analytical solution. (d) Your Matlab program must be able to plot the results for (i) all the 4 numerical methods, analytical solution in one window (figure 1) (ii) % numerical errors (in another window (figure 2)). E, when h-02. 0.1 and 0.01 over 0sxs 2

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!