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

Info icon This 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;
Image of page 1

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

View Full Document Right 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)
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 % % Aufruf: eulerError(n) % % Parameter: n maximale Anzahlder Gitterpunkte % % Beispiel: eulerError(100) % 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; e(j)=max(e(j),abs(exp(k*tau(j))-xk));
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern