Borrar filtros
Borrar filtros

When I enter the following code in 2017 MATLAB it gives me a nonsense answer, or so it is to me. does some one know how to fix it? i am trying to solve for w and the second one does give the right answer but the first one does not.

2 visualizaciones (últimos 30 días)
Code entered:
format compact
syms w;
y = solve( ( 5 / ( (-1.5*w^2)^2 + ( w - 0.5*w^3 )^2 )^(1/2) ) - 1 );
x = solve( (-pi/2) - atan(w/2) - atan(w) + (pi) );
disp(y);
disp(x);
num = [5];
den = [0.5 1.5 1 0];
G = tf(num, den);
bode(G), grid
margin(num, den);
answer given:
root(z^6 + 5*z^4 + 4*z^2 - 100, z, 1)
root(z^6 + 5*z^4 + 4*z^2 - 100, z, 2)
root(z^6 + 5*z^4 + 4*z^2 - 100, z, 3)
root(z^6 + 5*z^4 + 4*z^2 - 100, z, 4)
root(z^6 + 5*z^4 + 4*z^2 - 100, z, 5)
root(z^6 + 5*z^4 + 4*z^2 - 100, z, 6)
2^(1/2)

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Nov. de 2017
I would suggest instead
vpa(y)
There are 6 solutions. vpasolve() would pick one of them, but there is no inherent reason to favour one over another.
If it is known that the solution should be a positive value, then add that as an assumption:
syms w positive
y = solve( ( 5 / ( (-1.5*w^2)^2 + ( w - 0.5*w^3 )^2 )^(1/2) ) - 1 );
This will get you the exact solution, though you may wish to simplify(y), which would give you
(3^(1/2)*((1315 - 6*47973^(1/2))^(1/3) + (6*47973^(1/2) + 1315)^(1/3) - 5)^(1/2))/3
You could vpa() that or you could double() that depending on your needs.

Más respuestas (1)

Birdman
Birdman el 16 de Nov. de 2017
Editada: Birdman el 16 de Nov. de 2017
y = vpasolve( ( 5 / ( (-1.5*w^2)^2 + ( w - 0.5*w^3 )^2 )^(1/2) ) - 1 );
disp(y)
Solve returns symbolic solutions, vpasolve returns numeric solutions.
  2 comentarios
aldo angulo
aldo angulo el 16 de Nov. de 2017
Thanks a lot, it solved the issue and you saved me a lot of time. I was using the 2011 version and the command solve would get the job done but I really had no clue about what you stated "Solve returns symbolic solutions, vpasolve returns numeric solutions."

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by