Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Euler-method/Maxima/euler-method.maxima
Normal file
38
Task/Euler-method/Maxima/euler-method.maxima
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
euler_method(f, y0, a, b, h):= block(
|
||||
[t: a, y: y0, tg: [a], yg: [y0]],
|
||||
unless t>=b do (
|
||||
t: t + h,
|
||||
y: y + f(t, y)*h,
|
||||
tg: endcons(t, tg),
|
||||
yg: endcons(y, yg)
|
||||
),
|
||||
[tg, yg]
|
||||
);
|
||||
|
||||
/* initial temperature */
|
||||
T0: 100;
|
||||
|
||||
/* environment of temperature */
|
||||
Tr: 20;
|
||||
|
||||
/* the cooling constant */
|
||||
k: 0.07;
|
||||
|
||||
/* end of integration */
|
||||
tmax: 100;
|
||||
|
||||
/* analytical solution */
|
||||
Tref(t):= Tr + (T0 - Tr)*exp(-k*t);
|
||||
|
||||
/* cooling rate */
|
||||
dT(t, T):= -k*(T-Tr);
|
||||
|
||||
/* get numerical solution */
|
||||
h: 10;
|
||||
[tg, yg]: euler_method('dT, T0, 0, tmax, h);
|
||||
|
||||
/* plot analytical and numerical solution */
|
||||
plot2d([Tref, [discrete, tg, yg]], ['t, 0, tmax],
|
||||
[legend, "analytical", concat("h = ", h)],
|
||||
[xlabel, "t / seconds"],
|
||||
[ylabel, "Temperature / C"]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue