-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericalMethods2_4A.m
87 lines (50 loc) · 1.09 KB
/
NumericalMethods2_4A.m
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
%authors Ivan Liljeqvist and Filip Martinsson
y=[1;-1/3];
L=2.6;
h=0.2;
x=0;
X=x;
Y=y';
while(x<L)
f1=dfunc(x,y);
f2=dfunc(x+h/2,y+h*f1/2);
f3=dfunc(x+h/2,y+h*f2/2);
f4=dfunc(x+h,y+h*f3);
y=y+h*(f1+2*f2+2*f3+f4)/6;
x=x+h;
X=[X;x'];
Y=[Y;y'];
end
Last_Y_BIG_STEP=Y(end,1);
y=[1;-1/3];
L=2.6;
h=0.1;
x=0;
X=x;
Y=y';
while(x<L)
f1=dfunc(x,y);
f2=dfunc(x+h/2,y+h*f1/2);
f3=dfunc(x+h/2,y+h*f2/2);
f4=dfunc(x+h,y+h*f3);
y=y+h*(f1+2*f2+2*f3+f4)/6;
x=x+h;
X=[X;x'];
Y=[Y;y'];
end
Last_Y_SMALL_STEP=Y(end,1);
LAST_Y_DIFFERENCE=abs(Last_Y_SMALL_STEP-Last_Y_BIG_STEP);
plot(X,Y(:,1),X,Y(:,1),'o');
%{
X
Y=Y(:,1)
three_d_y=[0:2*pi/30:2*pi];
X_3D=X*ones(size(three_d_y));
Y_3D=Y*cos(three_d_y);
Z_3D=Y*sin(three_d_y);
surf(X_3D,Y_3D,Z_3D);
When h = 0.2 the graph is not very smooth.
It is smoother when h=0.1 because the distance between the datapoints
is reduced and we have more datapoints.
The difference in last Y between small and big step is 2.406478945444795e-02
%}