Got Questions? Get Answers.
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:
Poor performance

Subject: Poor performance

From: Roman Tolmachev

Date: 12 May, 2010 10:02:03

Message: 1 of 14

Hello everyone,
I need your help with such a question: I try to plot the solution for Lorenz system, but find that matlab's performance is extremely slow. I started the program yesterday at 19.00 and it is still calculating. I tried matlabpool to use second core, but it seems no result. Is it ok that such a simple program requires so much time? What would you do in that case?
Thanks in advance, the code is below.

function lorplane(p1)
global r sigma b
sigma=10; b=8/3;
r=p1;
options=odeset('AbsTol',1e-6,'RelTol',1e-4);
xinit=sqrt(b*(r-1));
yinit=sqrt(b*(r-1));
zinit=(r-1);
[T,X]=ode45(@lorenzeqs,[0 50],[xinit yinit zinit],options);
plot(X(:,1),X(:,3))

function dx=lorenzeqs(t,x);
global r;
sigma=10; b=8/3;
dx=zeros(3,1);
dx(1)=sigma*(x(2)-x(1));
dx(2)=r*x(1)-x(2)-x(1)*x(3);
dx(3)=x(1)*x(3)-b*x(3);

Subject: Poor performance

From: Sean

Date: 12 May, 2010 12:00:22

Message: 2 of 14

"Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message <hsduar$ff4$1@fred.mathworks.com>...
> Hello everyone,
> I need your help with such a question: I try to plot the solution for Lorenz system, but find that matlab's performance is extremely slow. I started the program yesterday at 19.00 and it is still calculating. I tried matlabpool to use second core, but it seems no result. Is it ok that such a simple program requires so much time? What would you do in that case?
> Thanks in advance, the code is below.
>
> function lorplane(p1)
> global r sigma b
> sigma=10; b=8/3;
> r=p1;
> options=odeset('AbsTol',1e-6,'RelTol',1e-4);
> xinit=sqrt(b*(r-1));
> yinit=sqrt(b*(r-1));
> zinit=(r-1);
> [T,X]=ode45(@lorenzeqs,[0 50],[xinit yinit zinit],options);
> plot(X(:,1),X(:,3))
>
> function dx=lorenzeqs(t,x);
> global r;
> sigma=10; b=8/3;
> dx=zeros(3,1);
> dx(1)=sigma*(x(2)-x(1));
> dx(2)=r*x(1)-x(2)-x(1)*x(3);
> dx(3)=x(1)*x(3)-b*x(3);


What are you using for p1? It takes fractions of a second to run on any number <= 1.4. Apparently it diverges above that.

Subject: Poor performance

From: Roman Tolmachev

Date: 12 May, 2010 13:13:04

Message: 3 of 14

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hse58m$t0l$1@fred.mathworks.com>...
> "Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message <hsduar$ff4$1@fred.mathworks.com>...
> > Hello everyone,
> > I need your help with such a question: I try to plot the solution for Lorenz system, but find that matlab's performance is extremely slow. I started the program yesterday at 19.00 and it is still calculating. I tried matlabpool to use second core, but it seems no result. Is it ok that such a simple program requires so much time? What would you do in that case?
> > Thanks in advance, the code is below.
> >
> > function lorplane(p1)
> > global r sigma b
> > sigma=10; b=8/3;
> > r=p1;
> > options=odeset('AbsTol',1e-6,'RelTol',1e-4);
> > xinit=sqrt(b*(r-1));
> > yinit=sqrt(b*(r-1));
> > zinit=(r-1);
> > [T,X]=ode45(@lorenzeqs,[0 50],[xinit yinit zinit],options);
> > plot(X(:,1),X(:,3))
> >
> > function dx=lorenzeqs(t,x);
> > global r;
> > sigma=10; b=8/3;
> > dx=zeros(3,1);
> > dx(1)=sigma*(x(2)-x(1));
> > dx(2)=r*x(1)-x(2)-x(1)*x(3);
> > dx(3)=x(1)*x(3)-b*x(3);
>
>
> What are you using for p1? It takes fractions of a second to run on any number <= 1.4. Apparently it diverges above that.

Thanks for attention. According to the Lorenz system features, p1 can be bigger than 1.4, e.g. 13 or 24 and it should lead to different results, and it is my task actually to test different p1 from 10 and higher to obtain these results. I thought about Euler iterations method here, but I am not sure it will be faster...

Subject: Poor performance

From: Sean

Date: 12 May, 2010 13:28:05

Message: 4 of 14

"Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message <hse9h0$sh9$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hse58m$t0l$1@fred.mathworks.com>...
> > "Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message <hsduar$ff4$1@fred.mathworks.com>...
> > > Hello everyone,
> > > I need your help with such a question: I try to plot the solution for Lorenz system, but find that matlab's performance is extremely slow. I started the program yesterday at 19.00 and it is still calculating. I tried matlabpool to use second core, but it seems no result. Is it ok that such a simple program requires so much time? What would you do in that case?
> > > Thanks in advance, the code is below.
> > >
> > > function lorplane(p1)
> > > global r sigma b
> > > sigma=10; b=8/3;
> > > r=p1;
> > > options=odeset('AbsTol',1e-6,'RelTol',1e-4);
> > > xinit=sqrt(b*(r-1));
> > > yinit=sqrt(b*(r-1));
> > > zinit=(r-1);
> > > [T,X]=ode45(@lorenzeqs,[0 50],[xinit yinit zinit],options);
> > > plot(X(:,1),X(:,3))
> > >
> > > function dx=lorenzeqs(t,x);
> > > global r;
> > > sigma=10; b=8/3;
> > > dx=zeros(3,1);
> > > dx(1)=sigma*(x(2)-x(1));
> > > dx(2)=r*x(1)-x(2)-x(1)*x(3);
> > > dx(3)=x(1)*x(3)-b*x(3);
> >
> >
> > What are you using for p1? It takes fractions of a second to run on any number <= 1.4. Apparently it diverges above that.
>
> Thanks for attention. According to the Lorenz system features, p1 can be bigger than 1.4, e.g. 13 or 24 and it should lead to different results, and it is my task actually to test different p1 from 10 and higher to obtain these results. I thought about Euler iterations method here, but I am not sure it will be faster...

Try some of the other ode functions ode15s, ode23t etc. I tried these two and it spit back a result. The result appeared to be meaningless (10^162) but that's what it gave. Maybe there's something wrong with your Lorenz equation. Apparently there is some stiffness in this equation. I'm not familiar with it.

Good Luck!

Subject: Poor performance

From: Steven Lord

Date: 12 May, 2010 13:35:19

Message: 5 of 14


"Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message
news:hsduar$ff4$1@fred.mathworks.com...
> Hello everyone,
> I need your help with such a question: I try to plot the solution for
> Lorenz system, but find that matlab's performance is extremely slow. I
> started the program yesterday at 19.00 and it is still calculating. I
> tried matlabpool to use second core, but it seems no result. Is it ok that
> such a simple program requires so much time? What would you do in that
> case?

I tried running this for p1 = 11 with one small change -- I added one option
to your options structure.

options=odeset('AbsTol',1e-6,'RelTol',1e-4, 'OutputFcn', @odeplot);

When I did this I saw that one of the components of your system, x(3), went
to zero and remained there fairly quickly. The other two components dropped
like a stone; when I stopped the execution around t = 3, they were down in
the -2e4 range and still falling. That is likely the cause of the "slow
performance".

I would confirm that the equations you included in your function are
correct. Doing a quick comparison with those in the Wikipedia page:

http://en.wikipedia.org/wiki/Lorenz_attractor

leads me to believe that your second and third equations are not correct.
When I replaced your equations with those in that page I got something
closer to what I expected in a fraction of a second.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Poor performance

From: Sean

Date: 12 May, 2010 13:38:04

Message: 6 of 14

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hsead5$oit$1@fred.mathworks.com>...
> "Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message <hse9h0$sh9$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hse58m$t0l$1@fred.mathworks.com>...
> > > "Roman Tolmachev" <tolmachevroman@gmail.com> wrote in message <hsduar$ff4$1@fred.mathworks.com>...
> > > > Hello everyone,
> > > > I need your help with such a question: I try to plot the solution for Lorenz system, but find that matlab's performance is extremely slow. I started the program yesterday at 19.00 and it is still calculating. I tried matlabpool to use second core, but it seems no result. Is it ok that such a simple program requires so much time? What would you do in that case?
> > > > Thanks in advance, the code is below.
> > > >
> > > > function lorplane(p1)
> > > > global r sigma b
> > > > sigma=10; b=8/3;
> > > > r=p1;
> > > > options=odeset('AbsTol',1e-6,'RelTol',1e-4);
> > > > xinit=sqrt(b*(r-1));
> > > > yinit=sqrt(b*(r-1));
> > > > zinit=(r-1);
> > > > [T,X]=ode45(@lorenzeqs,[0 50],[xinit yinit zinit],options);
> > > > plot(X(:,1),X(:,3))
> > > >
> > > > function dx=lorenzeqs(t,x);
> > > > global r;
> > > > sigma=10; b=8/3;
> > > > dx=zeros(3,1);
> > > > dx(1)=sigma*(x(2)-x(1));
> > > > dx(2)=r*x(1)-x(2)-x(1)*x(3);
> > > > dx(3)=x(1)*x(3)-b*x(3);
> > >
> > >
> > > What are you using for p1? It takes fractions of a second to run on any number <= 1.4. Apparently it diverges above that.
> >
> > Thanks for attention. According to the Lorenz system features, p1 can be bigger than 1.4, e.g. 13 or 24 and it should lead to different results, and it is my task actually to test different p1 from 10 and higher to obtain these results. I thought about Euler iterations method here, but I am not sure it will be faster...
>
> Try some of the other ode functions ode15s, ode23t etc. I tried these two and it spit back a result. The result appeared to be meaningless (10^162) but that's what it gave. Maybe there's something wrong with your Lorenz equation. Apparently there is some stiffness in this equation. I'm not familiar with it.
>
> Good Luck!

Also, according to this website:
http://planetmath.org/encyclopedia/LorenzEquation.html
Your lorenz equation is wrong. It might be a different variation of it, but running it with this equation provided meaningful plots at higher values!

should be:
function dx=lorenzeqs(t,x)
   sigma=10;
   b=8/3;
   dx=zeros(3,1);
   dx(1)=sigma*(x(2)-x(1));
   dx(2)=x(1)*(28-x(3))-x(2);
   dx(3)=x(1)*x(2)-b*x(3);
end

Subject: Poor performance

From: Roman Tolmachev

Date: 12 May, 2010 14:13:04

Message: 7 of 14

> > Try some of the other ode functions ode15s, ode23t etc. I tried these two and it spit back a result. The result appeared to be meaningless (10^162) but that's what it gave. Maybe there's something wrong with your Lorenz equation. Apparently there is some stiffness in this equation. I'm not familiar with it.
> >
> > Good Luck!
>
> Also, according to this website:
> http://planetmath.org/encyclopedia/LorenzEquation.html
> Your lorenz equation is wrong. It might be a different variation of it, but running it with this equation provided meaningful plots at higher values!
>
> should be:
> function dx=lorenzeqs(t,x)
> sigma=10;
> b=8/3;
> dx=zeros(3,1);
> dx(1)=sigma*(x(2)-x(1));
> dx(2)=x(1)*(28-x(3))-x(2);
> dx(3)=x(1)*x(2)-b*x(3);
> end

Thank you guys, I made a really stupid mistake in rewriting equations and didn't checked it. I'll try new system as soon as possible.
  Thank you again and best wishes,
     Roman.

Subject: Poor performance

From: oh

Date: 19 May, 2010 19:28:04

Message: 8 of 14

You should be
 function dx=lorenzeqs(t,x)
    sigma=10;
    b=8/3;
    dx=zeros(3,1);

    dx(1)=sigma*(x(2)-x(1));
    dx(2)=x(1)*(28-x(3))-x(2);
    dx(3)=x(1)*x(2)-b*x(3);

Usually, ODE function do not use end statements.

Subject: Poor performance

From: Walter Roberson

Date: 19 May, 2010 19:35:52

Message: 9 of 14

OH wrote:
> You should be
> function dx=lorenzeqs(t,x)
> sigma=10; b=8/3;
> dx=zeros(3,1);
>
> dx(1)=sigma*(x(2)-x(1));
> dx(2)=x(1)*(28-x(3))-x(2);
> dx(3)=x(1)*x(2)-b*x(3);
>
> Usually, ODE function do not use end statements.

That's an interesting remark. Is there any reason why an ODE function should
*not* use an 'end' statement?

Subject: Poor performance

From: oh

Date: 20 May, 2010 03:17:04

Message: 10 of 14

I thinks the reason why ode functions do not use end statements.

1. not fortran compiler
As far as I know about fortran, end statements need to designate the end of program. But, Matlab do not need those command mendatory.

2. ode function related to odesolver command and do not open any function like for, if statement.

How do you think about my comment?

(for several weeks, I stick to solve ode45 function on my marine snow aggregation function. )

Subject: Poor performance

From: Walter Roberson

Date: 21 May, 2010 01:34:28

Message: 11 of 14

OH wrote:
> I thinks the reason why ode functions do not use end statements.
> 1. not fortran compiler As far as I know about fortran, end statements
> need to designate the end of program. But, Matlab do not need those
> command mendatory.

But that is not a reason to _not_ use a final 'end' statement,
especially since Matlab can do better optimization if you put the final
'end' statement in.

> 2. ode function related to odesolver command and do not open any
> function like for, if statement.

There is no reason why an 'if' or 'for' could not be used, if that made
the calculations easier.

> How do you think about my comment?

I still do not see any reason to avoid adding the 'end' statement. If
the 'end' statement shoud to be avoided, then there should be a reason,
such as "it makes the calculation slower", or "you cannot do <this> if
you have an 'end' statement and you often need to do that in ode code."
(There are a few things you cannot do if you add the 'end', having to do
with eval() and load() and assignin().)

Subject: Poor performance

From: Roman Tolmachev

Date: 21 May, 2010 04:28:03

Message: 12 of 14

Walter Roberson <roberson@hushmail.com> wrote in message <EqlJn.28017$wV2.1965@newsfe23.iad>...
> OH wrote:
> > I thinks the reason why ode functions do not use end statements.
> > 1. not fortran compiler As far as I know about fortran, end statements
> > need to designate the end of program. But, Matlab do not need those
> > command mendatory.
>
> But that is not a reason to _not_ use a final 'end' statement,
> especially since Matlab can do better optimization if you put the final
> 'end' statement in.
>
> > 2. ode function related to odesolver command and do not open any
> > function like for, if statement.
>
> There is no reason why an 'if' or 'for' could not be used, if that made
> the calculations easier.
>
> > How do you think about my comment?
>
> I still do not see any reason to avoid adding the 'end' statement. If
> the 'end' statement shoud to be avoided, then there should be a reason,
> such as "it makes the calculation slower", or "you cannot do <this> if
> you have an 'end' statement and you often need to do that in ode code."
> (There are a few things you cannot do if you add the 'end', having to do
> with eval() and load() and assignin().)
Thank you guys for so much attention for my code)) Personally, I believe that 'end' should be in the code, since I also don't see any reasons not to write it. It doesn't affect the speed of calculations, and what does is one wrong coefficient in the equation, which I wrote with mistake.
P.S. May be some of you know, how can one create an .exe file from Matlab? I mean some gui compiled into a stand-alone application to run on another computer where Matlab is not installed? I think there should be some package also that the client has to install before running such an application.

Subject: Poor performance

From: Walter Roberson

Date: 21 May, 2010 04:34:03

Message: 13 of 14

Roman Tolmachev wrote:

> P.S. May be some of you know, how can one create an .exe file from
> Matlab? I mean some gui compiled into a stand-alone application to run
> on another computer where Matlab is not installed? I think there should
> be some package also that the client has to install before running such
> an application.

You need the Matlab Compiler product. It is not really a compiler: it is
really a deployment tool, producing an executable that runs no faster
than Matlab itself. It is, though, fine for producing something that
runs on the machine of someone that does not have Matlab, and it does
not require that the people have a Matlab license (within certain limits.)

Subject: Poor performance

From: Steven Lord

Date: 21 May, 2010 14:59:57

Message: 14 of 14


"Walter Roberson" <roberson@hushmail.com> wrote in message
news:ht1ejt$h60$2@canopus.cc.umanitoba.ca...
> OH wrote:
>> You should be
>> function dx=lorenzeqs(t,x)
>> sigma=10; b=8/3;
>> dx=zeros(3,1);
>>
>> dx(1)=sigma*(x(2)-x(1));
>> dx(2)=x(1)*(28-x(3))-x(2);
>> dx(3)=x(1)*x(2)-b*x(3);
>>
>> Usually, ODE function do not use end statements.
>
> That's an interesting remark. Is there any reason why an ODE function
> should *not* use an 'end' statement?

Just keep in mind that if ANY of the functions in a file end with an END
statement (that's matched with the initial FUNCTION keyword) then they ALL
need to end with an END (at least that's been the case since nested
functions were introduced.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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