Error using mtimes Inner matrix dimensions must agree

hi hope anyone can help me with solving the problem. the system is
m=4.2*10^3, c=2.8*10^3, k=2*10^4, y0=0.4,
where p=sqrt((k/m)-(c^2/4m^2) and
n=c/2m
y(t)=exp(-n*t)(y0cos(pt)+y0sin(pt)(n/p));
to solve it i have done
>> m=4.2*10^3;
>> c=2.8*10^3;
>> k=2*10^4;
>> t=linspace(0,10,100);
>> p=sqrt((k/m)-((c^2)/(4*m^2)));
>> n=(c/(2*m));
>> y0=0.4;
when i use all info in the eq Y(t) it gives an error
>> y(t)=(exp(-n*t))*((y0*cos(p*t))+(y0*(n/p)*sin(p*t)));
??? Error using ==> mtimes Inner matrix dimensions must agree.
can anyone please point out my mistake and show me how to plot y(t) against t.
thanks

 採用された回答

Sean de Wolski
Sean de Wolski 2014 年 10 月 20 日
編集済み: Sean de Wolski 2014 年 10 月 20 日

0 投票

You are calling * for multiplication which means it's trying to do a matrix multiply. In order to do an elementwise multiple, use .*. To help:
>>vectorize '(exp(-n*t))*((y0*cos(p*t))+(y0*(n/p)*sin(p*t)))'
ans =
(exp(-n.*t)).*((y0.*cos(p.*t))+(y0.*(n./p).*sin(p.*t)))
And use this as right hand side

1 件のコメント

salman
salman 2014 年 10 月 20 日
to find the real roots im trying fzero() function but it also gives error
x=fzero((exp(-n.*t)).*((y0.*cos(p.*t))+(y0.*(n./p).*sin(p.*t))),t)
??? Error using ==> fzero at 169 FUN must be a function, a valid string expression, or an inline function object.

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

その他の回答 (1 件)

Matt J
Matt J 2014 年 10 月 20 日
編集済み: Matt J 2014 年 10 月 20 日

0 投票

y = vectorize( @(t) (exp(-n*t))*((y0*cos(p*t))+(y0*(n/p)*sin(p*t))) );
t=linspace(...);
plot(t,y(t));

カテゴリ

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

質問済み:

2014 年 10 月 20 日

コメント済み:

2014 年 10 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by