Why does "solve" throw an error when I try to solve a simple equation containing an integral in MATLAB?

1 回表示 (過去 30 日間)
I am getting an error when trying to solve the very simple equation:
 
y + y*I == 0
 
where "I" is an integral that does not depend on "y":
>> syms x
>> I = int(-(1+1/x)*exp(-1/2*log(x)^2), x, 0.01, 1);
>> syms y
>> solve(y + I*y == 0, y)
Error using mupadengine/feval (line 157)
MuPAD error: Error: The second argument must be of form x or x = a..b. [int]
Error in *solve* (line 170)
sol = eng.feval('symobj::solvefull',eqns,vars);
 
Is this a bug?
Also, how can I solve the same equation in case the integral depends on the unknown "y"? For example:
syms x y
f = y + int(-exp(-log(x)^2/2)*(y+ y/x), x, 0.01,1);

採用された回答

MathWorks Support Team
MathWorks Support Team 2014 年 4 月 25 日
There is a bug in the Symbolic Math Toolbox that affects release R2014a and prior. The bug causes the "int" function to return an invalid syntax -- it is a mix of MuPAD and MATLAB syntax. Thus, the "solve" function thinks that "x" is an unknown and cannot solve the equation.
  1. If the integral is a constant
As a workaround, if integral "I" is a constant, you can numerically approximate its value using the "vpa" function:
>> syms x
>> I = int(-(1+1/x)*exp(-1/2*log(x)^2), x, 0.01, 1);
>> syms y
>> solve(y + vpa(I)*y == 0, y)
ans =
0
  2. If the integral depends on the unknown
If integral "I" depends on "y", you can use the MuPAD "simplify" and "solve" functions with "feval" as follows:
>> syms x y
>> f = y + int(-exp(-log(x)^2/2)*(y+ y/x), x, 0.01,1);
>> simplify(feval(symengine, 'solve', f, y))
ans =
0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by