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!