Try again

# Try again - waitforbuttonpress; jMin= max(1,fix(n/10)); for...

This preview shows pages 1–2. Sign up to view the full content.

function []=euler(f,x0,T,x,n) t=linspace(0,T,100); x_Exakt=feval(x,t,x0*ones(1,100)); tau_n=T/n; x_Delta(1)=x0; t_Delta=linspace(0,T,n+1); for k=1:n x_Delta(k+1)=x_Delta(k)+tau_n*feval(f,x_Delta(k)); end if n<=20 plot(t,x_Exakt,'k-',t_Delta,x_Delta,'r-o'); else plot(t,x_Exakt,'k-',t_Delta,x_Delta,'r-'); end; hold off xlabel('t') ylabel('solutions') legend('exact solution','approx. solution'); %print -deps eulerApprox.eps

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: waitforbuttonpress; jMin= max(1,fix(n/10)); for j=1:n-jMin+1 tau(j)=1/(j+jMin-1); xk=1; e(j)=0; for k=1:j+jMin-1 xk=(1+tau(j))*xk; x_k=xk+tau(j)*feval(f,xk); e(j)=max(e(j),abs(feval(x,k*tau(j),x0)-xk)); end; end; figure(1) hold off plot(tau,e,'-ko'); xlabel('\tau') ylabel('error') legend('error') print -deps eulerError.eps hold off clear...
View Full Document

## This note was uploaded on 05/01/2009 for the course PSTAT 120A taught by Professor Mackgalloway during the Spring '08 term at UCSB.

### Page1 / 2

Try again - waitforbuttonpress; jMin= max(1,fix(n/10)); for...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online