How to determine if my equation is equal to, less that or more then 0?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
James Perkins
el 14 de Oct. de 2019
Comentada: J Chen
el 14 de Oct. de 2019
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 comentarios
Jos (10584)
el 14 de Oct. de 2019
Did you debug your code, by for instance, displaying D before the if statement (remove the semicolon)?
Respuesta aceptada
J Chen
el 14 de Oct. de 2019
- 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)
- The formula for damping ratio is probably wrong. Should it be b/(2*sqrt(a*c)?
2 comentarios
J Chen
el 14 de Oct. de 2019
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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!