Question
Hello

These are a math problems that need to solve by MATLAB as code
Thank you !
Initial Value Problem #1: Consider the following first order ODE: dy-p-3 from to 2.2 with y() I (a) Solve with Eulers explicit method using h04. (b) Solve with the midpoint method using h 0.4. (c) Solve with the classical fourth-order Runge-Kutta method using 0.4 analytical solution of the ODE is,·? solution and the numerical solution at the points where the numerical solution is determined +In each part, calculate the error between the true Initial Value Problem #2: Consider the differential equation for mass-spring-damper system as shown: where k2 - 48 N/m/kg, y07s, x(0)0, and d0.2 m/s. Solve the ODE over the interva dt dx 031s5 s, and pla (two separate figures on one page) as a function of t. 1.) Write the second order ODE as a system of first order ODEs 2.) Solve for step size t = 0.1 seconds 3.) Provide brief discussion of the physics (derivation of governing equation) and explanation of the results
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: More than one question asked. So I did first part.

Copyable Code:

Part (a):

function.m

%function for EulerImplicit method
function ns = EulerImplicitMethod(func, tinitial, h, tend, y1)
%define the analytical solution equation
ys = 1/6*((5/(tend^3)) + tend^3);
%assign y = y1
y = y1;
%find the final solution using for loop
for t = tinitial:h:tend-h
%using euler implicit method
ss = func(t, y);
y = y + h * ss;
end
y;
%find the error between the final solution and analytical solution
error = ys - y;
%display the result
fprintf('Final solution: %.4f\n', y)
fprintf('Analytical solution: %.4f\n', ys)
fprintf('Error: %.4f\n', error)

main.m:

%assign given dy/dt
func = @(t, y) t^2 - (3*y)/t
%initial value of t
tinitial = 1;
%assign h value
h = 0.4;
%assign t end value
tend = 2.2;
%assign y(1)
y1 = 1;
%call EulerImplicitMethod() function
EulerImplicitMethod(func, tinitial, h, tend, y1);

Part (b)

function.m

%function for MidPointMethod method
function ns = MidPointMethod(func, tinitial, h, tend, y1)
%define the analytical solution equation
ys = 1/6*((5/(tend^3)) + tend^3);
%assign y = y1
y = y1;
%find the final solution using for loop
for t = tinitial:h:tend-h
%using midpoint method
ss = func(t, y);
ss1 = func(t+h/2, y+h*ss/2);
y = y + h * ss1;
end
y;
%find the error between the final solution and analytical solution
error = ys - y;
%display the result
fprintf('Final solution: %.4f\n', y)
fprintf('Analytical solution: %.4f\n', ys)
fprintf('Error: %.4f\n', error)

main.m:

%assign given dy/dt

func = @(t, y) t^2 - (3*y)/t
%initial value of t
tinitial = 1;
%assign h value
h = 0.4;
%assign t end value
tend = 2.2;
%assign y(1)
y1 = 1;
%call MidPointMethod() function
MidPointMethod(func, tinitial, h, tend, y1);

Part (c)

function.m

%function for RungeKuttaMethod
function ns = RungeKuttaMethod(func, tinitial, h, tend, y1)
%define the analytical solution equation
ys = 1/6*((5/(tend^3)) + tend^3);
%assign y = y1
y = y1;
%find the final solution using for loop
for t = tinitial:h:tend-h
%using runge kutta method
ss = func(t, y);
ss1 = func(t+h/2, y+h*ss/2);
ss2 = func(t+h/2, y+h*ss1/2);
ss3 = func(t+h, y+h*ss2);
y = y + h * (ss + 2*ss1 + 2*ss2 + ss3)/6;
end
y;
%find the error between the final solution and analytical solution
error = ys - y;
%display the result
fprintf('Final solution: %.4f\n', y)
fprintf('Analytical solution: %.4f\n', ys)
fprintf('Error: %.4f\n', error)

main.m:

%assign given dy/dt
func = @(t, y) t^2 - (3*y)/t
%initial value of t
tinitial = 1;
%assign h value
h = 0.4;
%assign t end value
tend = 2.2;
%assign y(1)
y1 = 1;
%call RungeKuttaMethod() function
RungeKuttaMethod(func, tinitial, h, tend, y1);

Add a comment
Know the answer?
Add Answer to:
Hello These are a math problems that need to solve by MATLAB as code Thank you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please solve this problem by hand calculation. Thanks Consider the following system of two ODES: dx = x-yt dt dy = t+ y...

    Please solve this problem by hand calculation. Thanks Consider the following system of two ODES: dx = x-yt dt dy = t+ y from t=0 to t = 1.2 with x(0) = 1, and y(0) = 1 dt (a) Solve with Euler's explicit method using h = 0.4 (b) Solve with the classical fourth-order Runge-Kutta method using h = 0.4. The a solution of the system is x = 4et- 12et- t2 - 3t - 3, y= 2et- t-1. In...

  • Please show MATLAB code for how to gain solution. 10.1 Consider the following first-order ODE: from...

    Please show MATLAB code for how to gain solution. 10.1 Consider the following first-order ODE: from x -0 to 2.1 with (0) 2 (a) Solve with Euler's explicit method using h 0.7. (b) Solve with the modified Euler method using h - 0.7. r Runge-Kutta method using h 0.7. The analytical solution of the ODE is24. In each part, calculate the eror between the true solution and the numerical solution at the points where the numerical solution is determined

  • 4. (25 points) Solve the following ODE using classical 4th-order Runge- Kutta method within the domain...

    4. (25 points) Solve the following ODE using classical 4th-order Runge- Kutta method within the domain of x = 0 to x= 2 with step size h = 1: dy 3 dr=y+ 6x3 dx The initial condition is y(0) = 1. If the analytical solution of the ODE is y = 21.97x - 5.15; calculate the error between true solution and numerical solution at y(1) and y(2).

  • 2. Consider the following first-order ODE from x = 0 to x = 2.4 with y(0)...

    2. Consider the following first-order ODE from x = 0 to x = 2.4 with y(0) = 2. (a) solving with Euler's explicit method using h=0.6 (b) solving with midpoint method using h= 0.6 (c) solving with classical fourth-order Runge-Kutta method using h = 0.6. Plot the x-y curve according to your solution for both (a) and (b).

  • I mostly needed help with developing matlab code using the Euler method to create a graph. All th...

    I mostly needed help with developing matlab code using the Euler method to create a graph. All the other methods are doable once I have a proper Euler method code to refer to. 2nd order ODE of modeling a cylinder oscillating in still water wate wate Figure 1. A cylinder oscillating in still water. A cylinder floating in the water can be modeled by the second order ODE: dy dy dt dt where y is the distance from the water...

  • Required information Consider the following pair of ODES. dt = -2y + 4et = lehen Given,...

    Required information Consider the following pair of ODES. dt = -2y + 4et = lehen Given, the step size = 0.1. Solve the following pair of ODEs over the interval from t=0 to 0.4. The initial conditions are y0) = 2 and 7(0) = 4. Obtain your solution using the fourth-order Runge-Kutta method. (Round the final answers to three decimal places.) The solutions of the given equations are as follows: t у Z 0.1 2.068 2.842 0.3 1.787 % 2.058...

  • Both parts please! 1 Runge-Kutta Method The discretization of the spatial derivatives of a PDE often...

    Both parts please! 1 Runge-Kutta Method The discretization of the spatial derivatives of a PDE often results in a system of ODEs of the fornm du Runge-Kutta methods are the most commonly used schemes for numerically integrating in time the ODE system. We will numerically implement the "standard" third-order Runge-Kutta method. To advance the solution u from time t to t + Δ1, three sub-steps, are taken. If the solution at time t is un the following three steps are...

  • Read the sample Matlab code euler.m. Use either this code, or write your own code, to solve first...

    Read the sample Matlab code euler.m. Use either this code, or write your own code, to solve first order ODE = f(t,y) dt (a). Consider the autonomous system Use Euler's method to solve the above equation. Try different initial values, plot the graphs, describe the behavior of the solutions, and explain why. You need to find the equilibrium solutions and classify them. (b). Numerically solve the non-autonomous system dy = cost Try different initial values, plot the graphs, describe the...

  • (1) Solve the differential equation y 2xy, y(1)= 1 analytically. Plot the solution curve for the interval x 1 to 2 (see...

    (1) Solve the differential equation y 2xy, y(1)= 1 analytically. Plot the solution curve for the interval x 1 to 2 (see both MS word and Excel templates). 3 pts (2) On the same graph, plot the solution curve for the differential equation using Euler's method. 5pts (3) On the same graph, plot the solution curve for the differential equation using improved Euler's method. 5pts (4) On the same graph, plot the solution curve for the differential equation using Runge-Kutta...

  • Consider the following initial value problem у(0) — 0. у%3D х+ у, (i) Solve the differential equation above in tabul...

    Consider the following initial value problem у(0) — 0. у%3D х+ у, (i) Solve the differential equation above in tabular form with h= 0.2 to approximate the solution at x=1 by using Euler's method. Give your answer accurate to 4 decimal places. Given the exact solution of the differential equation above is y= e-x-1. Calculate (ii) all the error and percentage of relative error between the exact and the approximate y values for each of values in (i) 0.2 0.4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT