Matrices in ODE function

1 view (last 30 days)
Mahmoud Madany
Mahmoud Madany on 7 Apr 2018
Answered: Abraham Boayue on 9 Apr 2018
I have this ODE Function where Mn, Kn, Kb, and Gamma are Matrices. ag is a ground motion records (attached txt file) , ts and ag have the same length. Attached the script, the Function, and the text file.
The Script
Gamma=[0.5637,0,0;0,0.3413,0;0,0,0.094];
Mn=[5443,0,0;0,1175,0;0,0,2105];
Kn=[3315304,0,0;2.0,547601,0;0,0,1968524];
Kb=[38013,0,0;0,19006,0;0,0,11404];
C_alpha_1=43180;
g=9.81;
ag=dlmread('ElCentro.txt');
ts=[0:0.01:40]';
IC = zeros(3);
[T, Y]=ode23s(@(t,y)fvdfn(t,y,ts,ag,g,Gamma,Mn,Kn,Kb,C_alpha_1),ts,IC);
The Function
function [ yp ] = fvdfn(t,y,ts,ag,g,Gamma,Mn,Kn,Kb,C_alpha_1)
agt=interp1(ts,ag,t);
X1=y(2);
X2=Gamma*agt*g+(Kn/Mn)*y(1)+y(3)./Mn;
X3=Kb*y(2)-Kb*y(3)/C_alpha_1;
yp=[X1; X2; X3];
end
Then I called this function inside the script, when I run the script I get an error that the dimensions of matrices being concatenated are not consistent. I expect to get a matrix of three columns for y(1), y(2), and y(3) with a length same as vector ag. Any help to get rid of this error.
  1 Comment
Walter Roberson
Walter Roberson on 7 Apr 2018
You have X1 = y(2) which is a scalar. A scalar is not a vector of the same length as ag.
Note that if you did get out a length(ag) by 3 array that ode23s would reject it:
The function dydt = odefun(t,y), for a scalar t and a column vector y, must return a column vector dydt of data type single or double that corresponds to f(t,y).

Sign in to comment.

Answers (1)

Abraham Boayue
Abraham Boayue on 9 Apr 2018
I find it a bit odd to follow your system of equations, your derivities are given in x1, x2, and x3 and you are trying to find y1 , y2 and y3? Is this really correct? Can you post the equations as they were given instead?

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!