Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!r10g2000prf.googlegroups.com!not-for-mail
From: Nitin <nitin.k.gupta@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Function without loop
Date: Wed, 28 Jan 2009 03:13:38 -0800 (PST)
Organization: http://groups.google.com
Lines: 24
Message-ID: <36b4a49c-e1c0-4360-9da7-0b36938a70f8@r10g2000prf.googlegroups.com>
References: <3e334842-e716-484b-bba8-8aca2de0b028@a12g2000pro.googlegroups.com>
NNTP-Posting-Host: 61.17.14.126
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1233141218 18753 127.0.0.1 (28 Jan 2009 11:13:38 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 28 Jan 2009 11:13:38 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: r10g2000prf.googlegroups.com; posting-host=61.17.14.126; 
	posting-account=JbiQ1AoAAAAoZhJzK-cEkrHqQiZPIYPF
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; 
	rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:514447


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 = 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);

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)=(X(:,i)*X(:,i)')*[x(1),x(2),x(3)]'-Y(i)*X(:,i);


Nitin
--
nitin@idearesearch.in
www.idearesearch.in