Error use mupadengine/feval_internal
2 views (last 30 days)
Show older comments
I am trying to solve a cubic equation, but getting the following error
Error use mupadengine/feval_internal
No complex subexpressions allowed in real mode.
My code:
syms sita1
a = abs(H(:,u)' * w1(:, m))^2;%5
b = H(:,u)' * w(:, j) * w1(:, m)' * H(:,u); %3
c = g(1,u) * w1(:, m)' * H(:,u); %2
d = alpha1 * phi(1,u) + rho/2;
h = -a * gamma^2 * sita1^3 + (gamma^3 * sigma - 2 * gamma * d *a - gamma^2 * phi(1, u) * a...
+gamma^2 * c - gamma^2 * b) * sita1^2 + (2 * gamma^2 * sigma * d - d^2 * a - 2 * gamma * ...
phi(1,u) * d * a + 2 * gamma * d * (c - b)) * sita1 + gamma * sum_w(1,j) + d^2 * gamma...
* sigma - phi(1, u) * d^2 * a + d^2 * (c - b);
sita1 = solve(h == 0, sita1, 'Real',1);
sita1 = double(sita1);
0 Comments
Answers (1)
Harshavardhan
on 6 Mar 2025
Hi @萌 孟
I see that you are trying to solve a cubic equation and find real solutions using “solve”.
The error suggests that some coefficients of “sita1” in the equation “h” are not real. Make sure to check that all your inputs and coefficients are real if that's your requirement.
If the coefficients are meant to be complex, you can address the error by allowing “solve” to solve for all solutions and then select only the real solutions.
To do this, the line
sita1 = solve(h == 0, sita1, 'Real',1);
should be replaced with
sita1 = solve(h == 0, sita1);
sita1 = double(sita1);
sita1 = sita1(imag(sita1) == 0);
For more information on “solve” and “imag” you can refer to the following links:
Or you can type the following lines in a MATLAB command window for version specific documentation:
doc solve
doc imag
0 Comments
See Also
Categories
Find more on Gamma Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!