How to determine if my equation is equal to, less that or more then 0?

4 ビュー (過去 30 日間)
James Perkins
James Perkins 2019 年 10 月 14 日
コメント済み: J Chen 2019 年 10 月 14 日
Hi,
Im trying to solve 2nd order ODE's and determine if the solution is critically damped, over damped or under damped.
I rearranged the formula and inputted the equation to solve the quadratic equation (which works) however i cannot get the IF statement to tell me when if D=0, D<0 or D>0. Is this running into problems with the complex numbers?
Please could someone point me in the correct direction with the IF statements?
A section of the script can be seen below:
a = 1
b = 1
c = 1
D = sqrt((b^2/(4*a^2))-(c/a));
if D>0
disp('Over Damped')
elseif D<0
disp('Under Damped')
else D==0
disp('Critically Damped')
end
  2 件のコメント
Jos (10584)
Jos (10584) 2019 年 10 月 14 日
Did you debug your code, by for instance, displaying D before the if statement (remove the semicolon)?
James Perkins
James Perkins 2019 年 10 月 14 日
Yes, this makes no difference.
In my command window i get the below
S2 =
-0.5000 - 0.8660i
D =
0.0000 + 0.8660i
ans =
logical
0
Index exceeds the number of array elements (11).

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

採用された回答

J Chen
J Chen 2019 年 10 月 14 日
  1. The result of sqrt((b^2/(4*a^2))-(c/a)) is a complex number. You can't compare it with 0 (a real number)
  2. The formula for damping ratio is probably wrong. Should it be b/(2*sqrt(a*c)?
  2 件のコメント
James Perkins
James Perkins 2019 年 10 月 14 日
  1. The result of sqrt((b^2/(4*a^2))-(c/a)) is a complex number. You can't compare it with 0 (a real number)
  2. The formula for damping ratio is probably wrong. Should it be b/(2*sqrt(a*c)?
Reply:
  1. Thank you for pointing this out, i have removed the 'sqrt' so that i just have a negative number which i should be able to relate to 0.
  2. I was told that there are different ways of determining the damping style? i have adjusted this to (b^2)-(4*a*c) which is what my lecturor has advised.
Im still getting an error saying "Index exceeds the number of array elements (11).". Can someone explain what this could be?
J Chen
J Chen 2019 年 10 月 14 日
The damping ratio is defined as r = b/(2*sqrt(a*c)) = b^2/(4*a*c). It is under damped if r<1 and critically damped if r=1, etc. Your error came from other programming error. It's not related to the formula.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by