在mupadmex上解决两个方程组的系统时,Matlab 2012b太慢了(语句)

时间:2014-10-28 16:59:33

标签: matlab symbolic-math mupad

我正试图在for循环中用Matlab求解一个两个非线性方程组的系统。我知道for循环可能导致程序运行缓慢,但现在需要大约一个小时才能解决一个实例。在调试代码时,我意识到这一行导致程序挂起:

[res,status] = mupadmex(statement);

如果我终止该程序,我会得到以下内容:

Operation terminated by user during mupadengine/evalin (line 97)
In mupadengine/feval (line 150)
            [S,err] = evalin(engine,stmt);
In solve (line 160)   sol = eng.feval('symobj::solvefull',eqns,vars);
In algorithm2 (line 139)
            answer = solve (f , g);

其中第97行引用相同的代码行。这是我的代码中我称之为solve函数的部分:

syms ro1 t_prime1
assume(t_prime1 > 0)
for i=1:1:length(n1ps)
    n1p = n1ps(1,i); 
    n2p = n2ps(1,i); 
    w1 = (ro1/theta_p)*(1-exp((-1)*theta_p*t_prime1)); 
    w2 = exp((-1)*theta_p*t_prime1);
    w3 = (ro1/theta_p)*(1-exp((-1)*theta_p*T1))-q(1,1);
    w4 = (1-exp((-1)*n1p*theta_p*T1))/(1-exp((-1)*theta_p*T1)); 
    w5 = exp((-1)*theta_p*(T1-t_prime1));
    Q1 = (w1 + w2*w3*w4)*w5 - q(1,1); 

    w6 = ((ro-ro1)/theta_p)*(1-exp((-1)*theta_p*(n1p*T1 + t_prime1 - n2p*T2))); 
    w7 = exp((-1)*theta_p*(n1p*T1 + t_prime1 - n2p*T2));
    w8 = ((ro-ro1)/theta_p)*(1-exp((-1)*theta_p*T2))-q(1,2);
    w9 = (1-exp((-1)*n2p*theta_p*T2))/(1-exp((-1)*theta_p*T2)); 
    w10 = exp((-1)*theta_p*(T2-(n1p*T1 + t_prime1 - n2p*T2)));
    Q2 = (w6 + w7*w8*w9)*w10 - q(1,2);

    Q1_prime = q(1,1)*((exp((tN1 - n1p - 1)*theta_p*T1)-1)/(1-exp((-1)*theta_p*T1))); 
    Q2_prime = q(1,2)*((exp((tN2 - n2p - 1)*theta_p*T2)-1)/(1-exp((-1)*theta_p*T2)));

    f=Q1_prime-Q1;
    g=Q2_prime-Q2;

    answer = solve (f , g);
end 

0 个答案:

没有答案