Question
SOLVE USING MATLAB ONLY AND SHOW FULL CODE. PLEASE TO SHOW TEXT BOOK SOLUTION. SOLVE PART D ONLY
Apply Eulers Method with step sizes h # 0.1 and h 0.01 to the initial value problems in Exercise 1. Plot the approximate sol
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%%Matlab code for Eulers forward clear all close all 888888,,88,,88움움8888888888움움88888888888888888888888888888888888888 %funh-0.01; %step length results of h-0.1 [x1_result,x2_result,t_result]-Euler (f1, £2,y1 in,y2_in,t_in, t end, h); figure (1) plFor functions e(yl,y2,t)yl+3*y2 Global truncation error for yl for h-0.100000 at t-1.000000 is 51.402972. Global truncation etvs. y2tt) plot 120 Solution for h:0.1 Solution for h-0.01 Exact solution 100 80 60 40 20 0 .1 0 03 04 05 0608 0.9 Published

%%Matlab code for Euler's forward
clear all
close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%function for Euler equation solution
f1=@(y1,y2,t) y1+3*y2;
f2=@(y1,y2,t) 2*y1+2*y2;

%for the functions
y1_ext=@(t) 3*exp(-t)+2*exp(4*t);
y2_ext=@(t) -2*exp(-t)+2*exp(4*t);

%displaying the functions
fprintf('For functions \n')
disp(f1)
disp(f2)

%Initial conditions
y1_in=5;   %y1(0)=1
y2_in=0;   %y2(0)=0
%initial t
t_in=0;
%t end values
t_end=1;
h=0.1; %step length

%results of h=0.1
[x1_result,x2_result,t_result]=Euler(f1,f2,y1_in,y2_in,t_in,t_end,h);
%error finding
err1=abs(y1_ext(t_end)-x1_result(end));
err2=abs(y2_ext(t_end)-x2_result(end));

figure(1)
hold on
plot(t_result,x1_result)
xlabel('t')
ylabel('y1(t)')
title('t vs. y1(t) plot')

figure(2)
hold on
plot(t_result,x2_result)
xlabel('t')
ylabel('y2(t)')
title('t vs. y2(t) plot')

fprintf('\tGlobal truncation error for y1 for h=%f at t=%f is %f.\n',h,t_end,err1)
fprintf('\tGlobal truncation error for y1 for h=%f at t=%f is %f.\n\n',h,t_end,err2)

h=0.01; %step length

%results of h=0.1
[x1_result,x2_result,t_result]=Euler(f1,f2,y1_in,y2_in,t_in,t_end,h);
figure(1)

plot(t_result,x1_result)
plot(t_result,y1_ext(t_result))
legend('Solution for h=0.1','Solution for h=0.01','Exact solution')

figure(2)
hold on
plot(t_result,x2_result)
plot(t_result,y2_ext(t_result))
legend('Solution for h=0.1','Solution for h=0.01','Exact solution')

%error finding
err1=abs(y1_ext(t_end)-x1_result(end));
err2=abs(y2_ext(t_end)-x2_result(end));

fprintf('\tGlobal truncation error for y1 for h=%f at t=%f is %f.\n',h,t_end,err1)
fprintf('\tGlobal truncation error for y1 for h=%f at t=%f is %f.\n\n',h,t_end,err2)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [x1_result,x2_result,t_result]=Euler(f1,f2,y1_in,y2_in,t_in,t_end,h)

    tn=t_in:h:t_end;
    % Euler steps
    x1_result(1)=y1_in;
    x2_result(1)=y2_in;
    t_result(1)=t_in;

    %loop for Euler step for finding the solution
  
    for i=1:length(tn)-1

        t_result(i+1)= t_result(i)+h;
        x1_result(i+1)=x1_result(i)+h*double(f1(x1_result(i),x2_result(i),t_result(i)));
        x2_result(i+1)=x2_result(i)+h*double(f2(x1_result(i),x2_result(i),t_result(i)));
     
    end
  
end

                %%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
SOLVE USING MATLAB ONLY AND SHOW FULL CODE. PLEASE TO SHOW TEXT BOOK SOLUTION. SOLVE PART D ONLY
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
  • *Matlab code, please! only 1d (a) 1. Apply the Euler’s Method with step size h =...

    *Matlab code, please! only 1d (a) 1. Apply the Euler’s Method with step size h = 1/4 to the initial value problem on [0, 1]. y1 = yi + y2 yí = -yi – 12 ya = - y1 + y2 on J y2 = yi – Y2 yı(0) = 1 yı(0) = 1 y2 (0) = 0 | Y2(0) = 0 y =-12 yí = yi + 3y2 ya = 2yı + 2y2 (d) yı(0) = 1 yi(0) =...

  • 5. Consider the system of differential equations yi = y1 + 2y2, y = -41/2 +...

    5. Consider the system of differential equations yi = y1 + 2y2, y = -41/2 + y2 with initial conditions yi(0) = 1, y2(0= 0. This has exact solution yı(t) = exp(t) cos(t), yz(t) = - exp(t) sin(t)/2. (a) Apply Euler's method with h=1/4 and find the global truncation error by comparing with the exact solution over the interval [0, 1]. (b) Apply the RK4 method with h=1 and find the global truncation error by comparing with the exact solution...

  • Please do not use SYMS package. It does not work on Octave for me. Matlab code...

    Please do not use SYMS package. It does not work on Octave for me. Matlab code needed for: 1. Apply the Explicit Trapezoid Method on a grid of step size h = 0.1 in [0, 1] to the initial value problems in Exercise 1. Print a table of the t values, approximations, and global truncation error at each step. IVP (Exercise 1): (a) y'=1 (b) y' = 12y (c) y' = 2(t+1)y (d) y = 564, (e) y'=1/y² (1) y'=1/y2...

  • a) Find the upper bound for the local truncation error if you solve the equation with...

    a) Find the upper bound for the local truncation error if you solve the equation with the explicit Euler's method b) Find the upper bound for the global error as a function of t and h if you solve the equation with the explicit Euler's method y = 3 sin(2y) 4 (0) =1, 0 <t<

  • dont use matlab yes Question 2 4 pts a) Find the upper bound for the local...

    dont use matlab yes Question 2 4 pts a) Find the upper bound for the local truncation error if you solve the equation with the explicit Euler's method b) Find the upper bound for the global error as a function of t and h if you solve the equation with the explicit Euler's method y = 3 sin(2y) y (0) = 1, 0<t<} HTML Editores

  • Complete using MatLab 1. Consider the following initial value problem 3t2-y, y(0) = 1 Using Euler's...

    Complete using MatLab 1. Consider the following initial value problem 3t2-y, y(0) = 1 Using Euler's Method and the second order Runge-Kutta method, for t E [0, 1] with a step size of h 0.05, approximate the solution to the initial value problem. Plot the true solution and the approximate solutions on the same figure. Be sure to label your axis and include an a. appropriate legend b. Verify that the analytic solution to the differential equation is given by...

  • 1. (Hand problem) Apply Euler's Method with step size h=1/4 to the initial value problem V=t+y,...

    1. (Hand problem) Apply Euler's Method with step size h=1/4 to the initial value problem V=t+y, Ostsi. y(0) = 1, (1) and find the global error at t = 1 by comparing with the exact solution y(t) = 2e - t-1.

  • Consider the initial-value problem y' = 2x - 3y + 1, y(1) = 9. The analytic...

    Consider the initial-value problem y' = 2x - 3y + 1, y(1) = 9. The analytic solution is 1 2 74 -X + e-3(x - 1) 9 (a) Find a formula involving c and h for the local truncation error in the nth step if Euler's method is used. (b) Find a bound for the local truncation error in each step if h = 0.1 is used to approximate y(1.5). (Proceed as in Example 1 of Section 6.1.) (c) Approximate...

  • Consider the initial-value problem y' = 2x – 3y + 1, y(1) = 9. The analytic...

    Consider the initial-value problem y' = 2x – 3y + 1, y(1) = 9. The analytic solution is 1 2 74 e-3(x - 1). 9 3 9 (a) Find a formula involving c and h for the local truncation error in the nth step if Euler's method is used. 372²e -3(0-1) (b) Find a bound for the local truncation error in each step if h = 0.1 is used to approximate y(1.5). (Proceed as in Example 1 of Section 6.1.)...

  • Exercise 3 is used towards the question. Please in MATLAB coding. 1. Apply Euler's Method with...

    Exercise 3 is used towards the question. Please in MATLAB coding. 1. Apply Euler's Method with step size h=0.1 on [0, 1] to the initial value problems in Exercise 3. Print a table of the t values, Euler approximations, and error (difference from exact solution) at each step. 3. Use separation of variables to find solutions of the IVP given by y) = 1 and the following differential equations: (a) y'=1 (b) y'=1y y'=2(1+1)y () y = 5e4y (e) y=1/92...

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