当符号数学工具箱用于评估为NaN时,除以零错误 [英] Symbolic Math Toolbox hitting divide by zero error when it used to evaluate to NaN

查看:128
本文介绍了当符号数学工具箱用于评估为NaN时,除以零错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于更新到了Matlab 2014a.我有许多使用Symbolic Math Toolbox的脚本,这些脚本过去可以正常工作,但是现在出现以下错误:

I've just updated to Matlab 2014a finally. I have loads of scripts that use the Symbolic Math Toolbox that used to work fine, but now hit the following error:

Error using mupadmex
Error in MuPAD command: Division by zero. [_power]
  Evaluating: symobj::trysubs

我无法在此处发布我的实际代码,但这是一个简化的示例:

I can't post my actual code here, but here is a simplified example:

syms f x y
f = x/y
results = double(subs(f, {'x','y'}, {1:10,-4:5}))

在我的实际脚本中,我将两个23x23的值网格传递给一个复杂的函数,但我事先不知道这些值中的哪一个将导致被零除.我在Google上可以找到的所有内容都告诉我不要尝试进行评估,以免除以零.没有帮助!我曾经因为那些无法评估我对这些数据进行下一步操作而无法轻松过滤的信息而得到"inf"(或"NaN",我不记得了).

In my actual script I'm passing two 23x23 grids of values to a complicated function and I don't know in advance which of these values will result in the divide by zero. Everything I can find on Google just tells me not to attempt an evaluation that will result in the divide by zero. Not helpful! I used to get 'inf' (or 'NaN' - I can't specifically remember) for those it could not evaluate that I could easily filter for when I do the next steps on this data.

有人知道如何迫使Matlab 2014a返回该行为而不是抛出错误吗?还是我注定要永远运行旧版本的Matlab或经历巨大的痛苦以至于改变我的方法来避免被零除?

Does anyone know how to force Matlab 2014a back to that behaviour rather than throwing the error? Or am I doomed to running an older version of Matlab forever or going through the significant pain of changing my approach to this to avoid the divide by zero?

推荐答案

您可以定义一个具有所需行为的除法,该除法函数返回inf以除以零:

You could define a division which has the behaviour you want, this division function returns inf for division by zero:

mydiv=@(x,y)x/(dirac(y)+y)+dirac(y)
f = mydiv(x,y)
results = double(subs(f, {'x','y'}, {1:10,-4:5}))

这篇关于当符号数学工具箱用于评估为NaN时,除以零错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆