Path: news.mathworks.com!not-for-mail
From: "Bjorn Gustavsson" <bjonr@irf.se>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab Problem!!!
Date: Thu, 4 Dec 2008 08:12:06 +0000 (UTC)
Organization: Ttroms&#248; University
Lines: 33
Message-ID: <gh83cm$7vc$1@fred.mathworks.com>
References: <6200318.1228278241565.JavaMail.jakarta@nitrogen.mathforum.org> <23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org> <gh5h9n$m1o$1@fred.mathworks.com> <gh6619$npo$1@fred.mathworks.com>
Reply-To: "Bjorn Gustavsson" <bjonr@irf.se>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228378326 8172 172.30.248.38 (4 Dec 2008 08:12:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Dec 2008 08:12:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 19453
Xref: news.mathworks.com comp.soft-sys.matlab:504899


"Steven Lord" <slord@mathworks.com> wrote in message <gh6619$npo$1@fred.mathworks.com>...
> 
> "Bjorn Gustavsson" <bjonr@irf.se> wrote in message 
> news:gh5h9n$m1o$1@fred.mathworks.com...
> > Matt <mcushi2@gmail.com> wrote in message 
> > <23500797.1228280941124.JavaMail.jakarta@nitrogen.mathforum.org>...
> >> I've tried many things.  I already have it saved as newton.m file.  And 
> >> I'm trying multiple things in the M-File Configuration Box.  I've tried:
> >>
> >> x = 1;
> >> f = [@(x)x.^2, @(x)2*x];
> >> newton(f, 0.2);
> >>
> > In my current version of matlab (7.1) the above pattern doesn't work, 
> > since you'd get a call along this line somewhere:
> >
> > val  = f(1)(12)
> >
> > As far as I recall the recommendation with arrays of function handles are 
> > to use cell arrays:
> >
> > f = {@(x) (x.^2), @(x) (2*x)};
> 
> It depends on what the OP wants.  Rather than a cell array of function 
> handles, I suspect he may want a function handle that returns an array:
> 
> f = @(x) [x.^2; 2*x];
> 
> Then something like f(5) would work.
> 
Is there any neat way to make that vectorize well too - so that one get an N-by-2 array out if called with an N-by-1 and a 2-by-N when called with a 1-by-N?

Bjoern, trying to learn something - sometimes