blob: 5951a0304e8ad93c780166fc565472bbc9436a61 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
//Example 15.11
//Midpoint Method
//Page no. 518
clc;clear;close;
deff('y=f(x,y)','y=y+x')
y=1;
h=0.2;
printf('i\txi\tyi\tslope1\tslope2\ty(i+1)\n-----------------------------------------------\n')
for i=1:3
x=(i-1)*h
s1=f(x,y);
s2=f(x+h/2,y+s1*h/2);
printf(' %i\t%g\t%g\t%g\t%g',i-1,x,y,s1,s2)
y=y+s2*h;
printf('\t%g\n',y)
end
|