using System; using Science.Mathematics; using L=Science.Mathematics.OrdinaryDifferentialEquation; namespace ScienceTest.MathematicsTest.OrdinaryDifferentialEquationTest { /// /// FixedString /// public class FixedString { public FixedString() { } private string result; public string Result { get{return result;} } private int numberOfParameters = 1; private int numberOfVariables = 3; private int n = 3; public void Compute() { L.BoundaryCondition bc = new L.BoundaryCondition(); Function.ToLastType load = new Function.ToLastType(Load); Function.ToLastType score = new Function.ToLastType(Score); bc.Load = load; bc.Score = score; bc.Start = 0.0; bc.End = 0.5; L.EquationWithBoundaryCondition eq = new L.EquationWithBoundaryCondition(); Function.ToLastType func = new Function.ToLastType(Derivs); eq.FirstDerivativeFunction = func; eq.Condition = bc; eq.HowMany = 20; double[] initialParameter = new double[1]; initialParameter[0] = ((double) n * 3.0)*((double) n * 3.0); eq.InitialGuess = initialParameter; eq.Solve(); for (int k = 0; k < eq.IndependentVariable.Count; k++) result += k + "\t" + eq.IndependentVariable[k].ToString() + "\t" + eq.Solution[0][k].ToString()+"\t"+ eq.Solution[1][k].ToString()+"\r\n"; result += eq.Solution[2][0].ToString()+"\r\n"; result += (Math.PI*n*n*Math.PI).ToString()+"\r\n"; } private double[] Load(double start, double[] p) { double[] y = new Double[numberOfVariables]; y[0] = 0.0; y[1] = 4.0; y[2] = p[0]; return y; } private double[] Score(double end, double[] v, double[] p) { double[] f = new Double[numberOfParameters]; f[0] = ( n%2==0 ? v[0] : v[1]); return f; } private double[] Derivs(double x, double[] y) { double[] dydx = new Double[y.Length]; dydx[0]=y[1]; dydx[1]=-y[2]*y[0]; dydx[2]=0.0; return dydx; } } } /* 0 0 0 4 1 0.025 0.0990772895988122 3.8894796815899 2 0.05 0.192679552400759 3.56402609675206 3 0.075 0.275634312461699 3.04162386239737 4 0.1 0.343357476533461 2.35114100916814 5 0.125 0.392106651788022 1.53073372945871 6 0.15 0.419187951039559 0.625737860159917 7 0.175 0.42310485737999 -0.31383638291161 8 0.2 0.403640921941355 -1.23606797749882 9 0.225 0.361871724894675 -2.08999425886276 10 0.25 0.300105438718628 -2.82842712474463 11 0.275 0.22175527822076 -3.41056065741412 12 0.3 0.131150885744237 -3.80422606517608 13 0.325 0.0332990744414527 -3.9876693349269 14 0.35 -0.0663928490163667 -3.95075336237381 15 0.375 -0.162415893067373 -3.69551813003743 16 0.4 -0.249463809009809 -3.23606797749326 17 0.425 -0.322726315150886 -2.59779219331442 18 0.45 -0.378154913737121 -1.81596199895302 19 0.475 -0.412686611586176 -0.933781455421348 20 0.5 -0.424413181577417 1.8249290967276E-15 88.8264396098016 88.8264396098042 */