Euler - function[tout yout = eul(FunFcn tspan y0 ssize...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
function [tout, yout] = eul(FunFcn, tspan, y0, ssize) % Initialization clf t0=tspan(1); tfinal=tspan(2); if (nargin < 4), ssize = (tfinal - t0)/100; end h = ssize; t = t0; y = y0(:); tout = t; yout = y.'; % The main loop while (t < tfinal) if t + h > tfinal, h = tfinal - t; end % Compute the slope s1 = feval(FunFcn, t, y); s1 = s1(:); % s1=f(t(k),y(k)) t = t + h; y = y + h*s1; % y(k+1) = y(k) + h*f(t(k),y(k)) tout = [tout; t]; yout = [yout; y.']; hold on plot(tout,yout(:,1),'rx-') if length(y0) > 1 hold on plot(tout,yout(:,2),'b*-') hold on plot(yout(:,1),yout(:,2),'gs-') end; end;
Background image of page 1

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

View Full DocumentRight Arrow Icon
clear; i=0; vec = zeros(12,1); vecdt= zeros(12,1); for kk=4:4:48 T =1.0; dt =T/kk; u0 = 200.; c = 1.0; usur = 70.; uk = u0; for k = 1:kk uk = uk +dt*c*(usur -uk); uex = usur + (u0 -usur)*exp(-c*k*dt); error = abs(uk - uex); end i= i+1; vec(i) = error; vecdt(i) = 1/dt; end plot(vecdt,vec)
Background image of page 2
function []=eulerError(n) % % berechnet und plottet den Diskretisierungsfehler des % expliziten Euler--Verfahrens % angewandt auf x'=x in t=[0,1], x(0)=1
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the 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 / 7

Euler - function[tout yout = eul(FunFcn tspan y0 ssize...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online