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

2 views (last 30 days)
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);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Apr 2014
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

More Answers (0)

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!