Do you know how to solve an integral over a loop?

Hi, I have a integral that I need to solve, the problem is that I have a loop, that is, for each value of r, Ihave one U, my inputs are:
r=[0 2.19 4.53 6.87 9.21 11.55 13.89 16.23 18.57 20.95 23.29 25.63 27.97 30.31 32.66 35.0 37.34 39.68 42.023 44.36 46.70 49.04 51.38];
U=[0 0 0 0.588 1.685 2.03 2.307 2.544 2.598 2.733 2.565 2.663 2.437 2.425 2.263 2.507 2.525 2.537 2.416 2.268 1.979 1.708 0.614];
Function is: F=2/(r^2) ∫U r dr
The bounds of integral are between 0 to 51.38 . Any help would be appreciated.

1 Comment

It does not make sense to integrate with respect to r if you have one U value for each r value.
It does not make sense to integrate with respect to a discrete variable.

Sign in to comment.

 Accepted Answer

Ur=U.*r;
result=trapz(r,Ur);
gives you an approximation of
integral_{r=0}^{r=51.38} U*r dr.
Best wishes
Torsten.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!