Integrate a 2D griddedInterpolant wrt one variable

Hello,
I would like to know how to integrate a 2D griddedInterpolant with respect to one variable.
I include an example:
[x,y] = ndgrid(-5:0.8:5);
z = x.^2 + y.^2;
F = griddedInterpolant(x,y,z);
integral(@(x) F(x,1),0,1)
The actual interpolant is from data and not availbe in a closed analytical form.
This produces an error. Is there a simple alternative?

6 件のコメント

Torsten
Torsten 2019 年 7 月 17 日
編集済み: Torsten 2019 年 7 月 17 日
x = -5:0.8:5;
y = x';
z = x.^2 + y.^2;
F = griddedInterpolant({x,y},z);
integral(@(x)F(x,1),0,1,'ArrayValued',true)
Anna Thuenen
Anna Thuenen 2019 年 7 月 17 日
@Torsten
Indeed, this does not return an error message.
However, it returns:
1.6080
but it should return in this setting:
1.3333
Torsten
Torsten 2019 年 7 月 17 日
What happens if you choose a finer discretization in x-direction:
x = -5:0.01:5
e.g.
Anna Thuenen
Anna Thuenen 2019 年 7 月 17 日
As mentioned: This is an example. The actual goal is to integrate an interpolant of data.
Torsten
Torsten 2019 年 7 月 17 日
I know, but the quality of the result depends on the denseness of points (x,y) where you can supply z(x,y).
Andrei Bobrov
Andrei Bobrov 2019 年 8 月 2 日
編集済み: Andrei Bobrov 2019 年 8 月 2 日
Hi friends!
>> x = -5:0.8:5;
y = x';
z = x.^2 + y.^2;
F = griddedInterpolant({x,y},z,'spline');
integral(@(x)F(x,1),0,1,'ArrayValued',true)
ans =
1.3333
>>

サインインしてコメントする。

回答 (1 件)

Sai Bhargav Avula
Sai Bhargav Avula 2019 年 8 月 2 日

0 投票

The integral function in MATLAB does Numerical Integration and is the approximate computation of an integral using numerical techniques. As mentioned by the @Torsten the quality depends on the denseness of points (x,y).

カテゴリ

製品

質問済み:

2019 年 7 月 17 日

編集済み:

2019 年 8 月 2 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by