|
On 20 Jun, 15:14, Loren Shure <lo...@mathworks.com> wrote:
> In article <39e38ef4-9894-45c8-9b17-e264ccf03233
> @m44g2000hsc.googlegroups.com>, robert.ian.tay...@gmail.com says...
>
>
>
>
>
> > I have a function (let us call it shape), and one example I could use
> > for this is:
>
> > shape =3D 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) =A0AND
> 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.
>
> --
> Lorenhttp://blogs.mathworks.com/loren/- Hide quoted text -
>
> - Show quoted text -
Thanks for the help. I will try it out. The second suggestion looks
more useful, because at a later date I may want to change the shape
function.
All the best
Ian Taylor
http://www.iantaylor.org.uk/
|