Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Integrating function of a function
Date: Fri, 20 Jun 2008 10:14:44 -0400
Organization: The MathWorks
Lines: 38
Message-ID: <MPG.22c58562d71814bf989874@news.mathworks.com>
References: <39e38ef4-9894-45c8-9b17-e264ccf03233@m44g2000hsc.googlegroups.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1213971284 20191 172.31.57.117 (20 Jun 2008 14:14:44 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 20 Jun 2008 14:14:44 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:474974



In article <39e38ef4-9894-45c8-9b17-e264ccf03233
@m44g2000hsc.googlegroups.com>, robert.ian.taylor@gmail.com says...
> I have a function (let us call it shape), and one example I could use
> for this is:
> 
> shape = hmin + x*x/(2*R)
> 
> so there are three input arguments: x, hmin, R
> 
> I want to integrate 1/(shape*shape) and 1/(shape*shape*shape).
> I'm having trouble with the syntax needed to do this with quad.
> 
> I know that if I simply wanted to integrate shape, I would use
> quad(@(x)shape(x,hmin,R),a,b)
> 
> Is it best to define two functions, one being 1/(shape*shape) and the
> other being 1/(shape*shape*shape), or can I call quad directly in some
> way ?
> 
> Thanks
> 

Why not just make an anonymous function for the integrand, either 
straight from your formula, or using the function shape?

quad(@(x) 1. / (hmin + x.^2 / (2*R)).^2, a,b)  AND
quad(@(x) 1. / (hmin + x.^2 / (2*R)).^3, a,b)

OR

quad(@(x) 1. / shape(x,hmin,R).^2, a,b) AND
quad(@(x) 1. / shape(x,hmin,R).^3, a,b) 

I didn't try these so they might not be correct, but the idea is there.

-- 
Loren
http://blogs.mathworks.com/loren/