Matlab numerical integration

拜拜、爱过 提交于 2019-12-12 03:04:22

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/16656953/matlab-numerical-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!