How to find unknown variable in the below equation?

1 view (last 30 days)
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

Alan Stevens
Alan Stevens on 1 Sep 2020
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
Alan Stevens
Alan Stevens on 3 Sep 2020
"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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!