using System; using L=Science.Physics.GeneralPhysics; namespace Serway.Chapter23 { /// /// Example03: Where is the Resultant Force Zero? /// Three point charges lie along the x axis as shown in Figure. /// The positive charge q_1 = 15.0 \mu C is at x = 2.0 m, /// the positive charge q_2 = 6 \mu C is at the origin, and /// the resultant force action on q_3 is zero. What is the /// x coordinate of q_3? /// x = 0.775 m /// public class Example03 { public Example03() { } private string result; public string Result { get{return result;} } public void Compute() { L.Calculus.Function f = new L.Calculus.Function(func); double[] x = {0.1,2.0}; // one-dim did not work. double[] ans = L.Calculus.MinimumOfFunction(f,x,0.5); result += ans[0].ToString() + "\r\n"; result += ans[1].ToString() + "\r\n"; result += ans[2].ToString() + "\r\n"; } private double func(double[] x) { L.ElectricCharge q1 = new L.ElectricCharge(); q1.C = 15.0E-6; L.ElectricCharge q2 = new L.ElectricCharge(); q2.C = 6.0E-6; L.ElectricCharge q3 = new L.ElectricCharge(); q3.C = 1.0; L.Position r1 = new L.Position(); r1.X = 2.0; L.Position r2 = new L.Position(); L.Position r3 = new L.Position(); r3.X = x[0]; L.ElectricForce F3by1 = new L.ElectricForce(q1,r1,q3,r3); L.ElectricForce F3by2 = new L.ElectricForce(q2,r2,q3,r3); L.Vector f = F3by1 + F3by2; return f.Norm + x[1]*x[1]; } } } /* 0.774851773445586 2.86682320522987E-10 1.60071067594222E-10 */