M BUZZ CRAZE NEWS
// news

Integration with discrete data - Matlab

By Sarah Rodriguez
$\begingroup$

I need to integrate function $\int_0^1 pur\mathrm{d}r$, where I only have discrete values for $p$,$u$ and $r$. So, if I multiply these values, would it be correct to integrate only that final value with some rule of numerical integration in Matlab, with boundaries 0 to 1?

I mean, how Matlab will know that I am integrating function where something inside function is dependent on $\mathrm{d}r$? It is necessary to know in symbolic integration.

Or do I need to integrate numerically only $\int_0^1r\mathrm{d}r$ and later myltiply everything with $pu$?

$\endgroup$

2 Answers

$\begingroup$

Assuming that $p$ and $u$ are evaluated at the same points as $r$, the MATLAB code to approximate this integral would be "trapz(r,p.*u.*r)". This integrates the vector of products of $p$, $u$, and $r$ against $r$. This assumes that $r$ actually ranges from 0 to 1, which it should if you are integrating with respect to $r$

$\endgroup$ $\begingroup$

If you're saying that $p$ and $u$ are scalar values and $r$ is a function when you numerically integrate just take the $p \cdot u$ outside

$$ p \cdot u \int_{0}^{1} r dr \tag{1}$$

there is a series of rules for integration, called the newton cotes rules

$$ \int_{a}^{b} f(x) dx \approx \sum_{i=0}^{n} w_{i} f(x_{i}) \tag{2} $$

there is a function called integral in matlab, you'd define the function and the bounds.

To do this you'd have your vectors

x = linspace(0,1,1000)
r =@(x) p*u *x 

then integrate it

q = integral(r,0 1) 

something like that..but you have actual data..

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy