How to find unknown variable in the below equation?
2 次查看(过去 30 天)
显示 更早的评论
I wish to solve the equation as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/354485/image.jpeg)
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?
0 个评论
采纳的回答
Alan Stevens
2020-9-1
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 个评论
Alan Stevens
2020-9-3
"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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!