Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Is it possible to convert this for loop into a matrix?
Date: Wed, 29 Dec 2010 20:17:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <ifg50g$2v5$1@fred.mathworks.com>
References: <ifavqc$jha$1@fred.mathworks.com> <wG7So.18696$My1.7287@newsfe16.iad> <ifb25d$ihh$1@fred.mathworks.com> <M%8So.22950$DO.13893@newsfe09.iad> <ifb7c8$kbe$1@fred.mathworks.com> <SG9So.3684$jj5.3468@newsfe03.iad> <ifducl$du0$1@fred.mathworks.com> <iff1n9$ogf$1@fred.mathworks.com> <u_DSo.8614$111.6134@newsfe12.iad>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1293653840 3045 172.30.248.35 (29 Dec 2010 20:17:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 29 Dec 2010 20:17:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2141479
Xref: news.mathworks.com comp.soft-sys.matlab:699061

How should I implement this? I have tried:

>> arrayfun(fminbnd(@(H) -1*phi_small(x1,y1,H),0,1e-8,optimset('TolX',1e-10)),x1,y1)
??? Undefined function or variable 'x1'.
Error in ==> @(H)-1*phi_small(x1,y1,H)
Error in ==> fminbnd at 212
x= xf; fx = funfcn(x,varargin{:});

>> arrayfun(@(x1,y1) fminbnd(@(H) -1*phi_small(x1,y1,H),0,1e-8,optimset('TolX',1e-10)),x1,y1)
??? Undefined function or variable 'x1'.

Thanks a bunch,

Walter Roberson <roberson@hushmail.com> wrote in message <u_DSo.8614$111.6134@newsfe12.iad>...
> On 29/12/10 4:15 AM, Haoyang Liu wrote:
> > I tried this without success:
> >
> > N=150;
> > a=rand(N,1).*1e-7;
> > f = @(x,y) bsxfun(@(x1,y1) (x1+y1)./(1./x1 +
> > 1./y1)./phi_small(x1,y1,fminbnd(@(H)
> > -1*phi_small(x1,y1,H),0,1e-8,optimset('TolX',1e-10))), x, y.');
> > c=f(a,a);
> >
> > The error message was:
> >
> > "??? Operands to the || and && operators must be convertible to logical
> > scalar values.
> >
> > Error in ==> fminbnd at 310
> > if ( (fu <= fw) || (w == xf) )"
> >
> > if I only use the first part of f, (i.e. f = @(x,y) bsxfun(@(x1,y1)
> > (x1+y1)./(1./x1 + 1./y1), x, y.');), it run without problem, and the
> > second part (i.e. phi_small(x1,y1,fminbnd(@(H)
> > -1*phi_small(x1,y1,H),0,1e-8,optimset('TolX',1e-10))) run fine
> > standalone too.
> >
> > Any idea?
> 
> Yup. Look at the documentation for bsxfun:
> 
> "If an M-file function is specified, it must be able to accept either 
> two column vectors of the same size, or one column vector and one 
> scalar, and return as output a column vector of the size as the input 
> values."
> 
> fminbnd() is not able to process column vectors. You will have to wrap 
> the call to it with arrayfun() over x1