Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!news.glorb.com!news.aset.psu.edu!news.cse.psu.edu!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: operation with a vector of n elements
Date: Wed, 6 Feb 2008 17:58:45 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 21
Message-ID: <focsgl$8vb$1@canopus.cc.umanitoba.ca>
References: <focquj$ked$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1202320725 9195 192.70.172.160 (6 Feb 2008 17:58:45 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Wed, 6 Feb 2008 17:58:45 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:449686


In article <focquj$ked$1@fred.mathworks.com>,
Marcelo Tames <jmarcelo.tb@mathworks.com> wrote:
>Hello, I just started studying matlab so my knowledge is 
>little. I have this problem: Given a vector x with n 
>elements, write a MATLAB function
>with x as input parameter to form the vector p with elements
>pk = x1*x2...xk1*xk+1...xn;

>that is, pk will contain the products of all the vector 
>elements except the kth. Then vector P = [p1 p2 ... pn]

P = prod(x) ./ x;

Note: this has a subtle bug in it. You will need to test it
to figure out the circumstances under which it can go wrong,
and you will have to make adjustments so that it gives the
right answer under those circumstances.

-- 
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec