Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Speeding up Matlab
Date: Thu, 22 Oct 2009 14:35:14 +0000 (UTC)
Organization: ENSIACET INPT
Lines: 56
Message-ID: <hbpqj2$iad$1@fred.mathworks.com>
References: <hbpoj0$5ld$1@fred.mathworks.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 1256222114 18765 172.30.248.37 (22 Oct 2009 14:35:14 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 22 Oct 2009 14:35:14 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 481279
Xref: news.mathworks.com comp.soft-sys.matlab:579337


"Hugh " <h_a_patience@hotmail.com> wrote in message <hbpoj0$5ld$1@fred.mathworks.com>...
> Hi there,
> 
> I have the following code which seeks to find the optimal solution to a rpoblem. Using a linear search over a hyperbox. The problem is I need a reasonably good granularity 1000+ on each parameter but becasue the scale of the problem rises exponentially with the granularity used this soon makes the problem prohibitively expensive in terms of computational time. Is there an in built matlab function I an use which will speed this process up?
> 
> function [Result] =PrimePermOp(tau,Y)
> tic;
> tau=tau.';
> Y=Y.';
> 
> nObs=length(Y);
> 
> z=1;
> 
> for(j=1:10)
> 
> L5=j/200+0.01;
> 
> for(k=1:10)
> 
> L4=k/200+0.01;
> 
> for(l=1:10)
> 
> L3=l/200+0.01;
> 
> for(m=1:10)
> 
> L2=m/200+0.01;
> 
> for(n=1:10)
> 
> L1=n/200+0.01;
> 
> G= [ones(nObs,1) L1*(1-exp(-tau./L1))./(tau) (1-exp(-((tau-L2).^2)/L3))./(((tau-L2).^2)/L3) (1-exp(-((tau-L4).^2)/L5))./(((tau-L4).^2)/L5) ];
> %c0(1)+c0(2)*c0(5)*(1-exp(-xdata./c0(5)))./(xdata) + c0(3)*(1-exp(-((xdata-c0(6)).^2)/c0(7)))./(((xdata-c0(6)).^2)/c0(7))+ c0(4)*(1-exp(-((xdata-c0(8)).^2)/c0(9)))./(((xdata-c0(8)).^2)/c0(9));
> 
> alpha =G\Y;
> u=Y-G*alpha;
> stderr=sqrt(diag((u'*u)/(length(Y)-4)*pinv(G'*G)));
> Sum_u2 = sum(u.^2);
> error2=(Y-G*alpha).^2;
> error2 = sum(error2);
> Res(z,:) = [Sum_u2 alpha' L1 L2 L3 L4 L5 error2];
> z=z+1;
> end
> end
> end
> end
> end
> 
> optim=find(Res(:,11)==min(Res(:,11)));
> %Result=Res(optim,2:end)
> Result=toc;

I don't know if there is a built in function doing the same computation, however I would advise to write your own C/C++ routine and interface this routine with Matlab. You could also use Matlab profiler to find what is the most computationally expensive part of your program and implement in C only that part.