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.

1 次查看(过去 30 天)
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)

采纳的回答

Walter Roberson
Walter Roberson 2017-11-16
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.

更多回答(1 个)

Birdman
Birdman 2017-11-16
编辑:Birdman 2017-11-16
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 个评论
aldo angulo
aldo angulo 2017-11-16
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."

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by