Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Show matlab code in this problem with given code. and results 1+ 4. Use both modified Euler's and Runge - Kutta Methods to find the
Show matlab code in this problem with given code. and results
1+ 4. Use both modified Euler's and Runge - Kutta Methods to find the solutions of the following equations. Use the initial conditions of y(0)=0. Print a table of the numerical results and plot the approximated solution y. Compare the approximated results with the analytic solutions (you can use MATLAB to find the analytical solution) (25 pts)). 1 y(t) = y = f ( tanga) %Modified Euler's Method clear all; clc; t = 0; y = 1; h = .1; N = 10; for n = 1:N tnp1 = t +h; yp = f_euler(t,y); ybarnp1 = y + h*yp; Z ybarnp1p = f_euler(tnp1, ybarnp1); y = y + (h/2)*(yp + ybarnp1p); Qe(n,:) = [n ty]; t = tnp1; end Qe Janni =ython I har = f ( trois grand baly 't y! nti %Function function ( Eul_val ] = f_euler( t,y) Eul_val = t*y; end %Runge-Ketta Method t = 0; y = 1; h = 0.1; N = 10; for n = 1:N k1 = h*RG(t,y); TRUTURE k2 = 1* RG(t+h/2,y +(1/2)*k1); k3 = h* RG(t+h/2,y +(1/2)*k2); k4 = h*RG(t+h/2,y + k3); y = y + (1/6)*(k1+2*k2+2*k3+k4); t=t+h Qrn,:) = [n ty]; end Qr %Function function ( RG_val ] = RG(ty) RG_Val = thy end %Analytical Solutions Y_1stD - 'Dy-y*t'; y_init = 'y(0) == 1'; Y_analytical = dsolve(y_1stD,y_init,'t') 1+ 4. Use both modified Euler's and Runge - Kutta Methods to find the solutions of the following equations. Use the initial conditions of y(0)=0. Print a table of the numerical results and plot the approximated solution y. Compare the approximated results with the analytic solutions (you can use MATLAB to find the analytical solution) (25 pts)). 1 y(t) = y = f ( tanga) %Modified Euler's Method clear all; clc; t = 0; y = 1; h = .1; N = 10; for n = 1:N tnp1 = t +h; yp = f_euler(t,y); ybarnp1 = y + h*yp; Z ybarnp1p = f_euler(tnp1, ybarnp1); y = y + (h/2)*(yp + ybarnp1p); Qe(n,:) = [n ty]; t = tnp1; end Qe Janni =ython I har = f ( trois grand baly 't y! nti %Function function ( Eul_val ] = f_euler( t,y) Eul_val = t*y; end %Runge-Ketta Method t = 0; y = 1; h = 0.1; N = 10; for n = 1:N k1 = h*RG(t,y); TRUTURE k2 = 1* RG(t+h/2,y +(1/2)*k1); k3 = h* RG(t+h/2,y +(1/2)*k2); k4 = h*RG(t+h/2,y + k3); y = y + (1/6)*(k1+2*k2+2*k3+k4); t=t+h Qrn,:) = [n ty]; end Qr %Function function ( RG_val ] = RG(ty) RG_Val = thy end %Analytical Solutions Y_1stD - 'Dy-y*t'; y_init = 'y(0) == 1'; Y_analytical = dsolve(y_1stD,y_init,'t')Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started