"Unable to prove `expr` literally..." error when trying to compare a symbol inside a function

StackOverflow https://stackoverflow.com/questions/18966576

  •  29-06-2022
  •  | 
  •  

Question

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

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

Error using symengine (line 58)
Unable to prove 'abs(x) < 1' literally. To test the statement mathematically, use isAlways.

Error in sym/subsindex (line 1554)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;

Error in sym>privformat (line 2357)
x = subsindex(x)+1;

Error in sym/subsref (line 1578)
[inds{k},refs{k}] = privformat(inds{k});

Error in bump (line 3)
b(region1) = (exp(-1./(1 - x(region1).^2)))

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.

Était-ce utile?

La solution

syms x defines x as a symbolic variable, invoking symbolic computation on x. This probably isn't what you want.

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)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top