-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRKF45Kinda.nb
54 lines (43 loc) · 1.85 KB
/
RKF45Kinda.nb
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
(*Define the system of ODEs*)
system = {y1'[t] == y2[t], y2'[t] == -0.5*y1[t], y3'[t] == y4[t],
y4'[t] == -0.5*y3[t]};
(*Initial conditions*)
initialConditions = {y1[0] == 1, y2[0] == 0, y3[0] == 0, y4[0] == 1};
(*Initial and final time*)
t0 = 0;
tf = 1;
(*Solve the system of ODEs*)
sol = NDSolve[{system, initialConditions}, {y1, y2, y3, y4}, {t, t0,
tf}];
(*Plot the solutions*)
Plot[Evaluate[{y1[t], y2[t], y3[t], y4[t]} /. sol], {t, t0, tf},
PlotLabels -> {"y1(t)", "y2(t)", "y3(t)", "y4(t)"},
PlotLegends -> {"y1(t)", "y2(t)", "y3(t)", "y4(t)"},
PlotLabel -> "Solutions to the System of ODEs",
AxesLabel -> {"t", "y(t)"}]
(*Define the system of ODEs*)
system = {y1'[t] == y2[t]^2, y2'[t] == -0.5*y1[t], y3'[t] == y4[t]^2,
y4'[t] == -0.5*y3[t]};
(*Initial conditions*)
initialConditions = {y1[0] == 1, y2[0] == 0, y3[0] == 0, y4[0] == 1};
(*Solve the system of ODEs and plot the solutions*)
sol = NDSolve[{system, initialConditions}, {y1, y2, y3, y4}, {t, t0,
tf}];
Plot[Evaluate[{y1[t], y2[t], y3[t], y4[t]} /. sol], {t, t0, tf},
PlotLabels -> {"y1(t)", "y2(t)", "y3(t)", "y4(t)"},
PlotLegends -> {"y1(t)", "y2(t)", "y3(t)", "y4(t)"},
PlotLabel -> "Test Case 2: Solutions to the System of ODEs",
AxesLabel -> {"t", "y(t)"}]
(*Define the system of ODEs*)
system = {y1'[t] == y2[t], y2'[t] == -10.5*y1[t], y3'[t] == y4[t],
y4'[t] == -0.5*y3[t]};
(*Initial conditions*)
initialConditions = {y1[0] == 0, y2[0] == 1, y3[0] == 1, y4[0] == 0};
(*Solve the system of ODEs and plot the solutions*)
sol = NDSolve[{system, initialConditions}, {y1, y2, y3, y4}, {t, t0,
tf}];
Plot[Evaluate[{y1[t], y2[t], y3[t], y4[t]} /. sol], {t, t0, tf},
PlotLabels -> {"y1(t)", "y2(t)", "y3(t)", "y4(t)"},
PlotLegends -> {"y1(t)", "y2(t)", "y3(t)", "y4(t)"},
PlotLabel -> "Test Case 3: Solutions to the System of ODEs",
AxesLabel -> {"t", "y(t)"}]