# Integral error: A and B must be floating point

I want to evaluate a simple example of an integral

``````a = max(solve(x^3 - 2*x^2 + x ==0 , x));
fun = @(x) exp(-x.^2).*log(x).^2;
q = integral(fun,0,a)
```

```

and error

``````Error using integral (line 85)
A and B must be floating-point scalars.
```

```

Any tips? The lower limit of my integral should be a function, not a number.

+3

source to share

Matlab command `solve`

returns symbolic result. `integral`

only accepts numeric input. Use `double`

to convert character to numeric. Since your code is written now, it `max`

should already be throwing an error due to symbolic input. The following works.

``````syms x;
a = max(double(solve(x^3 - 2*x^2 + x)));
fun = @(x) exp(-x.^2).*log(x).^2;
q = integral(fun,0,a)
```

```

Output: `1.9331`

.

the lower bound of my integral should be a function, not a number

`integral`

is a numerical integration program; integration limits must be numeric.

+2

source

Check the values ​​of a with the mouse at the breakpoint or delete point; from the end of the line so that it prints a . Based on the error, a is not a scalar float. Converting a vector to one value may require another max () or double () operator.

Integral Help: http://www.mathworks.com/help/ref/integral.html

0

source

All Articles