For Programmers: Free Programming Magazines  


Home > Archive > Matlab > November 2005 > product of function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author product of function
Dupire

2005-11-29, 8:00 am

What do i do to make f time g where f and g are inline function?
Thank for your answer.
Steven Lord

2005-11-29, 8:00 am


"Dupire" <gdupire@hds.utc.fr> wrote in message
news:ef1cf4c.-1@webx.raydaftYaTP...
> What do i do to make f time g where f and g are inline function?
> Thank for your answer.


If you want a single inline function you evaluate to obtain the product,
it's kind of messy.


f = inline('sin(x)', 'x');
g = inline('cos(x)', 'x');
h = inline('feval(f, x).*feval(g, x)', 'x', 'f', 'g');
t1 = feval(h, 1:10, f, g)


Of course, if you need to evaluate the product once you could write:


f = inline('sin(x)', 'x');
g = inline('cos(x)', 'x');
t2 = feval(f, 1:10) .* feval(g, 1:10)


If you're using MATLAB 7.0 or later, use anonymous functions instead.


f = @(x) sin(x);
g = @(x) cos(x);
h = @(x) f(x).*g(x);
t3 = h(1:10)


--
Steve Lord
slord@mathworks.com


Zahidullah

2005-11-29, 8:00 am

Dupire wrote:
>
> sdfsdfsdfsdf
> What do i do to make f time g where f and g are inline function?
> Thank for your answer.

us

2005-11-29, 8:00 am

Steven Lord:
<SNIP drill down to overhead...

> f = @(x) sin(x);
> g = @(x) cos(x);
> h = @(x) f(x).*g(x);
> t3 = h(1:10)


.... could read

f=@sin;
g=@cos;
h=@(x) f(x).*g(x);
h(1:10)

just a thought
us
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com