How to find unknown variable in the below equation?
1 回表示 (過去 30 日間)
古いコメントを表示
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?
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 で Assumptions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!