# Question about integration within matlab

2 visualizzazioni (ultimi 30 giorni)
Ano il 18 Set 2017
Modificato: Cam Salzberger il 18 Set 2017
I would like to know how far would be my code correct if I used the 'sum' function to compute a double integral or should I use the Gaussian quadrature formulas ??! Thank you !
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Cam Salzberger il 18 Set 2017
Modificato: Cam Salzberger il 18 Set 2017
Hello Ano,
If you were to do this:
x = 0:1:10;
y = sin(x);
intsinxdx = sum(y);
Then this would be a valid approximation of the integral. Technically, it would be the left Riemann sum integrating from 0 to 11, with step-size 1. This is really the key part, because if you were to try this:
x = 0:0.1:10;
y = sin(x);
intsinxdx = sum(y);
then this would not be accurate. That is because to approximate the integral, you have to multiply the height by the width of the given rectangle. It only worked in the previous case because the width of the rectangles were 1.
However, if you simply use the integral function, that uses an adaptive quadrature approximation. So that may be your best-bet for a quick implementation of an approximate integral.
-Cam
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by