# Matlab integration trouble

1. Feb 28, 2013

### MotoPayton

syms y
int(2*y*(sqrt(1-(y-1)^2)),y,0,2)

I plug this into matlab and I get the answer is negative pi. The entire integration region is positive. How is this possible!! what the heck is going on????????????????????????????????

Just noticed that if I set the limits to 0.00001 and 1.99999
it works perfect. Can someone explain this

Last edited: Feb 28, 2013
2. Mar 1, 2013

### kreil

I couldn't reproduce this. I got pi as the answer below with two different methods (the first is yours):

via symbolic:
Code (Text):
syms y
int(2*y*(sqrt(1-(y-1)^2)),y,0,2)

ans =

pi

via function handle:
Code (Text):
fcn = @(y) 2.*y.*(sqrt(1-(y-1).^2))
integral(fcn,0,2)

ans =

3.141592653589793

3. Mar 1, 2013

### MotoPayton

What version are you using?

4. Mar 1, 2013

### kreil

I work at MathWorks, so I was using 13a (due out in a month or two).

If you got this answer using 12b, it may have been a bug that got fixed in 13a. Let me know what version you're using and I can check.

5. Mar 8, 2013

6. Mar 8, 2013

### kreil

Haha okok so I didn't look up exactly when it went live..

7. Mar 10, 2013

### timsea81

I'm trying to replicate this to modify the problem and numerically calculate an integral, but I get the error:
"Attempt to execute SCRIPT integral as a function"

Any ideas what that means?

8. Mar 10, 2013

### AIR&SPACE

At some point you've written a script, and called it: integral. It's probably in your root Matlab directory, or in your active directory. Matlab has a built-in function called integral, which is what the code is meant to execute. However, your version is "covering" it up. A script can't be run as a function, however, hence the error.

9. Mar 10, 2013

### timsea81

Thanks! That's exactly it. I just created a file to experiment with integrals and called it "integral.m". I never would have thought of that. I was reading the error message as if there were separate "script integrals" and "function integrals" or something. Thanks a lot!