Question

1. Consider the following differential equation. ag = ty, y(0)=1. dt (a) Use Eulers Method with At = .1 to approximate y(1).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB Script:

close all
clear
clc

% Given
f = @(t,y) t^2 * y; % Given ODE
t0 = 0; tf = 1; % Intervals of x
y0 = 1; % Initial condition

fprintf('Part (a)\n----------------------------------\n')
h1 = 0.1; % Step Size 1
x1 = t0:h1:tf;
y1 = my_euler(t0, y0, tf, h1, f);
fprintf('For h = 0.1, y(1) = %.6f\n', y1(end))

fprintf('\nPart (b)\n----------------------------------\n')
h2 = 0.05; % Step Size 2
x2 = t0:h2:tf;
y2 = my_euler(t0, y0, tf, h2, f);
fprintf('For h = 0.05, y(1) = %.6f\n', y2(end))

fprintf('\nPart (c)\n----------------------------------\n')
% Exact Solution
syms y(t)
ODE = diff(y,t) == t^2 * y; % Given ODE
cond = y(0) == 1; % Initial condition
y_sol = dsolve(ODE, cond); % Solver
fprintf('For h = 0.1, Error = %.6f\n', abs(subs(y_sol, 1) - y1(end)))
fprintf('For h = 0.05, Error = %.6f\n', abs(subs(y_sol, 1) - y2(end)))
disp('Lower step-size gives better results.')

function y = my_euler(t0, y0, tf, h, f)
y(1) = y0;
t = t0:h:tf;
for i = 1:length(t)-1
y(i+1) = y(i) + h*f(t(i), y(i)); % Euler Update
end
end

Output:

Part (a)
----------------------------------
For h = 0.1, y(1) = 1.320016

Part (b)
----------------------------------
For h = 0.05, y(1) = 1.355880

Part (c)
----------------------------------
For h = 0.1, Error = 0.075597
For h = 0.05, Error = 0.039732
Lower step-size gives better results.

Add a comment
Know the answer?
Add Answer to:
1. Consider the following differential equation. ag = ty, y(0)=1. dt (a) Use Euler's Method with...
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
  • 3. Euler's Method (a) Use Euler's Method with step size At = 1 to approximate values...

    3. Euler's Method (a) Use Euler's Method with step size At = 1 to approximate values of y(2),3(3), 3(1) for the function y(t) that is a solution to the initial value problem y = 12 - y(1) = 3 (b) Use Euler's Method with step size At = 1/2 to approximate y(6) for the function y(t) that is a solution to the initial value problem y = 4y (3) (c) Use Euler's Method with step size At = 1 to...

  • Problem 1 Use Euler's method with step size h = 0.5 to approximate the solution of the IVP. 2 dy ...

    Problem 1 Use Euler's method with step size h = 0.5 to approximate the solution of the IVP. 2 dy ev dt t 1-t-2, y(1) = 0. Problem 2 Consider the IVP: dy dt (a) Use Euler's method with step size h0.25 to approximate y(0.5) b) Find the exact solution of the IV P c) Find the maximum error in approximating y(0.5) by y2 (d) Calculate the actual absolute error in approximating y(0.5) by /2. Problem 1 Use Euler's method...

  • (1 point) Suppose that we use Euler's method to approximate the solution to the differential equation...

    (1 point) Suppose that we use Euler's method to approximate the solution to the differential equation dyr. dzvi y(0.4) = 9. Let f(x, y) = 25/y. We let Xo = 0.4 and yo = 9 and pick a step size h=0.2. Euler's method is the the following algorithm. From In and Yn, our approximations to the solution of the differential equation at the nth stage, we find the next stage by computing In+1 = xin + h Y n+1 =...

  • 7. Given the differential equation y' = 4x – 2y; y(1) = 0.5, use Euler's method,...

    7. Given the differential equation y' = 4x – 2y; y(1) = 0.5, use Euler's method, with a step size (Ax or h) of 0.25 to approximate y(2). Show appropriate steps.

  • 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...

  • 2. Differential Equation (5 points) Using (i) Euler's method and (ii) modified Euler's method, bo...

    Please show Matlab code and Simulink screenshots 2. Differential Equation (5 points) Using (i) Euler's method and (ii) modified Euler's method, both with step size h-0.01, to construct an approximate solution from t-0 to t-2 for xt 2 , 42 with initial condition x(0)-1. Compare both results by plotting them in the same figure. 3. Simulink (5 points) Solve the above differential equation using simplink. Present the model and result. 2. Differential Equation (5 points) Using (i) Euler's method and...

  • C++ Euler's method is a numerical method for generating a table of values (xi , yi)...

    C++ Euler's method is a numerical method for generating a table of values (xi , yi) that approximate the solution of the differential equation y' = f(x,y) with boundary condition y(xo) = yo. The first entry in the table is the starting point (xo , yo.). Given the entry (xi , yi ), then entry (xi+1 , yi+1) is obtained using the formula xi+1 = xi + x and yi+1 = yi + xf(xi , yi ). Where h is...

  • C Consider a differential equation with the given slope field and the in y(0) = 1....

    C Consider a differential equation with the given slope field and the in y(0) = 1. 0.5 st -0.5 (a) Explain why, if you wanted to approximate y(2) using two steps of Euler's method, you would need At = 1. (b) Use a straight edge to graph two steps of Euler's method to approximate y(2). (c) This time, instead of using two steps of Euler's method, sketch on the same slope field what it would look like if you used...

  • ) For the IVP y+2y-2-e(0)- Use Euler's Method with a step size of h 5 to...

    ) For the IVP y+2y-2-e(0)- Use Euler's Method with a step size of h 5 to find approximate values of the solution at t-1 Compare them to the exact values of the solution at these points.

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