• Resolved pvtsolver

    (@pvtsolver)


    Hello,

    I am trying to create an advanced while-loop with multiple conditions.

    Here is my source code:

    (function(){
    var T_pr = 1.25;
    var P_pr = 0.8;
    var Z_Trial = 1;
    var dZ = 1;
    var Z_Calc = 1;
    var I = 0;
    while (AND (I < 10001 , OR (dZ > 0.00000000000001 , dZ < -0.00000000000001)));
    var Den_r = (0.27 * P_pr) / (Z_Trial * T_pr);
    var C1 = 1 + 2 / T_pr + 3 / POW(T_pr , 3) + 4 / POW(T_pr , 4) + 5 / POW(T_pr , 5);
        var C2 = 6 + 7 / T_pr + 8 / POW(T_pr , 2);
        var C3 = 9 * (7 / T_pr + 8 / POW(T_pr , 2));
        var C4 = A_10 * (1 + 11 * POW(Den_r , 2) / (T_pr , 3));
        var Z_Calc = 1 + C1 * Den_r + C2 * POW(Den_r , 2) - C3 * POW(Den_r , 5) + C4 * POW(Den_r , 2) * Exp(-1 * 11 * POW(Den_r , 2));
        var dZ = Z_Calc - Z_Trial;
        if (P_pr <= 2) { var Z_Trial =+ dZ; }
        if (AND (P_pr > 2, P_pr <= 3)) { var Z_Trial =+ dZ / 2; }
        if (AND (P_pr > 3, P_pr <= 6)) { var Z_Trial =+ dZ / 3; }
        if (P_pr > 6) { var Z_Trial =+ dZ / 5; }
        I++;   
    }
    return Z_Calc;
    })();

    I don’t understand why it’s causing my browser to crash.

    Please advise.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @pvtsolver

    Your equation includes a semicolon in this line of code:

    
    while (AND (I < 10001 , OR (dZ > 0.00000000000001 , dZ < -0.00000000000001)));
    

    This means the loop is only this line of code, and as the variables used in the condition don’t change on it, there is no way to stop the loop.

    Furthermore, I see the use of symbols { and } are incorrect. You have forgotten a { symbol.

    Note I’m analyzing only the equation’s structure and not the mathematics you have implemented.

    Best regards.

    Thread Starter pvtsolver

    (@pvtsolver)

    I tried this code, still not working!

    Please note that both T_pr and P_pr were assigned earlier to the function.

    (function(){
    var A_1 = 0.3265;
    var A_2 = -1.07;
    var A_3 = -0.5339;
    var A_4 = 0.01569;
    var A_5 = -0.05165;
    var A_6 = 0.5475;
    var A_7 = -0.7361;
    var A_8 = 0.1844;
    var A_9 = 0.1056;
    var A_10 = 0.6134;
    var A_11 = 0.721;
    var Z_Trial = 1;
    var dZ = 1;
    var I = 0;
    while (AND (I < 10001 , OR (dZ > 0.00000000000001 , dZ < -0.00000000000001))) {
        var Den_r = (0.27 * P_pr) / (Z_Trial * T_pr);
        var C1 = A_1 + A_2 / T_pr + A_3 / POW(T_pr , 3) + A_4 / POW(T_pr , 4) + A_5 / POW(T_pr , 5);
        var C2 = A_6 + A_7 / T_pr + A_8 / POW(T_pr , 2);
        var C3 = A_9 * (A_7 / T_pr + A_8 / POW(T_pr , 2));
        var C4 = A_10 * (1 + A_11 * POW(Den_r , 2) / (T_pr , 3));
        var Z_Calc = 1 + C1 * Den_r + C2 * POW(Den_r , 2) - C3 * POW(Den_r , 5) + C4 * POW(Den_r , 2) * Exp(-1 * A_11 * POW(Den_r , 2));
        var dZ = Z_Calc - Z_Trial;
        if (P_pr <= 2) { var Z_Trial =+ dZ; }
        if (AND (P_pr > 2, P_pr <= 3)) { var Z_Trial =+ dZ / 2; }
        if (AND (P_pr > 3, P_pr <= 6)) { var Z_Trial =+ dZ / 3; }
        if (P_pr > 6) { var Z_Trial =+ dZ / 5; }
        I++;   
    }
    var Z = Z_Calc;
    return Z;
    })();

    Please advise.

    • This reply was modified 4 years, 8 months ago by pvtsolver.
    • This reply was modified 4 years, 8 months ago by pvtsolver.
    Plugin Author codepeople

    (@codepeople)

    Hello @pvtsolver

    There are some variables in your equation that are not defined, like P_pr and T_pr

    I’m sorry, but the support service does not cover the debugging of the users’ equations. If you need we implement your project, please, contact us through our private website: Customization

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘While Loop Causes Browser Crashing’ is closed to new replies.