Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
20
Task/Runge-Kutta-method/Mathematica/runge-kutta-method.math
Normal file
20
Task/Runge-Kutta-method/Mathematica/runge-kutta-method.math
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(* Symbolic solution *)
|
||||
DSolve[{y'[t] == t*Sqrt[y[t]], y[0] == 1}, y, t]
|
||||
Table[{t, 1/16 (4 + t^2)^2}, {t, 0, 10}]
|
||||
|
||||
(* Numerical solution I (not RK4) *)
|
||||
Table[{t, y[t], Abs[y[t] - 1/16*(4 + t^2)^2]}, {t, 0, 10}] /.
|
||||
First@NDSolve[{y'[t] == t*Sqrt[y[t]], y[0] == 1}, y, {t, 0, 10}]
|
||||
|
||||
(* Numerical solution II (RK4) *)
|
||||
f[{t_, y_}] := {1, t Sqrt[y]}
|
||||
h = 0.1;
|
||||
phi[y_] := Module[{k1, k2, k3, k4},
|
||||
k1 = h*f[y];
|
||||
k2 = h*f[y + 1/2 k1];
|
||||
k3 = h*f[y + 1/2 k2];
|
||||
k4 = h*f[y + k3];
|
||||
y + k1/6 + k2/3 + k3/3 + k4/6]
|
||||
solution = NestList[phi, {0, 1}, 101];
|
||||
Table[{y[[1]], y[[2]], Abs[y[[2]] - 1/16 (y[[1]]^2 + 4)^2]},
|
||||
{y, solution[[1 ;; 101 ;; 10]]}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue