I want Absolute numerical integral-sth like absolute trapz
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to calculate integral of this function with trapz .
x=-1.5*pi:pi/100:pi;
y=sin(x);
z=trapz(x,y);
It gives me this : z=0.999;
Now I want the whole surface confined by the function to be calculated. so the number must be z=3.
whole surface=[positive surfaces+abs(negative surfaces)].
Is there any function for numerical Integration for this process.
I have to add that I can not use explicit integral function because the only thing I have is just some X & Y .In other words assume that we don't know y's function.
Thanks in advance.
2 个评论
Daniel Shub
2011-8-10
I don't understand the question. How is what you want not trapz(x, abs(y))? I don't understand how what you want can lead to z=3.
回答(2 个)
Friedrich
2011-8-10
Hi,
as long as Y is positive trapez(X,Y) will work. You don't have to worry about negative X values, e.g.
>> X = -0.5:0.1:0;
>> Y = ones(size(X));
>> trapz(X,Y)
(This would be a simple recatangle). You only have to take care of negative Y values, which you don't have.
0 个评论
Fangjun Jiang
2011-8-10
Your y HAS negative values. plot(x,y) to take a look.
This is a simple task. There is a theoretical solution of the integration of sin(x). Do that calculation and compare that with your numerical result.
Depending on your need, you may need to do z=trapz(x,y) or z=trapz(x,abs(y))
Although your y is generated using sin(x), when you use trapz(x,y), MATLAB doesn't know the functional relationship between x and y. So don't worry about that. Calm down, do your paper work and you will confirm that trapz() is doing what it suppose to do. Then you can move on with your real task.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!