Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Euler's Method

Subject: Euler's Method

From: Shelby

Date: 12 Apr, 2011 06:15:21

Message: 1 of 6

The Question is:

• Uses ode23 to solve (1) from t = 0 to t = 4.
• Uses Euler’s method (as discussed in class) to solve (1) from t = 0 to t = 4, starting with one interval, and increasing the number of intervals one at a time until the Euler solution is within one percent of the ode23 solution, displays the number of intervals.

I have:
%dx/dt=sin(x*(t^2))
clc
%Using Ode on dxdt.m
[t,x]=ode23(@dxdt, [0,4], 1) %Exact Solution

%Euler's Method
xo=1;
to=0;
step=.2;
N=0:step:4;

for i=1:length(N)-1
    xo=xo+step*sin(xo*(to^2));
    to=to+step;
end
xo
step


When I try to change the step size, then number gets further away, no matter which direction I move in.

Subject: Euler's Method

From: Torsten

Date: 12 Apr, 2011 06:49:21

Message: 2 of 6

On 12 Apr., 08:15, "Shelby " <sstra...@jhu.edu> wrote:
> The Question is:
>
> •     Uses ode23 to solve (1) from t = 0 to t = 4.
> •     Uses Euler’s method (as discussed in class) to solve (1) from t = 0 to t = 4, starting with one interval, and increasing the number of intervals one at a time until the Euler solution is within one percent of the ode23 solution, displays the number of intervals.
>
> I have:
> %dx/dt=sin(x*(t^2))
> clc
> %Using Ode on dxdt.m
> [t,x]=ode23(@dxdt, [0,4], 1)  %Exact Solution
>
> %Euler's Method
> xo=1;
> to=0;
> step=.2;
> N=0:step:4;
>
> for i=1:length(N)-1
>     xo=xo+step*sin(xo*(to^2));
>     to=to+step;
> end
> xo
> step
>
> When I try to change the step size, then number gets further away, no matter which direction I move in.

I don't see any obvious error -except that you should change the order
of the
commands in your loop:

for i=1:length(N)-1
       to=to+step;
       xo=xo+step*sin(xo*(to^2));
end

What results do you get for different step sizes ?

Best wishes
Torsten.

Subject: Euler's Method

From: Nasser M. Abbasi

Date: 12 Apr, 2011 07:25:58

Message: 3 of 6

On 4/11/2011 11:15 PM, Shelby wrote:

>
> When I try to change the step size, then number gets further away,
> no matter which direction I move in.

Forward Euler, which is what you are using is not stable. Trye backward
Euler, you just get better results.

--Nasser

Subject: Euler's Method

From: Florin Neacsu

Date: 12 Apr, 2011 16:15:08

Message: 4 of 6

"Nasser M. Abbasi" <nma@12000.org> wrote in message <io0uqe$6tm$1@speranza.aioe.org>...
> On 4/11/2011 11:15 PM, Shelby wrote:
>
> >
> > When I try to change the step size, then number gets further away,
> > no matter which direction I move in.
>
> Forward Euler, which is what you are using is not stable. Trye backward
> Euler, you just get better results.
>
> --Nasser

There is always a downside. Forward Euler is explicit, but instable. Backward Euler is stable, but implicit(meaning one has to solve a system). It is up to OP to decide which method is appropriate for the problem.
Regards,
Florin

Subject: Euler's Method

From: Peyman

Date: 8 Oct, 2012 11:28:07

Message: 5 of 6


> There is always a downside. Forward Euler is explicit, but instable. Backward Euler is stable, but implicit(meaning one has to solve a system). It is up to OP to decide which method is appropriate for the problem.
> Regards,
> Florin

To Florin:
You said "It is upto OP to decide which method is appropriate for the problem"
what do you mean by "methods", what "methods" options do I have? can you name some of them?
Regards,
Peyman

Subject: Euler's Method

From: Bruno Luong

Date: 8 Oct, 2012 11:51:07

Message: 6 of 6

"Peyman" wrote in message <k4udc7$64o$1@newscl01ah.mathworks.com>...
> To Florin:
> You said "It is upto OP to decide which method is appropriate for the problem"
> what do you mean by "methods", what "methods" options do I have? can you name some of them?

He already named it: Forward Euler vs Backward Euler.

Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us