Numerical Integration with variable limits MATLAB

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 2K views
member 428835
Hi PF!

Suppose I have two functions ##f(x),\,g(y)## that are numerically defined as vectors (i.e. ##g(y) = [0,1,4,9,16]:y = [0,1,2,3,4]## and say ##f(x) = [0,1,8,27,64]:x = [0,1,2,3,4]##) and am trying to compute $$\int_0^1 f(x) \int_x^1 g(y)\, dydx.$$

How would I do this in MATLAB? I could be in the wrong thread here, in which case I'm sorry!
 
Physics news on Phys.org
mathman said:
f and g are defined only for discrete points. Without further definition, there is nothing to integrate.
Let's say ##g(x) = x^3## and ##f(y) = y^2##. Now can you help?
 
Rereading my post, that came off a little rude. I'm not trying to be. Just wanting to make sure I have addressed the issue you pointed out. :)
 
To properly answer this question we need to know how familiar you are with numerical integration and how familiar you are with matlab.

Think about what numerical integration is... you are basically summing up the f(x) values as you sweep the x axis. If you have discrete points this becomes easy, as you are already ready. With some MATLAB knowledge this is fairly easy.
 
The function cumsum() may help you to do this, but only if the x value increases by the same amount every time
Alternatively you may need to write your own function, if you have varying x values.
 
donpacino said:
To properly answer this question we need to know how familiar you are with numerical integration and how familiar you are with matlab.
I'd say I'm pretty familiar with both, but I know some people on here are way more advanced than me, so I'm unsure. I think I'm going to write my own double sum from Stephan Tashi's post. Thanks for your input!