Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Integrating function of a function
Date: Sat, 21 Jun 2008 11:34:02 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 29
Message-ID: <g3iova$all$1@fred.mathworks.com>
References: <39e38ef4-9894-45c8-9b17-e264ccf03233@m44g2000hsc.googlegroups.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1214048042 10933 172.30.248.37 (21 Jun 2008 11:34:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 21 Jun 2008 11:34:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:475154



Ian Taylor <robert.ian.taylor@gmail.com> wrote in message <39e38ef4-
9894-45c8-9b17-e264ccf03233@m44g2000hsc.googlegroups.com>...
> 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

shape = @(x,hmin,R) hmin + x.*x/(2*R);

quad(@(x) 1./shape(x).^n,,a,b)

Note the use of the dotted operators, .* ./ and .^
in these calls. This allows quad to run properly.

John