hw18_solutions

hw18_solutions - Homework #8 1. () () We have () where ( is...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Homework #8 1. () () We have () where ( is the Lipschitz constant for ( ). We have ) () so we need to know the solution to actually complete the estimation. We find ( ) so which implies that () 2. Using previous problem we need to find a bound on () Since () | |* , we need to find the upper bound for () | |* , , - () We start computing it () Knowing what y is, we get that -+ () , - () () and therefore -+ 3. Matlab code for this problem First file: function [f,k]=funeval(t,y,k) % this function computes f(t,y) and increases the number of function % evaluations k k=k+1; f=sin(t+y)*exp(-sqrt(1+y^2)); end Second file: clear all close all clc n=[2 4 10 100 1000 2000]; % set of number of steps h=2./n; % define step sizes for i=1:length(n) t0=0; % initial time y0=2; % initial value of function number_eval=0; % numver of function evaluations for k=1:n(i) [f0,number_eval]=funeval(t0,y0,number_eval); ybar= y0+h(i)*f0; % predict [f1,number_eval]=funeval(t0+h(i),ybar,number_eval); y=y0+0.5*h(i)*(f0 + f1); % correct y0=y; % update f0r the next loop t0=t0+h(i); % next time step end number_eval_final(i)=number_eval; % save number of fun eval yfinal(i)=y; % save final value for the plots end error=yfinal(1:end-1)-yfinal(end); % define error subplot(1,2,1) plot(log10(n(1:end-1)),log10(abs(error)),'-o') title('Log10 of error vs Log10 of n') grid on xlabel('Log10 of n') ylabel('Log10 of error') subplot(1,2,2) plot(log10(number_eval_final(1:end-1)),log10(abs(error)),'-o') title('Log10 of error vs Log10 of fun eval') grid on xlabel('Log10 of fun eval') ylabel('Log10 of error') Second file returns the following figure Using the material in Section 4.5 we have ( ( ) ) () ( ) () so that the differential equation becomes ( ) () ( ) () ( ( )) ( )) or ( Thus ) () ( ) ( () ( ) () ( ) ( ( The residual is () and the truncation error is () The method is consistent as long as is continuous. )) () ...
View Full Document

Ask a homework question - tutors are online