## Solve Differential Equation with Boundary Conditions (lengthy equation)

I have a lengthy equation to be substitute into a differential equation. I used DSolve to generate the output. However, it took me more than 3 hours and it still running. The DE is the convective-diffusion equation which is

`1/r del /del r (r del f1s/ del r) - a1 = 0`

and the boundary condition is
`r=k` when `del f1s/ del r =0`

so the input is:

``````a1 = -(810165067720210957064125/25546163167349695028752149) -
0.00395833 (-0.5 + r) (1.02817 +
3.98107/(5.36839*10^11/r - 1.*10^12 r)^(1/20) +
2./((1.27718 - 0.666667 r - 0.333333 r^2)/(1. + r))^(1/20) +
3./((3.05377 - 0.888889 r - 0.111111 r^2)/(4. + r))^(1/20) +
3.01772/(-((1. (-0.675531 + 0.125 r + r^2))/(0.0625 + r)))^(
1/20) + 3.03794/(-((1. (-0.867019 + 0.285714 r + r^2))/(
0.142857 + r)))^(1/20) +
2.04096/(-((1. (-1.14539 + 0.5 r + r^2))/(0.25 + r)))^(1/20) +
3.08948/(-((1. (-1.57936 + 0.8 r + r^2))/(0.4 + r)))^(1/20) +
3.12414/(-((1. (-2.32712 + 1.25 r + r^2))/(0.625 + r)))^(1/20) +
3.23431/(-((1. (-7.80849 + 3.5 r + r^2))/(1.75 + r)))^(1/20)) +
0.125 (-0.5 + r) (0.196614 +
1.32702*10^-12 (5.36839*10^11/r - 1.*10^12 r)^(19/20) +
0.666667 ((1.27718 - 0.666667 r - 0.333333 r^2)/(1. + r))^(
19/20) + ((3.05377 - 0.888889 r - 0.111111 r^2)/(4. + r))^(
19/20) +
0.894139 (-((1. (-0.675531 + 0.125 r + r^2))/(0.0625 + r)))^(
19/20) +
0.787613 (-((1. (-0.867019 + 0.285714 r + r^2))/(0.142857 + r)))^(
19/20) +
0.453547 (-((1. (-1.14539 + 0.5 r + r^2))/(0.25 + r)))^(19/20) +
0.572125 (-((1. (-1.57936 + 0.8 r + r^2))/(0.4 + r)))^(19/20) +
0.462835 (-((1. (-2.32712 + 1.25 r + r^2))/(0.625 + r)))^(
19/20) +
0.239579 (-((1. (-7.80849 + 3.5 r + r^2))/(1.75 + r)))^(19/20))

TRY = DSolve({1/r D(r f1s'(r), r) - a1 == 0, f1s'(k) == 0}, f1s, r, GeneratedParameters -> S)
``````

I’m stuck and I don’t know what else should I do. I tried to do manually by integrating the equation but it’s kinda haywire. Could anyone help me out with this coding. Really appreciate it 🙂

Posted on

## differential equations – How to solve this ODE by DSolve

I try to solve this second order ODE:
$$frac{ y'(x)}{3 x}+y”(x)+y(x)^3=0$$
with some of the following boundary conditions:

My question is, how to solve this problem ?
I have tried
`sol=DSolve({y''(x) + (1/(3x ))y'(x) + y(x)^3 == 0,y(0) == 0, y'(0) == 0},y,x)`

Unfortunately, DSolve not work

Posted on

## differential equations – Problem with ParameterFitting:””The function value…is not a list of real numbers…”

I’m trying to use the data:

``````    In:= data = Transpose[{datat, datax}]

Out= {{1, 83956}, {2, 83959}, {3, 83959}, {4, 83964}, {5,
83966}, {6, 83968}, {7, 83970}, {8, 83975}, {9, 83976}, {10,
83990}, {11, 84010}, {12, 84011}, {13, 84018}, {14, 84024}, {15,
84029}, {16, 84038}, {17, 84044}, {18, 84054}, {19, 84063}, {20,
84063}, {21, 84063}, {22, 84063}, {23, 84081}, {24, 84084}, {25,
84095}, {26, 84102}, {27, 84103}, {28, 84106}, {29, 84106}, {30,
84123}, {31, 84128}, {32, 84146}, {33, 84154}, {34, 84161}, {35,
84160}, {36, 84171}, {37, 84177}, {38, 84186}, {39, 84191}, {40,
84195}, {41, 84198}, {42, 84209}, {43, 84216}, {44, 84228}, {45,
84286}, {46, 84335}, {47, 84378}, {48, 84422}, {49, 84458}, {50,
84494}, {51, 84494}, {52, 84553}, {53, 84572}, {54, 84624}, {55,
84653}, {56, 84673}, {57, 84701}, {58, 84725}, {59, 84743}, {60,
84757}, {61, 84780}, {62, 84785}, {63, 84816}, {64, 84830}, {65,
84838}, {66, 84857}, {67, 84871}, {68, 84889}, {69, 84917}, {70,
84950}, {71, 84992}, {72, 84992}, {73, 85071}, {74, 85117}, {75,
85117}, {76, 85226}, {77, 85246}, {78, 85327}, {79, 85402}, {80,
85418}, {81, 85503}, {82, 85622}, {83, 85708}, {84, 85906}, {85,
86045}, {86, 86202}, {87, 86381}, {88, 86570}, {89, 86783}, {90,
86990}, {91, 87213}, {92, 87489}, {93, 87655}, {94, 87827}, {95,
87985}, {96, 88099}, {97, 88206}, {98, 88328}, {99, 88460}, {100,
88580}, {101, 88672}, {102, 88793}, {103, 88906}, {104,
88958}, {105, 89045}, {106, 89144}, {107, 89214}, {108,
89279}, {109, 89375}, {110, 89441}, {111, 89494}, {112,
89527}, {113, 89567}, {114, 89616}, {115, 89654}, {116,
89695}, {117, 89718}, {118, 89752}, {119, 89784}, {120,
89814}, {121, 89836}, {122, 89863}, {123, 89895}, {124,
89914}, {125, 89933}, {126, 89953}, {127, 89986}, {128,
90008}, {129, 90025}}
``````

To find parameters in the differential equation model that give the best fit:

``````    pfun = ParametricNDSolveValue[{
Ii[1.] + S[1.] + R[1.] + F[1.] == 1411780000,
S'[x] == -R0*F[x]/alpha,
R'[x] == gamma*Ii[x],
Ii'[x] == F[x]/alpha + r*F[x] - gamma*Ii[x],
F'[x] == -F[x]/alpha + R0*F[x]/alpha - r*F[x],
Ii[1.] == 1900,
R[1.] == 78504,
F[1.] == 1900}, R + Ii + F, {x, 0, 150}, {alpha, R0, gamma, r}]

fit = FindFit[data,
pfun[alpha, R0, gamma, r][x], {{alpha, 1.}, R0, gamma, r}, x]
``````

however I got an error code:

`````` FindFit::nrlnum: The function value {<<1>>} is not a list of real numbers with dimensions {129} at {alpha,R0,gamma,r} = {1.,1.,1.,1.}.
``````

How can I solve this problem? Any help would be greatly appreciated.

Posted on

## Computations on differential geometry – Mathematica Stack Exchange

I have to do some really long computations of basic riemannian geometry. I am trying to use Mathematica to check them. This is the kind of computations I want to do. Let $$M$$ be a riemannian manifold and $$f:Mrightarrow M$$ be given by $$f(x)=x$$, then I want a code that tells me that
$$df_x(e_i)=e_i,$$
for $$xin M$$ and $$e_iin T_xM$$.
Also some of the computations involve and inner product. For exampe, if $$f:Msubset (mathbb{R}^3,langle, rangle) rightarrow mathbb{R}$$ is given by $$f(x)=langle x,xrangle$$ then I would like to have a code that tells me that
$$df_x(e_i)=2langle x,e_irangle,$$
for $$xin M$$ and $$e_iin T_xM$$.
I would be thankful for any help.

Posted on

## Discrete stochastic process to stochastic differential equation

I was studying about stochastic processes and got stuck at a question.
Let’s say, I have a stochastic process like the following,

$$X_i(t+1)=epsilon(X_i + X_j)$$

$$X_j(t+1)=(1-epsilon)(X_i + X_j)$$

where $$epsilon$$ is a uniform random number $$in(0,1)$$ and $$i,jin{1,2,3,…,N}$$. I wanted to know if this process can be formulated in terms of $$dX_i/dt$$, with an unit of time being $$N^2$$.

Also is it possible to do this for any discrete stochastic process ? I mean, can any discrete stochastic process be casted into a corresponding stochastic differential equation ?

Posted on

## differential equations – Passing Product function through NIntegrate?

I have a set of intervals, Times1, that I have calculated using the following code. This code works well on its own.

``````a = 3/100; b = d = 1; c = 1/2; K = HMax = 2000;NCritical = 100; SearchIncrements = 100; FinalSearchTime = 5000; InterpolatingFinalTime = 30000;

Needs("RootSearch`");

System3(g1_, t0_) :=Once(Y(t) /. NDSolve({X'(t) == X(t)*b*H(t)/HMax - X(t)*d*(X(t)+Y(t))/K,

Y'(t) == Y(t)*b*(1 - c*g1)*H(t)/HMax + Y(t)b(1 - c*g1)g1(1 - H(t)/HMax) - Y(t)d(X(t) + Y(t))/K,

H'(t) == Y(t)*b*(1 - c*g1)*(1 - H(t)/HMax)*g1 - a*H(t),

X(0) == ((b E^((b E^(-a t0) K t0)/HMax) K^2)/(d E^(a t0) (-1 + E^((b E^(-a t0) K t0)/HMax)) HMax + b K)), Y(0) == 1, H(0) == Exp(-a*t0)*HMax},

{X(t), Y(t), H(t)}, {t, 0,InterpolatingFinalTime}) // First);

Times1(g1_, t0_) := Block({},If(0.2 <= g1 <= 1,Times2 = Drop(Flatten(Table(RootSearch(System3(g1, t0) == NCritical,

{t, i*SearchIncrements, (i + 1)*SearchIncrements}), {i, 0,
FinalSearchTime/SearchIncrements, 1})), 1)((All, 2));

Intervals1 = Partition(Times2, 2, 2)))
``````

I am trying to solve a numerical integral, P1. This integral is a function of another numerical integral, P2, that is a function of `Product`. This product is performed j times, where j is the number of elements in Times1.

``````System1 = ParametricNDSolve({X'(t) == X(t)*b - a*X(t)^2/K,X(0) == Exp(-a*t0)*K}, {X}, {t, 0,1000}, {g, t0});

System2 = ParametricNDSolve({X'(u) == X(u)*b - a*X(u)^2/K,X(0) == Exp(-a*t0)*K}, {X}, {u, 0,1000}, {g, t0});

P1(g_, t0_?NumericQ) := Module({B1, P2},

P2(t1_?NumericQ) := Piecewise({{Product(

B1(u_?NumericQ) :=NIntegrate(b*(1 - c*g)*(H(g, t0)(t) /. System1)/HMax -d*((X(g, t0)(t) /. System1))/K,

{t, Times1(g, t0)((j, 1)), u},Method -> {Automatic, "SymbolicProcessing" -> 0});

1 - (1 - 2/(1 + NIntegrate(Exp(-B1(u))*(b*(1 - c*g)),{u, Times1(g, t0)((j, 1)), Times1(g, t0)((j, 2))},

Method -> {Automatic, "SymbolicProcessing" -> 0}))),{j, 1, Length(Times1(g, t0))}),

0.2 <= g <= 1}, {0, g < 0.2}}); P2(t0))

P1(0.6, 80)
``````

When I try this, I receive an error that says “The expression j cannot be used as a part specification.” Is there a solution to this problem? Any help would be greatly appreciated!

Alex

Posted on

## How to solve a lengthy Differential Equation with boundary conditions

How to solve a lengthy Differential Equation with boundary condition. I tried using DSolve however it took me up 3 hours but still running. When I used DSolve in a simple Differential Equation with boundary condition, it works perfectly. Have you experienced this before or could you give any alternatives way to solve a lengthy Differential Equation with boundary condition.

Posted on

## differential equations – Mathematica + Waddington Landscape

The fool has a question. Concerning updates 1, 2 and especially three (Visualization, Plot3D). How does one control the number of valleys and the slope (either backwards or forwards) for each valley? I need one groove as a starting point branching out to 12 more or less symmetrical valleys. The valleys should be about the same distance apart (left to right) but with variable, controllable amounts of slope (front to rear). I can only afford to pay two trillion dollars for the correct answer. (I am a Nigerian banker!) Here is the link to the discussion:
How to solve this PDE for steady state?

Posted on

## Solution of general linear stochastic differential equation system

The form of the general linear SDE system is the following:

$$dunderline{X}(t) = left(underline{underline{A}}(t) cdot underline{X}(t) + underline{a}(t) right) cdot dt + sum_{i = 1}^{I} left(underline{underline{B_i}}(t) cdot underline{X}(t) + underline{b_i}(t) right) cdot dW_i(t)$$

where $$underline{underline{A}}$$ and $$underline{underline{B}}$$ are matrices, $$underline{X}$$, $$underline{a}$$ and $$underline{b}$$ are vectors.

I would like to know the general solution of the $$underline{X}(t)$$, $$mathbb{E}left( underline{X}(t) right)$$ and $$mathbb{Var}left( underline{X}(t) right)$$. It is clear that $$mathbb{E}left( underline{X}(t) right)$$ is the solution without any $$dW_i(t)$$ noise. It is clear too that $$mathbb{Var}left( underline{X}(t) right) = mathbb{E}left((underline{X}(t)-mathbb{E}left( underline{X}(t) right)) cdot (underline{X}(t)-mathbb{E}left( underline{X}(t) right))^T right)$$.

But what are the exact formulas of the fields above? Do they even exist? If there is no exact formula in general case, is there any in (1) $$underline{underline{B_i}}(t) = 0$$, (2) $$underline{b_i}(t) = 0$$ or (3) $$I = 1$$ cases? What are they then?

Thank you very much for the answers!

Posted on

## differential equations – How to use NDEigenvalue to accurately estimate functional determinants?

Goal: Ultimately, I would like to find a trustworthy approximation for the ratio of the functional determinant of two differential operators using the formula
$$frac{text{Det}(hat{D}_0)}{text{Det}(hat{D})} =frac{prod^infty_i lambda_{0,i}}{prod^infty_j lambda_j} approx frac{prod^N_i lambda_{0,i}}{prod^N_j lambda_j}$$
where $$lambda$$ are the eigenvalues of the respective operators and $$N$$ is the number of eigenvalues used in the approximation.

Step 1: defining the operators.

To define these two operators I first must solve the following coupled ODE boundary value problem in $$phi(t)$$ and $$p_phi(t)$$. The system depends on the parameter $$tau > 0$$.

``````bvp = {D(p(Phi)(t), t) == (-(1/(Tau)))*p(Phi)(t)^2*(Sin(2*(Phi)(t))/2) +
(1/(Tau))*p(Phi(t)*Cos(2*(Phi)(t)) + (1/(Tau))*(Sin(2*(Phi)(t))/2),
D((Phi)(t), t) == 2*Pi - ((1/(Tau))*Sin(2*(Phi)(t)))/2 +
(1/(Tau))*p(Phi)(t)*Sin((Phi(t))^2,
(Phi)(0) == 2*ArcTan((-1 + Sqrt(1 + 4*Pi^2*(Tau)^2))/(2*Pi*(Tau))),
(Phi)(1) == 2*ArcTan((-1 + Sqrt(1 + 4*Pi^2*(Tau)^2))/(2*Pi*(Tau))) + 2*Pi}
``````

``````sol = ParametricNDSolveValue(bvp, {(Phi)(t), p(Phi)(t)}, {t, 0, 1}, {(Tau)})
``````

Using these solutions I can define the two differential operators (which depend on a choice of parameter $$tau$$ and the numerical solution of $$phi(t)$$) with Dirichlet boundary conditions

$$hat{D}_0$$

``````{-D((Tau)*Csc(sol((Tau))((1)))^2*D((Psi)(t), t), t), (Psi)(0) ==
0, (Psi)(1) == 0}
``````

and $$hat{D}$$

``````{-D((Tau)*Csc(sol((Tau))((1)))^2*D((Psi)(t), t), t) + (2*(Tau)*Cot(sol((Tau))
((1)))*Csc(sol((Tau))((1)))^2*D(sol((Tau))((1)), {t, 2}) -
(Tau)*Csc(sol((Tau))((1)))^4*(Cos(2*sol((Tau))((1))) + 2)*D(sol((Tau))((1)), t)^2 +
2*Pi*Csc(sol((Tau))((1)))^4*(2*Pi*(Tau)*(Cos(2*sol((Tau))((1))) + 2) - Sin(2*sol((Tau))
((1)))))*(Psi)(t), (Psi)(0) == 0,
(Psi)(1) == 0}
``````

Step 2: Numerically calculating the eigenvalues.

First selecting a particular value of the parameter $$tau$$ to be $$0.1$$, I use the inbuilt function NDEigenvalue to numerically calculate N=39 Eigenvalues for $$hat{D}_0$$ and multiply them together

``````Times @@ NDEigenvalues({-D(0.1*Csc(sol(0.1)((1)))^2*D((Psi)(t), t), t), (Psi)(0) == 0,
(Psi)(1) == 0}, (Psi)(t), {t, 0, 1}, 39)
``````

Similarly for $$hat{D}$$

``````Times @@ NDEigenvalues({-D(0.1*Csc(sol(0.1)((1)))^2*D((Psi)(t), t), t) +
(2*0.1*Cot(sol(0.1)((1)))*Csc(sol(0.1)((1)))^2*D(sol(0.1)((1)), {t, 2}) -
0.1*Csc(sol(0.1)((1)))^4*(Cos(2*sol(0.1)((1))) + 2)*D(sol(0.1)((1)), t)^2 +
2*Pi*Csc(sol(0.1)((1)))^4*(2*Pi*0.1*(Cos(2*sol(0.1)((1))) + 2) - Sin(2*sol(0.1)((1)))))*(Psi)(t), (Psi)(0) == 0,
(Psi)(1) == 0}, (Psi)(t), {t, 0, 1}, 39)
``````

Then I simply take the ratio. I do this also for additional choices of the parameter $$tau$$.

The issue: The accuracy of this approximation is not good enough for small values of the parameter $$tau$$.

From the underlying physics, I strongly expect that

• The ratio will be a monotonically increasing function of $$tau$$

Unfortunately, after calculating a few of these ratios in the parameter range $$0, I find that the ratios do not appear to be monotonically increasing. Additionally, the order of magnitude seems to change significantly as I change $$N$$, the number of eigenvalues used in the approximation. These two things make me conclude the numerical solutions I have so far are untrustworthy.

If I try to increase the number of Eigenvalues used in the approximation beyond 39 I get an error message saying “A maximum number of 39 eigenvalues and functions can be computed for this discretized system.” Solution Attempt:

My main guess at how to solve this issue is to find a way to increase the number of eigenvalues that NDEigenvalue returns.

1. I have tried to increase the accuracy of the parametric solutions for $$phi(t)$$, but this did not seem to help very much

2. I have also tried to change methods used in NDEigenvalues (see the code below)

``````NDEigenvalues({-D(0.1*Csc(sol(0.1)((1)))^2*D((Psi)(t), t),t), (Psi)(0) == 0,
(Psi)(1) == 0}, (Psi)(t), {t, 0, 1}, 70, Method -> {"SpatialDiscretization" ->
{"FiniteElement","MeshOptions" -> {"MaxCellMeasure" -> 0.0001}}})
``````

This will return about 60 eigenvalues before returning another error message (see image below) but has the same issue as the original method and will also sometimes find eigenvalues that when compared with the set of the first 39 eigenvalues found by the default method are sometimes an order of magnitude different! So far all of this code runs fairly quickly, so I feel that there should be a way to get Mathematica to think for longer and find more eigenvalues but so far I have not found how to do this in a satisfactory way. I do not know if there are other ways I should be trying to solve my problem and would very much appreciate any advice I can get on how to make progress.

Posted on