Path: news.mathworks.com!newsfeed-00.mathworks.com!news.mv.net!news.glorb.com!news2.glorb.com!postnews.google.com!h18g2000yqj.googlegroups.com!not-for-mail
From: kem <kemelmi@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: making an evaluation of a VERY long expression much faster
Date: Sun, 5 Jul 2009 00:11:02 -0700 (PDT)
Organization: http://groups.google.com
Lines: 89
Message-ID: <932c3692-54a8-453b-bcf5-e6e0f69ca69f@h18g2000yqj.googlegroups.com>
References: <64605448-23d8-4aab-946f-a66103ac62b6@n11g2000yqb.googlegroups.com> 
	<62dc30c3-e7a8-405e-9c9f-8101fd9a0a25@x5g2000yqk.googlegroups.com>
NNTP-Posting-Host: 132.77.4.43
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1246777862 10979 127.0.0.1 (5 Jul 2009 07:11:02 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 5 Jul 2009 07:11:02 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: h18g2000yqj.googlegroups.com; posting-host=132.77.4.43; 
	posting-account=UKxCVgoAAAABvWaCgw-9-SAknbQcOdS3
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; 
	Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 wisweb (NetCache NetApp/6.0.6)
Xref: news.mathworks.com comp.soft-sys.matlab:552849



Hi Arun and James,
Thanks for your response.

Here's the expression I am evaluating:

E=ux.*vy.^2.*c.*wx+2.*ux.*b.*wy.^2+ux.*c.*wx+2.*ux.*B.*wy+vy.^2.*c.*wx
+vx.^2.*a.*wy.^2+ux.^2.*b.*wy.^2+ux.^2.*g.*vy.^2+vy.*B.*wy+2.*vy.*c.*wx
+2.*ux.*vy.*B.*zy+2.*ux.*vy.*c.*wx+ux.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.*wy.*A.*zy-2.*vx.*wy.*a.*zx-2.*uy.*wx.*b.*wy-
uy.*vx.*c.*zx-uy.*vx.*B.*wy-vx.*vy.*c.*wy-
vx.*vy.*c.*zy-2.*uy.*vx.*g.*vy-uy.*vx.*B.*zy-2.*uy.*b.*wy.*zx-
uy.*vx.*c.*wx-2.*vx.*vy.*wy.*a.*zx-2.*vx.*vy.*a.*zx.*zy-2.*vx.*vy.*wx.*a.*wy-2.*uy.*vx.*g-2.*uy.*vy.*wx.*A.*zx-
uy.*vx.*vy.*c.*wx+uy.*vx.*wy.*A.*zx-uy.*vx.*vy.*c.*zx+uy.*vx.*A.*zx.*zy
+uy.*vx.*wx.*A.*wy
+uy.*vx.*wx.*A.*zy-2.*uy.*wx.*A.*zx-2.*vx.*vy.*wx.*a.*zy
+uy.*vx.^2.*c.*wy-2.*uy.*wx.*b.*zy+uy.*vx.^2.*c.*zy;


Each of the variables is a 200x200 matrix. and I am calculating these
before the evaluation of this expression, in each iteration of the
optimization. Essentially I'd like to minimize this expression.

I was thinking to write this line in mex, will it be evaluated faster?

any other ideas are more than welcome ..

Thanks for your help!




On Jul 4, 3:44 pm, arun <aragorn1...@gmail.com> wrote:
> On Jul 3, 2:10 pm, kem <keme...@gmail.com> wrote:
>
>
>
>
>
> > Hello,
> > How can an evaluation of a very very long expression can be made
> > faster.
> > My expression has terms with the operation .* between matrices and
> > then those terms  are summed together
> > for example:
>
> > A.*B + B.*C.^2.*D+ A.*C + .....
>
> > where A B C D .. are matrices
> > this can be a sum of  100 terms like these
>
> > will programming it in MEX help here?
>
> > Can something else be done?
>
> > I am using it inside an optimization so it is crucial that it will run
> > as fast as possible
>
> > Thanks!
>
> Hi Kem,
>
> I agree to James' view. Please post your code. It might be useful to
> suggest something then. Otherwise, its walking in the dark right now.
>
> best,
> arun.- Hide quoted text -
>
> - Show quoted text -