Hello, I am trying to solve a system of ODEs with the following function and solver:
function dy=response_h(t,y)load('Matrices.mat') %loads the workspace to obtain coefficients
dy=zeros(2,1);K=Stiff(1,1);C=C_damp(1,1);M=M_inertia(1,1);dy(1)=y(2);dy(2)=-(K/M)*y(1)-(C/M)*y(2);
The ode45 solver (in the script that the Matrices.mat workspace is from):
[T,Yh]=ode45(@response_h,[0 100],[1 0]);[T,Ya]=ode45(@response_a,[0 100],[1 0]);[T,Yb]=ode45(@response_b,[0 100],[1 0]);plot(T,Yh(:,1))figureplot(T,Ya(:,1))figureplot(T,Yb(:,1))
The other response functions are identical to response_h only they call out different coefficients from the respective matrices.
The error I am getting:
??? Attempted to access y(2); index out of bounds because numel(y)=1.Error in ==> response_h at 7dy(1)=y(2);Error in ==> odearguments at 110f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...Error in ==> AA554HW1 at 139[T,Yh]=ode45(@response_h,[0 100],[1 0]);
I am relatively new to these types of MATLAB functions, but I do know that the y(2) element doesn't seem to exist, even though I have the correct number of elements in my I.C. vector. Any help for this would be great. Thanks!
Best Answer