필터 지우기
필터 지우기

Matrices in ODE function

조회 수: 2 (최근 30일)
Mahmoud Madany
Mahmoud Madany 2018년 4월 7일
답변: Abraham Boayue 2018년 4월 9일
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
Walter Roberson
Walter Roberson 2018년 4월 7일
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).

댓글을 달려면 로그인하십시오.

답변 (1개)

Abraham Boayue
Abraham Boayue 2018년 4월 9일
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?

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by