Tue 22 Jan 2013 04:20:02 PM UTC, original submission:
I spent an hour writing a nice and complete bug report, but everything was deleted when I clicked the link to answer the final question!!
Sorry but I won't write again that nice report, I will just forward my original post on the forum to let you know that lsode gives incorrect results for basic linear vibration problems.
********************************************************************************
I use lsode to solve a simple standard vibration problem with Octave 3.6.1:
function ydot=f(y,t) % 2nd order equation conversion to a 1st order system
ydot(1)=y(2);
ydot(2)=eqd(t,y(1),y(2));
end
function xdd = eqd(t,x,xd) % generic vibration
m=1;
K=1;
omega=sqrt(K/m); % pulsazione naturale oscillatore
fattore_smorzamento=0.07;
S=2fattore_smorzamentom*omega;
ampiezza_forzante=1;
Omega=2.5; % pulsazione forzante
forzante=ampiezza_forzante/msin(Omegat);
xdd=(SxdKx+forzante)/m;
end
y=lsode("f",[0;0],(t=(0:0.1:20*pi)'));
figure(1);plot(t,y(:,2))
But the result is qualitatively different from a manual AdamMoulton corrector implementation which agrees with the text book the example was taken from.
Add the following code to the previous:
function [x,xd,xdd]=pred_corr(dt,tp,xp,xdp,xddp,tol)
% tp, xdp, xddp are values of t, xd and xdd at previous step
xddg=xddp; % as initial guess xdd is taken same as xddp
for j=1:100
xd=xdp+dt/2*(xddp+xddg);
x=xp+dt/2*(xdp+xd);
xdd=eqd(tp+dt,x,xd);
if abs(xddxddg)<tol
break;
else
xddg=xdd;
end
end
end
dt=.1;
tv=0:dt:20*pi;
t=tv(1);
x=0; % initial values
xd=0;
xdd=eqd(t,x,xd);
xv=[x];
for t=tv(1:end1)
[x,xd,xdd]=pred_corr(dt,t,x,xd,xdd,.000001);
%display([t+dt x xd xdd])
xv(end+1)=x;
end
figure(2);plot(tv,xv)
*****************************************************************************
Here is the analytic solution found with Maxima (copy and paste it):
x:%e^(omegatxi)(((4omega^2Omegaxi^2+2Omega^32omega^2Omega)sin((tsqrt(4omega^24omega^2xi^2))/2)F)/(4momega^2Omega^2xi^2sqrt(4omega^24omega^2xi^2)+mOmega^4sqrt(4omega^24omega^2xi^2)2momega^2Omega^2sqrt(4omega^24omega^2xi^2)+momega^4sqrt(4omega^24omega^2xi^2))+(2omegaOmegaxicos((tsqrt(4omega^24omega^2xi^2))/2)F)/(4momega^2Omega^2xi^2+mOmega^42momega^2Omega^2+momega^4))
((2omegaOmegacos(Omegat)xi+(Omega^2omega^2)sin(Omegat))F)/(4momega^2Omega^2xi^2+mOmega^42momega^2Omega^2+m*omega^4);
m:1;
omega:1;
xi:0.07;
Omega:2.5;
F:1;
load("draw");
draw2d(explicit(x,t,0,50));
