Path: news.mathworks.com!not-for-mail
From: "Marcelo Tames" <jmarcelo.tb@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: operation with a vector of n elements
Date: Thu, 20 Mar 2008 06:29:02 +0000 (UTC)
Organization: M&#65533;lardalen University
Lines: 47
Message-ID: <frt07e$jqn$1@fred.mathworks.com>
References: <focquj$ked$1@fred.mathworks.com> <foct9h$njq$1@fred.mathworks.com> <fod80o$kni$1@fred.mathworks.com> <frsemt$cti$1@fred.mathworks.com>
Reply-To: "Marcelo Tames" <jmarcelo.tb@mathworks.com>
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 1205994542 20311 172.30.248.37 (20 Mar 2008 06:29:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Mar 2008 06:29:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1272310
Xref: news.mathworks.com comp.soft-sys.matlab:458210


"Harish Jain" <hp_jain@yahoo.com> wrote in message 
<frsemt$cti$1@fred.mathworks.com>...
> "Marcelo Tames" <jmarcelo.tb@mathworks.com> wrote in 
message
> <fod80o$kni$1@fred.mathworks.com>...
> > I think I get what you mean, and yes it?s a homework 
that 
> > kept me thinking the whole afternoon, thanks fort the 
ideas 
> My homework is one step beyond this point. 
> 
> I need some of the all the element except itself and do 
not
> use division (/) operator (That means only use *
> (Multiplication).
> 
> One step further from here is to create liner solution for
> minimum computations.
> 
> Let me know your thoughts.
> 
> -Harish Jain


well, I?ve finished with this one already, I did it using 
many conditionals and it worked perfectly, this one by the 
way solves the problem when there are one or more zero 
vector elements:

function [Pk] = vector_Pk (x)
if x==0          
    Pk = [];
    elseif length(x)== 
    Pk = 1;
        elseif sum((x==0))>1 %if 
        Pk = zeros(size(x));
              elseif sum((x==0))==0
              Pk = zeros(size(x));
              Pk(find(x))=prod(x(find(x)))./x;
                  else Pk = zeros(size(x));
                  Pk(find(x==0))=prod(x(find(x)));
end


I thought if you don?t have to use (/) then just change it 
to .*x^(-1), hope it helps.