ODE with matrix DYNAMIC problem
显示 更早的评论
Hi all, I am trying to solve the system below using ODE23s...at the moment it is a classical system to study the structural response under a general excitation.
[M]{x''} +[C]{x'} + [K]{x} = Fcos(t)
in order to use ODE I changed the system to a serie of first order equations:
y=x' and then z=[x,y]...now the system is:
[M]{z(2)'} +[C]{z(2)} + [K]{Z(1)} = Fcos(t)
then I wrote these 2 lines of code:
ic=[0 1]; %initial displacement and velocity
tspan=[0 4];
disp = @(t,z)[z(2);-(C*inv(M)).*z(2)-(K*inv(M)).*z(1)-(eye(4).*cos(t))];
[t,y] = ode23s(disp, tspan, ic);
but I get this error every time :
Error using vertcat Dimensions of matrices being concatenated are not consistent.
M C and K are all 4x4 matrix...I have 4 mass and so as output I should have 4 solutions ( vibration of each mass)
any idea?
Thank you in advance
回答(2 个)
James Tursa
2017-3-7
编辑:James Tursa
2017-3-7
0 个投票
If M, C, and K are all 4x4, then I would conclude that x must be a 4x1 vector. If this is true, then you have four 2nd order equations, which would mean you need to rewrite everything as eight 1st order equations. I.e., you are going to have z(1) -> z(8), not just z(1) and z(2). Also, it appears you have your inv(M) in the wrong place (should be inv(M)*C and inv(M)*K instead of what you currently have). And you seem to be completely missing the inv(M)*F part. (i.e., you seem to have solved that equation incorrectly).
Jan
2017-3-7
Code in anonymous functions is stuffed. Prefer a normal function to use the available space.
In your code
[z(2); -(C*inv(M)).*z(2)-(K*inv(M)).*z(1)-(eye(4).*cos(t))]
You have a scalar as first element and a 4x4 matrix on the right side. This cannot work.
The conversion from
[M]{x''} +[C]{x'} + [K]{x} = Fcos(t)
to
[M]{z(2)'} +[C]{z(2)} + [K]{Z(1)} = Fcos(t)
is not correct already, when [M], [C] and [K] are matrices. Write down the equations on paper again and perform the conversion again using components. Finally the replied dz should be a [2 x 1] vector, when the initial value has 2 components also.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!