Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Creation of a list of functions, multiplying functions and integrating them
Replies: 3   Last Post: Apr 25, 2013 10:48 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,029 Registered: 12/7/04
Re: Creation of a list of functions, multiplying functions and integrating them
Posted: Apr 25, 2013 9:41 AM

"Tot " <najib_cool19@hotmail.com> wrote in message
news:klb6gs\$fr5\$1@newscl01ah.mathworks.com...
> Ok It's me again.
>
> I managed to multiply and integrate function handles as I wanted to.
>
> Now can anyone help me to create a list (or array) of function handle A,
> so that i can write something like:
>
> for i=1:n
> A(i)=@(x) blablabla(x)
> end
>
> Does anybody have an idea?

MATLAB no longer allow creation of arrays of function handles. You will need
to create a cell array.

S = {@sin, @(x) x.^2, @exp};
f = @(x) S{1}(x).*S{2}(x)-S{3}(x);
result1 = f(0.2)

% Alternately to get a cell array of values of the functions in S
g = @(x) cellfun(@(myfun) myfun(x), S, 'UniformOutput', false);
h = g(0:0.1:1)
h{1} % sin(0:0.1:1)
result2 = h{1}(3)*h{2}(3)-h{3}(3)

--
Steve Lord
slord@mathworks.com