How to accelerate matrix calculation with matlab?

I have 40800 linear sparse equations that have the following forms:
F(1)=2*x(1)+x(2)-10;
F(2)=x(9)+3*x(10)-7;......
F(40800)=x(40200)-x(1)+....-10;
I want to convert these equations to matrices by evaluating them at the columns of speye(N);
N=40200; %the number of variables
E=speye(N,N+1);
columns=cell(1,N);
beq=-evaluate_equations(E(:,N+1));
for i=1:N
columns{i}=evaluate_equations(E(:,i))+ beq;
end
Aeq=cell2mat(columns);
full(Aeq),
full(beq),
function F=evaluate_equations(x)
F(1)=2*x(1)+x(2)-10;
F(2)=x(9)+3*x(10)-7;......
F(40800)=x(40200)-x(1)+....-10;
F=F(:); %column vector
But Matlab is very slow. It can not build the matrices. However i use 8 workers to accelerate the computing. Have you an idea to overcome this problem? Thanks.

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 7일

0 개 추천

If they are sparse linear equations, could you not code them as a matrix multiplication in the first place? If you did that you could also skip the "for i" loop and do it as a single matrix multiplication.

댓글 수: 4

I don't understand what do you mean by single matrix multiplication? Can you explain more please?
A = [2 1 0 0 0 0 0 0 0 0 -10; %predetermined
0 0 0 0 0 0 0 0 1 3 -7]
x = [E(1:size(A,2)-1, :); ones(1, size(E,2))]; %column-oriented!
A * x
This is for general E. Considering that your particular E is spyeye(), the answer probably just comes out as A.
Thus, you would code them in matrix form instead of in equation form.
Are you generating the equations somehow, perhaps using the symbolic toolbox? If so then the symbolic toolbox can be used to convert into matrix form.
imed NASRI
imed NASRI 2014년 1월 8일
편집: imed NASRI 2014년 1월 8일
I generate my equations using a matlab code. Equations are generated in a text file using fprintf. Then i copy them into an other m file to generate the desired matrices Aeq and beq into an other text file(the code that I have posted above)
imed NASRI
imed NASRI 2014년 1월 8일
편집: imed NASRI 2014년 1월 8일
Aeq and beq are unknown. I have to generate them from equations:
F(1)=2*x(1)+x(2)-10;
F(2)=x(9)+3*x(10)-7;......
F(40800)=x(40200)-x(1)+....-10;
such that we have the following matrix form:
Aeq*x=beq
So, I would like to get my generated matrice Aeq and beq and save them to a text file because i will call them after in the ga() solver

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기

질문:

2014년 1월 7일

편집:

2014년 1월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by