Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!postnews.google.com!a12g2000pro.googlegroups.com!not-for-mail
From: fas <faisalmufti@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Function without loop
Date: Tue, 27 Jan 2009 22:42:12 -0800 (PST)
Organization: http://groups.google.com
Lines: 11
Message-ID: <3e334842-e716-484b-bba8-8aca2de0b028@a12g2000pro.googlegroups.com>
NNTP-Posting-Host: 150.203.45.195
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1233124933 25476 127.0.0.1 (28 Jan 2009 06:42:13 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 28 Jan 2009 06:42:13 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: a12g2000pro.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:514413


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 = objfun(x,X,Y)

for i=1:1000
    f=(X(:,i)*X(:,i)')*[x(1),x(2),x(3)]'-Y(i)*X(:,i);
end
f=norm(f);