How to find unknown variable in the below equation?

I wish to solve the equation as shown below:
So, I made a new variable "A1" as coded below with i/p parameters.
r = 3.88;
Vau = 43;
theta_u = 71.8;
gamma = 5/3;
Vsu = 47.45;
syms Unu
A1 = double(solve(((Unu^2 - (r * Vau^2 *(cosd(theta_u))^2))^2) * (Unu^2 - ((2 * r * Vsu^2)/(r+1-gamma*(r-1)))) - ((r * (sind(theta_u)^2) * Unu^2 * Vau^2) *((2 * r - gamma * (r-1))*(Unu^2)/(r+1-gamma(r-1)) - r * Vau^2 * (cosd(theta_u))^2))))
A1 shows error like:
Subscript indices must either be real positive integers or logicals.
Error in IPS_P2 (line 333)
A1 = double(solve(((Unu^2 - (r * Vau^2 *(cosd(theta_u))^2))^2) * (Unu^2 - ((2 * r * Vsu^2)/(r+1-gamma*(r-1)))) - ((r * (sind(theta_u)^2) * Unu^2 * Vau^2) *((2 * r - gamma * (r-1))*(Unu^2)/(r+1-gamma(r-1)) - r * Vau^2 * (cosd(theta_u))^2))))
Can anyone please help me, if there is any error in coding equation?

 Accepted Answer

The equation is a cubic in Unu^2, so the following uses roots to find solutions:
r = 3.88;
Vau = 43;
theta_u = 71.8;
gamma = 5/3;
Vsu = 47.45;
A = r*Vau^2*cos(theta_u)^2;
B = 2*r*Vsu^2/(r+1-gamma*(r-1));
C = r*Vau^2*sin(theta_u)^2;
D = (2*r - gamma*(r-1))/(r+1 - gamma*(r - 1));
% Let x = Unu^2
% (x - A)^2*(x - B) - C*x*(D*x - A) = 0
% (x/A - 1)^2*(x/A - B/A) - C/A*(x/A)*(D*x/A - 1) = 0
% Let y = x/A
% (y^2 - 2y + 1)*(y - B/A) - D*C/A*y^2 + C/A*y = 0
% Expand and collect like terms to get:
% y^3 -(2 + B/A + D*C/A)y^2 + (1 + 2*B/A + C/A)y - B/A = 0
p = [1; -(2 + B/A + D*C/A); (1 + 2*B/A + C/A); -B/A];
y = roots(p);
x = A*y; % reconstruct x
Unu = sqrt(x); % reconstruct Unu
disp(y)
disp(x)
disp(Unu)
% Check (f should be zero)
f = polyval(p,y);
disp(f)

6 Comments

As is often the case, Alan has shown that just because you don't know the value of a variable, this does not mean it must be made symbolic. All the symbolic parameter does is make the solution happen considerably slower.
A symbolic solution here would be useful only if you truly wanted to see an algebraic form for the solution. Since this is a cubic polynomial at heart, that is doable. But roots can handle a cubic far faster and more efficiently.
@ Alan Stevens : thank you so much spending your valuable time on this. However, I see that the answer of Unu is 678 (in my text refrences). I dont know how to find this answer from the above equation using above input parameters. I am unsure if solving this equation would lead me to this answer. Could you please help?
Ah! The problem seems to be that i used the constants exactly as you specified them. This means I used theta_u = 71.8. However, If you change theta_u to 71.8*pi/180 (i.e. turn degrees into radians), Matlab produces Unu = 677.25.
(Alternatively, you could keep theta_u as 71.8 and use cosd and sind instead of cos and sin).
@ Alan Stevens, Great!! That was such a great great help. That woked. So happy.
Could you please tell what difference does that make if i use "Solve" and "Roots"?
"solve" produces a symbolic solution, but not all equations have symbolic solutions. "roots" provides numerical solutions only. As John said (above) "roots" is faster and more efficient.
Great. Thank you so much

Sign in to comment.

More Answers (0)

Asked:

on 1 Sep 2020

Commented:

on 3 Sep 2020

Community Treasure Hunt

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

Start Hunting!