How to get defined integral?
Show older comments
Hi, I have a small project due in a couple of hours. Currently I'm using the following code:
x = linspace(-3,6,1000); % Define x-interval as -3 to 6 with 1000 points defined in vector
y = x.^3 - 5*x.^2 - 4*x + 20; % Define y as equation
plot(x,y)
Now I have to find the defined integral over the interval -2,5. A minute ago I put the following into the command window:
int(x.^3 - 5*x.^2 - 4*x + 20,-2,5)
and got the right answer. But now suddenly it doesn't work. I get the error:
Undefined function 'int' for input arguments of type 'double'.
What's the problem here? Also, once it works, how do I get an output when written in the editor and run (will it show a window like the axes plotted or do I have to tell it to show the output somewhere?)
Thanks
Answers (2)
Andrei Bobrov
on 15 Oct 2012
Edited: Andrei Bobrov
on 15 Oct 2012
x = linspace(-3,6,1000);
y = x.^3 - 5*x.^2 - 4*x + 20;
out = quad(@(x)x.^3 - 5*x.^2 - 4*x + 20,-2,5);
or
out2 = diff(polyval(polyint([1 -5 -4 20]),[-2,5]));
or your case
syms x
out3 = int(x.^3 - 5*x.^2 - 4*x + 20,-2,5)
or if you use MATLAB R2012a or R2012b
out4 = integral(@(x)x.^3 - 5*x.^2 - 4*x + 20,-2,5);
Walter Roberson
on 15 Oct 2012
The "int" call would have worked if you had used
syms x
before you made the int() call, and you had not assigned any numeric value to x between the "syms" command and the int() call.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!