summaryrefslogtreecommitdiff
path: root/260/CH13/EX13.12/13_12.sce
blob: 4659f5353e3e9c6e5871d7a3104e7055977a76cc (plain)
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
//Eg-13.12
//pg-552

clear
clc

y(1) = 1;

h = 1;

printf('For h = 1\n')
printf('              x           y\n')

for(i = 1:3)
    x(i) = i;    //since h = 1
    y(i+1) = y(i)/(1+2*h);
    printf('            %f    %f\n',x(i),y(i+1))
end

h = 0.5;
printf('\nFor h = 0.5\n')
printf('              x           y\n')

n = (3.0-0.5)/0.5+1;

for(i = 1:n)
    x(i) = 0.5 + (i-1)*h;    //since h = 0.5
    y(i+1) = y(i)/(1+2*h);
    printf('            %f    %f\n',x(i),y(i+1))
end

printf('Observe that the implicit method is stable for h = 1, whereas the explicit method is not.')