0

我正在尝试在 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 行指的是同一行代码。这是我调用求解函数的代码部分:

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 
4

0 回答 0