How to get defined integral?
이전 댓글 표시
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
답변 (2개)
Andrei Bobrov
2012년 10월 15일
편집: Andrei Bobrov
2012년 10월 15일
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
2012년 10월 15일
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.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!