Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!postnews.google.com!o40g2000prn.googlegroups.com!not-for-mail
From: fas <faisalmufti@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Function without loop
Date: Wed, 28 Jan 2009 16:47:15 -0800 (PST)
Organization: http://groups.google.com
Lines: 29
Message-ID: <d9333ce0-d611-4d7d-84b1-a12452141f51@o40g2000prn.googlegroups.com>
References: <3e334842-e716-484b-bba8-8aca2de0b028@a12g2000pro.googlegroups.com> 
	<36b4a49c-e1c0-4360-9da7-0b36938a70f8@r10g2000prf.googlegroups.com>
NNTP-Posting-Host: 150.203.45.195
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1233190035 13937 127.0.0.1 (29 Jan 2009 00:47:15 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 29 Jan 2009 00:47:15 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: o40g2000prn.googlegroups.com; posting-host=150.203.45.195; 
	posting-account=GPH0AgoAAAAxfbd_rNaAdoRNt4LD8YmY
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.0.5) 
	Gecko/2008120122 Firefox/3.0.5,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:514610


On Jan 28, 10:13=A0pm, Nitin <nitin.k.gu...@gmail.com> wrote:
> On Jan 28, 11:42 am, fas <faisalmu...@gmail.com> wrote:
>
> > I have written my objective function. However I have to run a loop. I
> > am wondering if I can write it without a loop. Here X is a 3x1000
> > matrix and Y is a scalar. In each loop it takes X(3,1) and create one
> > equation.
>
> > function f =3D objfun(x,X,Y)
>
> > for i=3D1:1000
> > =A0 =A0 f=3D(X(:,i)*X(:,i)')*[x(1),x(2),x(3)]'-Y(i)*X(:,i);
> > end
> > f=3Dnorm(f);
>
> did you mean that Y is a "vector"? and, it takes "x(3,1)" in each
> loop?
>
> shouldn't your equation look like:
> f(i)=3D(X(:,i)*X(:,i)')*[x(1),x(2),x(3)]'-Y(i)*X(:,i);
>
> Nitin
> --
> ni...@idearesearch.inwww.idearesearch.in

Sorry I made a mistake it should have been like that
f(:,i)=3D(X(:,i)*X(:,i)')*[x(1),x(2),x(3)]'-Y(i)*X(:,i);

and Y is a 1000x1 vector