Approximate the solution of this initial value problem using Euler's method (Maple)

220 Views Asked by At

I have the following initial value problem for two functions $y(x)$,$z(x)$:

$0=y''+(y'+6y)\cos(z)$,

$5z'=x^2+y^2+z^2$,

where $0\leq x \leq 2$ and $y(0)=1.7$, $y'(0)=-2.7$, $z(0)=0.5$.

Then I got the following for $u(x)$: $$\left\{ \begin{aligned} y'(x) &=u_2 \\ y''(x)&=-(u_2+6u_1)\cos(u_3) \\ z'(x)&=\frac{1}{5}(x^2+u_1^2+u_3^2) \end{aligned} \right. $$ I assume $u_1=y(x)$, $u_2=y'(x)$, $u_3=z(x)$ for ablove.

The task is to solve this problem using Euler's method with $100$ steps in Maple. I'm stuck here. Can someone help with what to do next?

2

There are 2 best solutions below

0
On

Well, the first step would be to write down Euler's method for this specific problem. In general, when solving an initial value problem for the system $Y' = F(x,Y)$, where $Y:\mathbb{R}\to \mathbb{R}^n$ and $F:\mathbb{R}\times \mathbb{R}^n \to \mathbb{R}^n$, Euler's method reads $$ \begin{cases} Y_0 = Y(t_0)\\ Y_{k+1}=Y_k + h F(x_k,Y_k) \end{cases} $$

As you already mentioned, denoting $w = y'$, your system becomes $$ \begin{cases} y' = w\\ w' = -(w+6y) \cos z\\ z' = \frac 15(x^2+y^2+z^2) \end{cases}. $$

Hence, Euler's method reads $$ \begin{cases} y_0 = 1.7; \,\, w_0 = -2,7; \,\, z_0 = 0.5\\ y_{k+1} = y_k + h w_k\\ w_{k+1} = w_k - h(w_k+6y_k) \cos z_k\\ z_{k+1} = z_k + \frac h5(x_k^2+y_k^2+z_k^2) \end{cases}. $$

Below you can see what to expect from the solution:

enter image description here

0
On

It isn't clear whether you're supposed to code Euler's method yourself, from scratch, or use a stock command that provides that functionality.

restart;
eq1 := 0 = diff(y(x),x,x)+(diff(y(x),x)
           +6*y(x))*cos(z(x)):
eq2 := 5*diff(z(x),x) = x^2 + y(x)^2
       + z(x)^2:

ics := y(0)=1.7, D(y)(0)=-2.7, z(0)=0.5:

H := dsolve({eq1,eq2,ics}, numeric,
            method=classical[foreuler],
            stepsize=(2-0)/(100),
            output=Array([seq(0..2,(2-0)/(100))])):

And now,

dat := H[2,1]:

# What the columns of Matrix `dat` mean
H[1,1];

    [          d            ]
    [x, y(x), --- y(x), z(x)]
    [          dx           ]

# plot column 2 versus column 1,
# ie. y(x) versus x.
plot(dat[..,[1,2]], labels=[x,y(x)]);

plot(dat[..,[1,3]], labels=[x,diff(y(x),x)]);

plot(dat[..,[1,4]], labels=[x,z(x)]);

Or, plotting them together,

plot([dat[..,[1,2]],
      dat[..,[1,3]],
      dat[..,[1,4]]],
      size=[500,300],
      legend=[y(x),diff(y(x),x),z(x)]);

enter image description here