Page 1 of 1

1. Implement the Improved Euler's Method (ie the pseudo-code on pe 127 of the textbook) ning the MATLAB/Octave bles prov

Posted: Tue Sep 07, 2021 7:23 am
by answerhappygod
1 Implement The Improved Euler S Method Ie The Pseudo Code On Pe 127 Of The Textbook Ning The Matlab Octave Bles Prov 1
1 Implement The Improved Euler S Method Ie The Pseudo Code On Pe 127 Of The Textbook Ning The Matlab Octave Bles Prov 1 (29.12 KiB) Viewed 85 times
1 Implement The Improved Euler S Method Ie The Pseudo Code On Pe 127 Of The Textbook Ning The Matlab Octave Bles Prov 2
1 Implement The Improved Euler S Method Ie The Pseudo Code On Pe 127 Of The Textbook Ning The Matlab Octave Bles Prov 2 (24.39 KiB) Viewed 85 times
1 Implement The Improved Euler S Method Ie The Pseudo Code On Pe 127 Of The Textbook Ning The Matlab Octave Bles Prov 3
1 Implement The Improved Euler S Method Ie The Pseudo Code On Pe 127 Of The Textbook Ning The Matlab Octave Bles Prov 3 (47.18 KiB) Viewed 85 times
1. Implement the Improved Euler's Method (ie the pseudo-code on pe 127 of the textbook) ning the MATLAB/Octave bles provided #) Using your Implementation from above, compute the Improwd Enter approximation of V = (0) - 1 at - 1 and thenssociated error value), using step sizes 1.0.1,0.01, and 0.001 Hint: All of the correct answers are in Table 3.5, Pg. 127 of the textbook. Use these numbers to ensure that your answers match b) Plot and Inbel the exact solution and the approximate solution from part a) for h = 0.1 on the same sixes. c) Using your implementation from above, compute the improved Euler approximation of ' + 2y = - +1. y(1) = 1/2 at = 2 (and the associated error value), using step sizes 1.0.1,0.01, and 0,001. Hint: This is a first order linear differential oquation d) Plot and label the exact solution and the approximate solution from part c) for h = 0.1 on the same axes
1 00 OWN -function [x,y] = ma550_euler-.m( a, b, N, f, y_init) %---Compute and output the h value from N, a, x=b 1 = (-a) / 10; fprintf("Your value of h is: %.5f \n \n', h); 7 8 9 10 11 12 13 14 15 16 17 18 %--- Define our discrete x values X = a:1:6; %--- Incorporate the initial condition y(1) = 1; %---Construct the Euler loop for n=1:1 y(n+1) = y(n) + h * f(x(n), y(n)); end
1 2 3 4 5 6 ----Standard header close all clear clc mc 7 8 9 10 11 12 13 14 15 16 - This is the function corresponding to the right hand side f = @(x,y) y; %---This is the initial condition y_init = 1; *---Time interval on which we wish to solve the problem a = @ b = 1; -- Define the number of subintervals we use for approximation N = 10; 17 18 19 1 %---Call Euler's Method to obtain the approximate solution [x,y] = ma55e_euler-.m( a, b, N, f, y_init); 20 21 22 23 24 25 26 27 28 29 error = *--- Define the exact solution if it's available yexact - @(x) exp(1); %---Grab the error at the right endpoint abs(yexact(1) - y(end) ); fprintf("Your error at the endpoint is: %.5f \n \n', error); %---- Construct an array of exact solution values for plotting xexact = a: 0.001:b; for i=1:length(xexact) yexact_full(1) = yexact( xexact(i)); end 30 31 32 33 34 35 36 37 38 %---Plot the exact vs the approximate figure (1) plot( xexact, yexact_full, 'l', X, Y, 'r.-'); legend('Exact', 'Approx); 39 48 41 42