Consider the following well-posed IVP: (t)-1 M, 1 sts 2; (1) y(1) 2, with the ex
ID: 3028095 • Letter: C
Question
Consider the following well-posed IVP: (t)-1 M, 1 sts 2; (1) y(1) 2, with the exact solution ylt) tln t 2t. hoose the step sizes h 0.2, 0,1,0,05, respec tively. (a) Use Taylor's method of order two to approximate the solution. Discuss the behavior of the approximated solution as a function of h, and compare it with the exact solution in plots of t versus y. Estimate the order of the method from the error. Which value of h do you need to choose (approximately) to achieve an accuracy of 10 for y(2)? (b) Use Midpoint method (p.286) to redo Part (a). (c) Compare the results and nunning times' of Part (a) and (b). What does the comparison of error and running time tell us about the efficiency of the two methods? Requirements Submit the code file to CCLE 2: A MATLAB (or other software) function taylor2.m that implements Taylor's method of order two, a MATLAB function (or other software) midpt.m that implements Mid- point method, and a MATLAB (or other software) script main.m that solves the IVP (1) and plots the approximated solutions versus the exact one.Explanation / Answer
function [T,Y] = taylor(f,a,b,ya,m) %--------------------------------------------------------------------------- %TAYLOR Taylor's solution for y' = f(t,y) with y(a) = ya. % Sample call % [T,Y] = taylor('f',a,b,ya,m) % Inputs % f name of the function % a left endpoint of [a,b] % b right endpoint of [a,b] % ya initial value % m number of steps % Return % T solution: vector of abscissas % Y solution: vector of ordinates %--------------------------------------------------------------------------- h = (b - a)/m; T = zeros(1,m+1); Y = zeros(1,m+1); T(1) = a; Y(1) = ya; for j=1:m, tj = T(j); yj = Y(j); D = feval('df',tj,yj); Y(j+1) = yj + h*(D(1)+h*(D(2)/2+h*(D(3)/6+h*D(4)/24))); T(j+1) = a + h*j; end function(M(f))= composite_midpoint(f) h=(b-a)/N for i=1:1:N c_i=a+0.5*(2i-1)*h M(f) = h*(sum + f) end