index must be a positive integer or logical.

%Programme to model Damped free vibration in a cannon %clear Screen clear; %define constants m=500; k=10000; %Evaluate natural frequency wn=sqrt(k/m) %Evaluate natural time period tn=(2*pi)/wn %Enter initial conditions xmax=0.4; %calculate critical damping constant cc=2*m*wn %set initial displacement & velocity xo=0; xdz=xmax*wn*exp(1); z=1.5; %defining constants C1 & C2 C1=(wn(z+sqrt(z^2-1))+xdz)/(2*wn*(sqrt(z^2-1))) C2=(wn(z-sqrt(z^2-1))-xdz)/(2*wn*(sqrt(z^2-1)))
But I'm getting an error Attempted to access wn(2.61803); index must be a positive integer or logical. Error in Cannon2 (line 20) C1=(wn(z+sqrt(z^2-1))+xdz)/(2*wn*(sqrt(z^2-1)))
In the workspace it's calculated at 4.4721 and I've used term wn in previous code and it worked fine without being an integer

 採用された回答

Michael Haderlein
Michael Haderlein 2014 年 10 月 28 日

0 投票

I dont know how this equation should read, but might there be a * missing? You write
C1=(wn(z+sqrt(z^2-1))+xdz)/(2*wn*(sqrt(z^2-1)))
but you might mean
C1=(wn*(z+sqrt(z^2-1))+xdz)/(2*wn*(sqrt(z^2-1)))
Same for C2.

1 件のコメント

Gary
Gary 2014 年 10 月 28 日
That fixed it, schoolboy error.
Thank you Michael

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2014 年 10 月 28 日

コメント済み:

2014 年 10 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by