Homework 8 30

Homework 8 30

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 30.1) To save time I modified the programs myeuler.m and mymodeuler.m to incorporate a plot command at the end of each program. function [T , Y] = myeuler(f,tspan,y0,n) a = tspan(1); b = tspan(2); h = (b-a)/n; t = a; y = y0; T = a; Y = y0'; for i = 1:n y = y + h*f(t,y); t = t + h; T = [T; t]; Y = [Y; y']; end plot(T,Y) function [T , Y] = mymodeuler(f,tspan,y0,n) a = tspan(1); b = tspan(2); h = (b-a)/n; t = a; y = y0; T = a; Y = y0'; for i = 1:n k1 = h*f(t,y); k2 = h*f(t+h,y+k1); y = y + .5*(k1+k2); t = a + i*h; T = [T; t]; Y = [Y; y']; end plot(T,Y) In the command window I then set up tw...
View Full Document

Ask a homework question - tutors are online