From: Wenxu Li on 13 May 2010 04:05 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?
From: Roger Stafford on 13 May 2010 08:07 "Wenxu Li" <lwxlee(a)gmail.com> wrote in message <hsgbs1$nvf$1(a)fred.mathworks.com>... > 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? The dynamics of the system will be entirely different with and without that minus sign. With the minus sign present, representing an actual retarding friction force, the mass can get stuck in a situation where the velocity is zero and the frictional force alternates back and forth rapidly. Such a discontinuity would slow down the functioning of the algorithm greatly since it is designed to handle continuous functions. Without the minus sign the oscillations back and forth take on wider and wider swings so that there is no stuck-at-zero-velocity situation occurring. Hence the discontinuity has far less effect on the speed of the algorithm. However, it is not a realistic way for friction to behave. Roger Stafford
|
Pages: 1 Prev: check if matrix contains zero or not Next: convert my condition logic to if statement |