Solve Equation which has 2 solutions but returns imaginary numbers

25 views (last 30 days)
So I have this super complicated equation which I wanted to rearranged to find Beta which is symbolic. There should be 2 solutions of Beta but when I solve it, it returns an imaginary number rather than the 2 solutions. Intitally I thought I was typing the equation in wrong so I broke it down signifcantly but still returned the same imaginary number. Can anyone help? I have attached an image of the orignal equation so you can see what it is
syms Beta
Gamma=1.4
Theta=[ 15]
M_1=2
Ans=tan(Theta)
Mult=2*cot(Beta)
NumMult=(M_1^2)*((sin(Beta))^2)
Num=NumMult-1
DenomMult_1=M_1^2
DenomMult_2=(Gamma+cos(2*Beta))
DenomMult=DenomMult_1*DenomMult_2
Denom=DenomMult+2
Fract=Num/Denom
equ=(Ans==Mult*Fract)
Beta_sol=solve(equ,Beta)
Beta_sol=double(Beta_sol)

Answers (1)

John D'Errico
John D'Errico on 27 Sep 2021
Edited: John D'Errico on 27 Sep 2021
Super-complicated? Seriously? :) NOT. But I suppose complexity is in the eyes of the beholder.
Start with this:
Theta=[ 15]
Theta = 15
That strongly suggests that theta, clearly an angle of some sort, is in degrees. (You don't need the brackets to define a scalar. As well, you should learn to terminate lines with a semi-colon.)
Why do I say this is clearly degrees? Because if it were in terms of radians, 15 radians is equivalent to
rad2deg(15) % radians to degrees, multiply by 180/p1
ans = 859.4367
This is way larger than 360 degrees. So it seems clear that you are thinking in terms of degrees. It also suggests, that if Theta were really 859.4367... degrees, then the solution might be complex valued. It might be. I have not checked to see if your messy code is actually correct for the not that complex equation you showed.
But to work in degrees, you need to use the functions tand, cosd, sind, etc. Nothing you have done here will make sense, because the functions sin, cos, tan, etc., all use RADIANS. You really need to read the getting started tutorials. Also, get used to the idea that radians are actually a better way to do mathematics, at least as you progress further in mathematics, engineering or the sciences. It will make your life easier in the long term. That is your choice though.
You want to solve the equation for beta. How would use use the symbolic TB to do that?
syms Beta
Theta = 15; % assuming this is degrees
M_1 = 2; % Note the semicolons
Gamma = 1.4;
Eqn = 2*cotd(Beta)*(M_1^2*sind(Beta).^2 - 1)/(M_1^2*(Gamma + cosd(2*Beta)) + 2);
When you break it down into so many sub-terms, this merely makes it MUCH more likely you will make a mistake in one of those terms. Instead, just learn to write code in MATLAB. Then display the result, to make sure it is as you intended.
Eqn
Eqn = 
As you should see, the symbolic toolbox converted the cotd, sind and cosd terms into sines and cosines that are defined in terms of radians. Beta and Theta are still in degrees though.
But now we can solve for a result.
Betasol = solve(Eqn,Beta)
Betasol = 
That finds 3 reasonable solutions. And the fact that they are reasonable numbers one would expect to see in the context of degrees makes me more positive that you are thinking in terms of degrees.
Of course, while it found exactly 3 solutions, since this involves periodic functions, we can probably add integer multiples of 180 (degrees) to get new solutions. Only multiples of 180 happens because you have a cos(2*Beta) in your equation. We can find the complete family of solutions as:
Betasol = solve(Eqn,Beta,'returnconditions',true)
Betasol = struct with fields:
Beta: [3×1 sym] parameters: k conditions: [3×1 sym]
Betasol.Beta
ans = 
Betasol.conditions
ans = 
So for integer values of k, we can add any integer multiple of 180 degrees to the base solutions.
Regardless, I think this is what you were looking to find. In the end, it all came down to your assumption that functions like sin, cos, and cot are all defined in terms of degrees. They use radians.
  2 Comments
katherine keogh
katherine keogh on 27 Sep 2021
Edited: katherine keogh on 27 Sep 2021
Okay. Thank you for your help. Maybe don't insult the people you are trying to help, clearly in your opinion I need to learn some more MATLAB but you need to learn some people skills and respect!
katherine keogh
katherine keogh on 27 Sep 2021
Also using the above solution produces the wrong answers, I am trying to make the M=2 curve and finding what Beta is when Theta is equal to 15 degrees and it would appear that the answer your code produces is wrong. Would you know how to solve this now?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!