15 - 15 A>>%This is an implementation of Runge-Kutta to...

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

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

View Full Document

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: 15.) A >> %This is an implementation of Runge-Kutta to approximate the solutions to question 15% >> h = .1; a = 1; b = 2; n = 10; y0 = 1; %These are the input values% >> t = a; w = 1; >> f = inline ('w/t - (w/t)^2') f = Inline function: f(t,w) = w/t - (w/t)^2 >> for i = 1:n K1 = h*f(t,w); K2 = h*f(t+h/2,w+(K1)/2); K3 = h*f(t+h/2,w+(K2)/2); K4 = h*f(t+h,w+K3); w = w + (K1+2*K2+2*K3+K4)/6; %Computes wi% t = a + i*h; %Computes ti% [t' w'] end ans = 1.1000 1.0043 ans = 1.2000 1.0150 ans = 1.3000 1.0298 ans = 1.4000 1.0475 ans = 1.5000 1.0673 ans = 1.6000 1.0884 ans = 1.7000 1.1107 ans = 1.8000 1.1337 ans = 1.9000 1.1572 ans = 2.0000 1.1812 Actual Solution = 2/(1+ln(2)) = 1.1812322183 15.) B >> %This is an implementation of Runge-Kutta to approximate the solutions to question 15% >> h = .2; a = 1; b = 3; n = 10; y0 = 0; %These are the input values% >> t = a; w = 0; >> f = inline ('1+w/t+(w/t)^2') f = Inline function: f(t,w) = 1+w/t+(w/t)^2 >> for i = 1:n K1 = h*f(t,w); K2 = h*f(t+h/2,w+(K1)/2);...
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 / 8

15 - 15 A>>%This is an implementation of Runge-Kutta to...

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

View Full Document
Ask a homework question - tutors are online