0

I'm trying to solve a symbolic system of equations for many variables. The structure of the equations will change based on the entries of AM, so solving these equations casually won't work well. This code does what I expect it to, however I need to solve for approximately 20,000 cases, so it is too slow. Is there any way to speed it up (possibly using vectorization?).

syms FD ICE EM GEN

AM = [0 1 1 0 ;
     0 1 0 0 ;
     0 0 1 0;
    0 0 0 1];

Tvec = [FD;ICE;EM;GEN]

eqs=  AM * Tvec  ==   Tvec

tic

%Start solving for different cases in loop.  This is really slow!
for j = 1:100

    FDv = j;
    ICEv = j^2;

    ans = solve(eqs, FD == FDv, ICE == ICEv);

    FD_ans(j)=double(ans.FD);
    ICE_ans(j)=double(ans.ICE);
    EM_ans(j)=double(ans.EM);
end
toc

Edit: For clarification, in the future I plan to have the entries of AM as parameters. These entries will vary, but will only have 1 or 0 values.

4

2 に答える 2

0

コードを採用して、MATLAB parforで使用することができます。

于 2013-11-14T23:15:26.827 に答える