问题描述
我正在尝试使用Matlab集成x,通过使用以下命令,该任务很简单:
I'm trying to integrate x using matlab, and that task is simple by using the following commands:
syms x
a=int(x)
问题是我不确定如何实现数值积分.我想使用不同的技术使用一定数量的间隔对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.
有人可以帮助我进行数字积分的语法调用吗? MathWorks网站不是很有帮助.
Can anyone help me with the syntax call for numerical integration? The MathWorks site isn't very helpful.
我也确实知道有一种叫做陷阱的方法,但是我正在matlab中寻找其他方法,例如黎曼和近似.
I also do know there is a method called traps, but I'm looking for other methods within matlab, like Riemann sum approximation.
更新
因此,我要寻找的具体功能是将x分成8个区域,然后将这8个区域相加.除了trapz之外,还有其他预定义功能可以做到这一点吗?
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
用于一维集成.
相反,如果您对多维集成技术感兴趣,则可以考虑使用以下功能
If, instead, you are interested in multi-dimensional integration techniques, you may think of making use of the following functions
dblquad
quad2d
integral2
integral3
编辑
在您的情况下,我将按照这种方式进行操作:
In your case, I would proceed this way:
x = 0:.1:2;
y = x;
trapz(x,y);
或
y = @(x) x;
quad(y,0,2);
编辑2
看一下:
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)
这篇关于Matlab数值积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!