“无法从字面上证明'expr` ..."尝试在函数内比较符号时出错

编程入门 行业动态 更新时间:2024-10-28 01:25:57
本文介绍了“无法从字面上证明'expr` ..."尝试在函数内比较符号时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚开始学习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` ..."尝试在函数内比较符号时出错

本文发布于:2023-11-23 11:04:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字面   函数   符号   expr   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!