質問

I'm trying to integrate x using matlab, and that task is simple by using the following commands:

syms x

a=int(x)

The problem is I'm not sure how to implement numerical integration. I want to integrate x using a set amount of intervals using different techniques.

Can anyone help me with the syntax call for numerical integration? The MathWorks site isn't very helpful.

I also do know there is a method called traps, but I'm looking for other methods within matlab, like Riemann sum approximation.

Update

So specifically what I'm looking for is a function that will break x into 8 pieces of area and then add those 8 pieces together. Is there a predefined function other than trapz that does such a thing?

Okay, I think I've come to the conclusion that there is no such thing. You have to make your own.

役に立ちましたか?

解決

For numerical integration you have a broad number of functions at your disposal:

trapz
quad
quadgk
integral

for uni-dimensional integration.

If, instead, you are interested in multi-dimensional integration techniques, you may think of making use of the following functions

dblquad
quad2d
integral2
integral3

EDIT

In your case, I would proceed this way:

x = 0:.1:2;
y = x;
trapz(x,y);

or

y = @(x) x;
quad(y,0,2);

EDIT 2

Give this a look:

clc,clear

s = 0:7;
y = @(x) x;

k = 1;
for ii = 1:numel(s)-1
  f(k) = quad(y,s(k), s(k+1));
  k = k + 1;
end
sum(f)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top