“无法从字面上证明'expr` ..."尝试在函数内比较符号时出错 [英] "Unable to prove `expr` literally..." error when trying to compare a symbol inside a function
问题描述
我刚刚开始学习MATLAB,我正试图规范由
给出的bump
函数.
I just started learning MATLAB and I'm trying to normalize a bump
function given by
function b = bump(x)
region1 = abs(x) < 1
b(region1) = (exp(-1./(1 - x(region1).^2)))
region2 = abs(x) >= 1
b(region2) = 0
end
为此,我需要将定积分从-1除以1.但是,当我输入
To do this, I need to divide by the definite integral from -1 to 1. However, when I input
syms x;
int(bump(x), -1, 1)
我收到一则很长的错误消息,内容为
I get a long error message, which says
使用symengine时出错(第58行)
无法证明'abs(x)<从字面上看是1'.要以数学方式测试该语句,请使用isAlways.
Error using symengine (line 58)
Unable to prove 'abs(x) < 1' literally. To test the statement mathematically, use isAlways.
sym/subsindex错误(第1554行)
X = find(mupadmex('symobj :: logical',A.s,9))-1;
Error in sym/subsindex (line 1554)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;
sym> privformat中的错误(第2357行)
x = subsindex(x)+1;
Error in sym>privformat (line 2357)
x = subsindex(x)+1;
sym/subsref错误(第1578行)
[inds {k},refs {k}] = privformat(inds {k});
Error in sym/subsref (line 1578)
[inds{k},refs{k}] = privformat(inds{k});
凹凸错误(第3行)
b(region1)=(exp(-1 ./(1-x(region1).^ 2)))
Error in bump (line 3)
b(region1) = (exp(-1./(1 - x(region1).^2)))
我尝试用我认为的isAlways(abs(x)<1)
替换abs(x)<1
,尽管它给出了错误的答案(它说积分为零),但是可以消除错误.
I tried replacing abs(x)<1
with what I think is the suggested isAlways(abs(x)<1)
, and that removes the error, although it gives the wrong answer (it says the integral is zero).
我不明白错误消息的含义.
I don't understand what does the error message means.
推荐答案
syms x
将x
定义为符号变量,并在x
上调用符号计算.这可能不是您想要的.
syms x
defines x
as a symbolic variable, invoking symbolic computation on x
. This probably isn't what you want.
相反,将x
定义为某种输入矩阵,例如x = zeros(3);
.或者,要进行数值积分,请使用 integral
函数:
Instead, define x
as some kind of input matrix, e.g. x = zeros(3);
. Or, to do numeric integration, use the integral
function:
integral(@bump, -1, 1)
这篇关于“无法从字面上证明'expr` ..."尝试在函数内比较符号时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!