public void Calc() { double sStart = S3_Minimal.SphereToCyl(Math.PI / 2 / K / 10); double offset = sStart / 10; // Using Newton's method didn't work for this (making A_i go to zero), // without first getting close to the roots. double sRunning = sStart; for (int i = 0; i < 1000; i++) { sRunning += offset; double result = CalcOne(sRunning); if (result > 0) { continue; } Newton n = new Newton(); n.MaxIterations = 25; n.Function = s => CalcOne(s); double s_1 = n.FindRoot(sRunning); double[] x_i = s_i.Select(si => CylToSphere(si)).ToArray(); return; } }
/// <summary> /// https://www.wolframalpha.com/input/?i=y+%3D+(a*(-tanh(x)+-+x*(sech(x))%5E2)+%2B+b*(sech(x))%5E2)%2F(a*(1-x*tanh(x))%2Bb*tanh(x)),+solve+for+x /// </summary> private void CalcNextS(int i) { // Find the s where the flux matches. Newton n = new Newton(); n.Function = s => Flux + CalcFlux(s, A_i[i], B_i[i]); double nextS = n.FindRoot2(s_i[i]); s_i[i + 1] = nextS; }