"Jan Simon" wrote in message <ks0q2f$rla$1@newscl01ah.mathworks.com>...
> Dear Lauara,
>
> Follow the standard approach directly:
>
> > Mx’’+Cx’+Kx=P(t)
> > x'' = inv(M) * (P(t) - Cx' -Kx)
>
> Lookup table: y1 = x, y2 = x', y3 = x''
>
> dydt(1) = y(2);
> dydt(2) = (P(t) - C * y(2) - K * y(1)) \ M;
>
> Or you could expand M to work with the vector y.
>
> Kind regards, Jan
Thank you so much Jan for your response. I have written the code as you said:
tspan=[0 0.25 0.5];
y0=zeros(76,1);
yp0=zeros(76,1);
[T,Y]=ode15i(@(t,y) Differential_Equation_Solver(t,y,K,M,C,P),tspan,y0,yp0);
%%%%%%%
function dydt=Differential_Equation_Solver(t,y,K,M,C,P)
dydt(1) = y(2);
dydt(2) = M\(P-C*y(2)-K*y(1));
end
But I am still getting an error for the number of the input arguments:
Too many input arguments.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15i (line 117)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, ~, odeFcn, ...
Error in Bridge_Displacement (line 49)
[T,Y]=ode15i(@(t,y) Differential_Equation_Solver(t,y,K,M,C,P),tspan,y0,yp0);
why do you think this format is wrong and how should I fix it?
Again, Thank you very much for your useful tip.
> Dear Lauara,
>
> Follow the standard approach directly:
>
> > Mx’’+Cx’+Kx=P(t)
> > x'' = inv(M) * (P(t) - Cx' -Kx)
>
> Lookup table: y1 = x, y2 = x', y3 = x''
>
> dydt(1) = y(2);
> dydt(2) = (P(t) - C * y(2) - K * y(1)) \ M;
>
> Or you could expand M to work with the vector y.
>
> Kind regards, Jan
Thank you so much Jan for your response. I have written the code as you said:
tspan=[0 0.25 0.5];
y0=zeros(76,1);
yp0=zeros(76,1);
[T,Y]=ode15i(@(t,y) Differential_Equation_Solver(t,y,K,M,C,P),tspan,y0,yp0);
%%%%%%%
function dydt=Differential_Equation_Solver(t,y,K,M,C,P)
dydt(1) = y(2);
dydt(2) = M\(P-C*y(2)-K*y(1));
end
But I am still getting an error for the number of the input arguments:
Too many input arguments.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15i (line 117)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, ~, odeFcn, ...
Error in Bridge_Displacement (line 49)
[T,Y]=ode15i(@(t,y) Differential_Equation_Solver(t,y,K,M,C,P),tspan,y0,yp0);
why do you think this format is wrong and how should I fix it?
Again, Thank you very much for your useful tip.