Clear["Global`*"];
eqns = {x'[t] + a*x[t] == 0, x[0] == 1};
As pointed out by Bill in the comments, for comparison the exact solution is
sol1 = DSolve[eqns, x, t][[1]]
(* {x -> Function[{t}, E^(-a t)]} *)
Verifying,
eqns /. sol1
(* {True, True} *)
table1 = Table[x[t] /. sol1, {a, 1, 10}, {t, 0, 10}];
Since there is a parameter in the differential equation, use ParametricNDSolve
sol2 = ParametricNDSolve[eqns, x, {t, 0, 10}, a, WorkingPrecision -> 45]
Comparing the approximate numeric results with the exact results (see Chop
):
table2 = Table[(x[t] /. sol2)[a], {a, 1, 10}, {t, 0, 10}];
table1 - table2 // Chop
(* {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} *)
EDIT: Duplicate values of x
occur whenever the products of a
and t
are identical.
table3 = DeleteDuplicates[
Table[
{(x[t] /. sol2)[a] // N, a, t},
{a, 1, 10}, {t, 0, 10}] //
Flatten[#, 1] &,
((Times @@ Rest[#1]) == (Times @@ Rest[#2]) &)]
{{1., 1, 0}, {0.367879, 1, 1}, {0.135335, 1, 2}, {0.0497871, 1,
3}, {0.0183156, 1, 4}, {0.00673795, 1, 5}, {0.00247875, 1,
6}, {0.000911882, 1, 7}, {0.000335463, 1, 8}, {0.00012341, 1,
9}, {0.0000453999, 1, 10}, {6.14421*10^-6, 2, 6}, {8.31529*10^-7, 2,
7}, {1.12535*10^-7, 2, 8}, {1.523*10^-8, 2, 9}, {2.06115*10^-9, 2,
10}, {3.05902*10^-7, 3, 5}, {7.58256*10^-10, 3, 7}, {3.77513*10^-11,
3, 8}, {1.87953*10^-12, 3, 9}, {9.35762*10^-14, 3,
10}, {6.9144*10^-13, 4, 7}, {1.26642*10^-14, 4, 8}, {2.31952*10^-16,
4, 9}, {4.24833*10^-18, 4, 10}, {1.38879*10^-11, 5,
5}, {6.30512*10^-16, 5, 7}, {2.86261*10^-20, 5, 9}, {1.94854*10^-22,
5, 10}, {5.74949*10^-19, 6, 7}, {1.4236*10^-21, 6,
8}, {3.74594*10^-24, 6, 9}, {-5.64139*10^-25, 6,
10}, {5.24831*10^-22, 7, 7}, {2.06509*10^-25, 7,
8}, {-1.67134*10^-25, 7, 9}, {5.40872*10^-26, 7,
10}, {-1.32346*10^-25, 8, 8}, {-1.35923*10^-26, 8,
9}, {4.91701*10^-27, 8, 10}, {3.00999*10^-27, 9,
9}, {9.54615*10^-28, 9, 10}, {7.64079*10^-28, 10, 10}}
x/.DSolve[{x'[t]+a*x[t]==0, x[0]==1}, x,t]
which gives youx[t]=E^-(a t)
and you can calculate any desired values ofx[t]
anda
from that $\endgroup$