I have two functions f(x) and g(x), and I need to find a numerical approximation to the area bounded by the two curves.
How do I do this using the trapz and linspace functions?
Thanks
I have two functions f(x) and g(x), and I need to find a numerical approximation to the area bounded by the two curves.
How do I do this using the trapz and linspace functions?
Thanks
Suppose I want to integrate over $[0 ,2\pi]$, and divide that into $1000$ subintervals.
To do this, first create a vector for the interval:
Then create a vector containing the function values you want to integrate. If $f(x) = \sin(x)$ and $g(x) = x^2$ then the area between them is equal to the integral of their difference, and I would use
finally, integrate
Or, if you want it to display the answer, you can omit the semi-colon. e.g.
or if you don't even care about storing the value (only displaying it)