using System; using Science.Mathematics; using L=Science.Mathematics.OrdinaryDifferentialEquation; namespace ScienceTest.MathematicsTest.OrdinaryDifferentialEquationTest { /// /// EquationTest /// public class EquationWithInitialConditionTest { public EquationWithInitialConditionTest() { } private string result; public string Result { get{return result;} } public void Compute() { double[] y = new double[2]; // two variables L.InitialCondition ic = new L.InitialCondition(); ic.At = 0.0; // initial independent variable y[0]=10.0; // initial 0-th component value y[1] = 0.0; // initial 1-st component value ic.Value = y; // initial value Function.ToLastType ff = new Function.ToLastType(RightHandSide); L.EquationWithInitialCondition eq = new L.EquationWithInitialCondition(ff, ic, 10.0, 100); eq.Solve(); for (int i = 0; i <= 100; i++) { result += i.ToString() + "\t"; result += eq.IndependentVariable[i].ToString() + "\t"; result += eq.Solution[0, i].ToString() + "\t"; result += eq.Solution[1, i].ToString() + "\r\n"; } } // change functions as you wish private double[] RightHandSide(double x, double[] y) { double[] dydxatx = new Double[y.Length]; dydxatx[0] = y[1]; dydxatx[1] = - y[0]; return dydxatx; } } } /* 0 0 10 0 1 0.1 9.95004165258213 -0.998334171832112 2 0.2 9.80066577775418 -1.98669331125595 3 0.3 9.55336488947271 -2.95520206634958 4 0.4 9.21060993551015 -3.8941834278203 5 0.5 8.77582560927138 -4.79425539900887 6 0.6 8.25335613465534 -5.64642475063038 7 0.7 7.64842185432532 -6.44217688906009 8 0.8 6.96706707156094 -7.17356092335089 9 0.9 6.21609965838548 -7.83326910654491 10 1 5.40302303363165 -8.41470985269459 11 1.1 4.53596119090944 -8.91207359836952 12 1.2 3.62357752584306 -9.32039085007585 13 1.3 2.6749882735528 -9.63558183778692 14 1.4 1.69967142139168 -9.85449727868326 15 1.5 0.707372008637011 -9.97494984338252 16 1.6 -0.291995231719315 -9.99573600690871 17 1.7 -1.28844494392631 -9.9166480797209 18 1.8 -2.27202095050393 -9.7384762825794 19 1.9 -3.23289567646542 -9.46300084868897 20 2 -4.16146836861069 -9.09297423953713 21 2.1 -5.04846104174215 -8.63209363797858 22 2.2 -5.885011161654 -8.08496400986593 23 2.3 -6.66276019634775 -7.45705209352133 24 2.4 -7.37393713397204 -6.75463177751147 25 2.5 -8.01143612921167 -5.98472141371381 26 2.6 -8.56888750273583 -5.15501369217931 27 2.7 -9.04072138497496 -4.27379877822148 28 2.8 -9.42222336891196 -3.34988147739918 29 2.9 -9.709581612169 -2.39249326564098 30 3 -9.89992492407566 -1.41120005537795 31 3.1 -9.99135145681827 -0.415806609533736 32 3.2 -9.98294770914071 0.583741439037669 33 3.3 -9.87479764942014 1.57745694858593 34 3.4 -9.66798187584665 2.55541101969514 35 3.5 -9.36456682269465 3.50783226696305 36 3.6 -8.96758411263867 4.42520441834369 37 3.7 -8.48100026319288 5.29836139615237 38 3.8 -7.90967706140452 6.11857889705581 39 3.9 -7.25932298121528 6.87766157702045 40 4 -6.53643614618044 7.56802493314527 41 4.1 -5.74823940307264 8.1827710835874 42 4.2 -4.90260815368176 8.71575768867806 43 4.3 -4.00799166650721 9.16165932300017 44 4.4 -3.07332865457313 9.51602068519316 45 4.5 -2.1079579617413 9.77530111427056 46 4.6 -1.12152524931332 9.93690996728719 47 4.7 -0.123886620429179 9.99923250380087 48 4.8 0.874989843606117 9.96164601527692 49 4.9 1.86512369203913 9.8245260521764 50 5 2.83662185024603 9.58924267126381 51 5.1 3.77977742363977 9.25814674583944 52 5.2 4.68516670305085 8.83454647951564 53 5.3 5.54374334171787 8.32267434593123 54 5.4 6.34692872869034 7.72764480155351 55 5.5 7.08669770196696 7.05540318464406 56 5.6 7.75565873434559 6.31266631140932 57 5.7 8.34712778796117 5.50685536360511 58 5.8 8.85519509948978 4.64602173821927 59 5.9 9.27478422880316 3.73876660008534 60 5.99999999999999 9.60170278098206 2.79415494178411 61 6.09999999999999 9.83268429515922 1.82162500695928 62 6.19999999999999 9.96542087808491 0.830893996194054 63 6.29999999999999 9.99858626792691 -0.16813902199105 64 6.39999999999999 9.93184908946754 -1.16549205334749 65 6.49999999999999 9.76587615808734 -2.15119988389088 66 6.59999999999999 9.50232582087026 -3.11541362522735 67 6.69999999999999 9.14383138490048 -4.04849918154536 68 6.79999999999999 8.69397480761484 -4.94113347512978 69 6.89999999999999 8.15725090690746 -5.78439759921288 70 6.99999999999999 7.53902244936329 -6.56986593649549 71 7.09999999999999 6.84546657123682 -7.28969034354877 72 7.19999999999999 6.08351305442959 -7.93667857239178 73 7.29999999999999 5.26077508678665 -8.50436613107581 74 7.39999999999999 4.38547319414753 -8.98708087375935 75 7.49999999999999 3.46635310442383 -9.37999967436252 76 7.59999999999999 2.51259836375575 -9.6791966177761 77 7.69999999999999 1.53373857575698 -9.88168222727645 78 7.79999999999999 0.539554179486744 -9.98543333523806 79 7.89999999999999 -0.460021272354385 -9.9894132969739 80 7.99999999999999 -1.45500034337087 -9.89358234379535 81 8.09999999999999 -2.43544152630802 -9.69889798550396 82 8.19999999999999 -3.39154859157393 -9.40730544326142 83 8.29999999999999 -4.31376842819551 -9.02171821251595 84 8.39999999999999 -5.19288651099903 -8.54598895616689 85 8.49999999999999 -6.0201189844898 -7.98487100387354 86 8.59999999999999 -6.78720041740384 -7.34397086031999 87 8.69999999999999 -7.48646638642146 -6.62969218781538 88 8.79999999999998 -8.11093005709774 -5.84917182318787 89 8.89999999999998 -8.65435199476798 -5.01020846862876 90 8.99999999999998 -9.11130250741312 -4.12118476907945 91 9.09999999999998 -9.477215897433 -3.19098355491247 92 9.19999999999998 -9.74843608043022 -2.22889908718859 93 9.29999999999998 -9.92225311531633 -1.24454419258884 94 9.39999999999998 -9.99693027766942 -0.247754220915291 95 9.49999999999998 -9.97172141590341 0.751511217672462 96 9.59999999999998 -9.84687841035703 1.7432678123893 97 9.69999999999998 -9.6236486499409 2.7176062572696 98 9.79999999999998 -9.30426257433173 3.66479126858089 99 9.89999999999998 -8.89191138289135 4.57535889428005 100 9.99999999999998 -8.39071515221216 5.44021104701362 */