Euler's Method with CoCalc/SageMath and Maple

Maple: (available in campus computer labs)

Suppose you want to estimate the solution to \(y' = 2\sqrt{y}+t-y\) at \(t=2\) starting from the point \((0,4)\) with \(n=10\) steps.

g:=(t,y)->2*sqrt(y)+ t -y;
t[0]:=0; y[0]:=4;
n:=10;

totalstep := 2;
dt:=evalf(totalstep/n);

for i from 0 to n-1 do
t[i+1]:=t[i]+dt:
y[i+1]:=y[i]+g(t[i],y[i])*dt:

print(t[i+1],y[i+1]); od;

SageMath (available for free online at https://www.cocalc.com).

Suppose you want to estimate the solution to \(y' = 2\sqrt{y}+t-y\) at \(t=2\) starting from the point \((0,4)\) with \(n=10\) steps.

g(t,y) = 2*sqrt(y)+t-y
t = 0
y = 4
n = 10
totalstep = 2

dt = totalstep/n 
for j in range(n) :
    y = y + g(t,y)*dt
    t = t + dt
    print(t.n(digits=2), y.n(digits=4))