# P20_1 - %Problem 20.1 f function P20_1 % %Analytical-t...

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

%Problem 20.1 % function P20_1 f %Analytical-------------------------------------------------------------- % tanal = (0:0.1:2)'; t yanal = exp((tanal.^3)./3 - 1.1.*tanal); y plot(tanal, yanal) p %Euler h = 0.5------------------------------------------------------------ h = 0.5; t = (0:h:2)'; y = zeros(2/h,1); y(1,1) = 1; y for i = 1:2/h y(i+1,1) = y(i,1) + f(t(i,1),y(i,1))*h; end e yE05 = y; tE05 = t; t fprintf('Euler with h = 0.5\n') fprintf('t y dy/dt\n') for r = 1:2/h+1 fprintf('%3.1f %8.6f %8.6f\n', t(r,1), y(r,1), f(t(r,1),y(r,1))) end e fprintf('\n') f %Euler h = 0.25---------------------------------------------------------- % h = 0.25; t = (0:h:2)'; y = zeros(2/h,1); y(1,1) = 1; y for i = 1:2/h y(i+1,1) = y(i,1) + f(t(i,1),y(i,1))*h; end e yE025 = y; tE025 = t; t fprintf('Euler with h = 0.25\n') fprintf('t y dy/dt\n') for r = 1:2/h+1 fprintf('%4.2f %8.6f %8.6f\n', t(r,1), y(r,1), f(t(r,1),y(r,1))) end e fprintf('\n')

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

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

## P20_1 - %Problem 20.1 f function P20_1 % %Analytical-t...

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

View Full Document
Ask a homework question - tutors are online