1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
//Eg-13.19
//pg-567
clear
clc
deff('out = func(in1,in2,in3)','out = in3 - in2')
//At t = 0
t = 0;
y0(1) = 1;
y1(1) = y0 - 1;
//Now all the values are known at t = 0. We will now use the Euler's method to compute y0 at (t+h), with h = 0.1
//At t = 0.1
t = 0.1;
y0(2) = y0(1) + t*func(0,y0(1),y1(1));
y1(2) = y0(2) - 1;
//Similarly
t = 0.2;
y0(3) = y0(2) + t*func(0.1,y0(2),y1(2));
y1(3) = y0(3) - 1;
t = 0.3;
y0(4) = y0(3) + t*func(0.2,y0(3),y1(3));
y1(4) = y0(4) - 1;
printf('Therefore at t = 0.3, y0 = %f, y1 = %f\n',y0(3),y1(3))
//printf('%f %f\n%f %f\n%f %f\n',y0(1),y1(1),y0(2),y1(2),y0(3),y1(3))
|