Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error in syms x, subs (1/x, x, 0)

185 views
Skip to first unread message

Joerg Buchholz

unread,
Mar 28, 2015, 1:55:02 PM3/28/15
to
Matlab can divide by zero:

>> 1/0

ans =

Inf

Matlab can also symbolically divide by zero:

>> 1/sym(0)

ans =

Inf

But if we use the subs command Matlab throws an error:

>> syms x
>> subs (1/x, x, 0)
Error using symengine (line 59)
Division by zero.

I filed a bug report, but an employee of The MathWorks said this is expected behavior. I think it is unexpected, unnecessary, inconsistent, and dangerous. Could you please help me to convince The MathWorks to reimplement the pre-R2013a behavior that subs (1/x, x, 0) correctly returns Inf?

Nasser M. Abbasi

unread,
Mar 28, 2015, 3:34:52 PM3/28/15
to
You can always add catch

------------------------
syms x
try
subs(1/x,x,0)
catch ME
x=Inf
end
--------------------

x =
Inf

Check catch help to customize this more to only catch this specific error.

Different software does this differently. Maple also gives error

--------------------
restart;
r:=1/0;
Error, numeric exception: division by zero
------------------------

Mathematica throws an error but also returns infinity

-------------------------------
In[16]:= r = 1/0;
Power::infy: Infinite expression 1/0 encountered. >>
In[17]:= r
Out[17]= ComplexInfinity
---------------------------------

So it depends on implementation. Matlab choose one way to do it.

So use catch.

--Nasser








Joerg Buchholz

unread,
Apr 5, 2015, 5:45:27 AM4/5/15
to
"Nasser M. Abbasi" wrote in message <mf6vok$9jj$1...@speranza.aioe.org>...
> So use catch.
>
> --Nasser

Nasser,

don't you think it is inconsistent that 1/sym(0) returns inf, but subs (1/x, x, 0) throws an error?

Jörg

Nasser M. Abbasi

unread,
Apr 5, 2015, 6:03:34 AM4/5/15
to
yes, it is inconsistent. All I can add, is how Maple and Mathematica do it:

Maple:

-----------------------------------
1/0;
Error, numeric exception: division by zero
subs(x=0,1/x)
Error, numeric exception: division by zero
------------------------

Mathematica:

----------------------
In[1]:= 1/0
Out[1]= ComplexInfinity

In[2]:= 1/x /. x -> 0
Out[2]= ComplexInfinity
---------------------

I do not know what Matlab does not differently in your example.
But note that using Mupad directly, it does not do it as you show:

-----------------------------------
>>evalin(symengine, '1/0')
Error using symengine (line 59)
Division by zero.

>> evalin(symengine, 'subs(1/x,x=0)')
Error using symengine (line 59)
Division by zero.
---------------------------------

So the 1/sym(0) giving Inf must be have been short-circuited to
Matlab numerical evaluator, since 1/0 gives Inf and it was
not send to the syms engine. i.e. 1/sym(0) was just treated
as 1./0. (adding syms to 1 did not make any change).

--Nasser

Loren Shure

unread,
Apr 6, 2015, 8:00:34 AM4/6/15
to

"Joerg Buchholz" <buch...@hs-bremen.de> wrote in message
news:mfr07h$m65$1...@newscl01ah.mathworks.com...
Please report the inconsistent behavior to tech support so someone in
development can take a look.

Thanks.

--
--Loren

http://blogs.mathworks.com/loren

0 new messages