Hi
I have this function then m and k are an input matrices having dimension (12,12) but an error message is displayed
like : Error using *
Inner matrix dimensions must agree.
Error in equabeam1 (line 9)
xdot = A*x+B*f;
Error in @(t,x)equabeam1(t,x,m,k)
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
function xdot = equabeam1(t,x,m,k)
% Function file for mass with spring.
% Position is first variable, velocity is second variable
freq=100; %frequency (Hz)
w=2*pi*freq;
A = [zeros(12,12),ones(12,12);-m^-1*k,zeros(12,12)];
B = [zeros(12,1);m^-1*ones(12,1)];
f =sin(w*t);
xdot = A*x+B*f;
end
[m,k,idof]=beam1(node,elt,pe,ie,opt)
[t,x] = ode45(@(t,x) equabeam1(t,x,m,k),[0,10],[0,0])
figure;
plot(t,x(:,1))
Please help me

 採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 13 日

0 投票

You construct your A as 24 by 24, and you do a matrix multiplication by x which is going to be 2 x 1 because your x0 of [0,0] is length 2. There is no way to multiply a 24 x 24 by a 2 x 1.
Note: I see you use m^-1 where m is a 12 x 12 matrix. That is equivalent to doing inv(m) which is an error prone operation. Instead of
-m^-1*k
you should be using
-(m\k)
and instead of
m^-1*ones(12,1)
you should be using
m\ones(12,1)

5 件のコメント

Mallouli Marwa
Mallouli Marwa 2016 年 6 月 13 日
What should i do about the dimension of x ?
Mallouli Marwa
Mallouli Marwa 2016 年 6 月 13 日
If i change it by another x(12,12) ??
Mallouli Marwa
Mallouli Marwa 2016 年 6 月 13 日
No (12,1)
Walter Roberson
Walter Roberson 2016 年 6 月 13 日
It looks to me as if you need to redesign your function. Remember you need to have as many output values as you have x input values, but your code appears to me to be designed to output only half as many outputs as inputs. But then it is not clear to me what your m and k are or where you are using the velocity information your comments mention. Your m sort of looks like a mass matrix?? If so then there are other ways of handling those; see http://www.mathworks.com/help/matlab/ref/odeset.html#zmw57dd0e573778
Mallouli Marwa
Mallouli Marwa 2016 年 6 月 13 日
m= mass matrix k= stiffness matrix

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStress and Strain についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by