Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: code operating speed is very slow
Replies: 1   Last Post: May 13, 2010 8:07 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Wenxu Li

Posts: 11
Registered: 5/13/10
code operating speed is very slow
Posted: May 13, 2010 4:05 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I try to simulate a one DoF mass-spring system,the code is as follows:
%M02, solution
tspan=0:0.06:10*pi;
x0=[0;5.0];
[t,x]=ode23w('friction_force',tspan,x0);
plot(t,x(:,1));

%function
function y=friction_force(t,x)
m=1;
k=1;
Frictionforce=10;
y=zeros(2,1);
y(1)=x(2);
y(2)=-Frictionforce*sign(x(2))/m-k/m*x(1);

My question is when I use y(2)=Frictionforce*sign(x(2))/m-k/m*x(1), i.e. without minus
before Frictionforce, the code operates very quickly, while I add a minus, it is very slow, more than half an hour to get the results. Can anybody tell what is the matter?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.