Integrate a 2D griddedInterpolant wrt one variable

18 vues (au cours des 30 derniers jours)
Anna Thuenen
Anna Thuenen le 17 Juil 2019
Modifié(e) : Andrei Bobrov le 2 Août 2019
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 commentaires
Torsten
Torsten le 17 Juil 2019
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 le 2 Août 2019
Modifié(e) : Andrei Bobrov le 2 Août 2019
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
>>

Connectez-vous pour commenter.

Réponses (1)

Sai Bhargav Avula
Sai Bhargav Avula le 2 Août 2019
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).

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by