Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Function without loop
Date: Wed, 28 Jan 2009 09:22:01 +0000 (UTC)
Organization: Erasmus MC
Lines: 22
Message-ID: <glp83p$p5b$1@fred.mathworks.com>
References: <3e334842-e716-484b-bba8-8aca2de0b028@a12g2000pro.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233134521 25771 172.30.248.37 (28 Jan 2009 09:22:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 28 Jan 2009 09:22:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:514425


fas <faisalmufti@gmail.com> wrote in message <3e334842-e716-484b-bba8-8aca2de0b028@a12g2000pro.googlegroups.com>...
> 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);

All this doesn't make any sense. 
If Y is really a scalar the loop will error for i=2, when refering to Y(2) ?
What do you mean "In each loop it takes X(3,1) ..." ?
f is continuously overwritten, so "f = X(:,1000) * X(:,1000)' * ..." would do as well.
What is x?

So, please restate your problem and code.

Jos