# Tag Info

0

ClearAll["Global*"]; Remove["Global*"]; sol = NDSolve[{f''[x] == f[x]^3 - f[x], f[-3] == 1, f[3] == -1}, f[x], {x, -3, 3}, Method -> {"Shooting", "StartingInitialConditions" -> {f'[0] == 0, f[0] == 1}}]; Maples symbolic solution(The symbolic solution is quite long and complex) ,converted to numeric form. maple = (-1.527999786 - ...

1

The equation is not stiff, despite the claim by Mathematica. It can be solved by using the "Shooting" Method. NDSolve[{f''[x] == 2 (f[x]^3 - f[x]), f[-3] == 1, f[3] == -1}, f, {x, -3, 3}, Method -> {"Shooting", "StartingInitialConditions" -> {f[-3] == 1, f'[-3] == 0}}][[1, 1]]; Plot[f[x] /. %, {x, -3, 3}, AxesLabel -> {f, x}] This looks like ...

2

If you make your A matrix a function (but avoid starting with capital letters), like aMatrix[x_] := ... then you can use Nest: Nest[aMatrix, x0, 100] where x0 is the starting vector.

3

For small k, xs = 10^-4; xm = 12; s = ParametricNDSolve[{y''[x] + 3 y'[x]/x - y[x] + 3/2 y[x]^2 - k y[x]^3/2 == 0, y'[xs] == 0, y[xm] == 0}, y, {x, xs, xm}, {k, ys}, Method -> {"Shooting", "StartingInitialConditions" -> {y[xs] == ys, y'[xs] == 0}}]; f = y[.2, 5.2] /. s; f[xs] Plot[f[x], {x, xs, xm}, AxesLabel -> {x, y}, PlotRange ...

3

NDSolve stops itself when it believes that it has encountered stiffness. To take advantage of this, rewrite test as test = ParametricNDSolveValue[{(Derivative[2][t][r] + (2/r)* Derivative[1][t][r] - D[Potential[x], x] /. x -> t[r]) == 0, t[10^(-12)] == d, Derivative[1][t][10^(-12)] == 0}, t, {r, 10^(-12), 1}, {d}] In other words, obtain the ...

2

A method is to write a message handler, like in this answer. The handler is passed an argument of the form Hold[Message[...], boolean] where the boolean tells the handler if the message is to be displayed, or not. Since you are looking to capture the info passed to NDSolve::ndsz, I would write the handler like Clear[messageHandler, vals]; vals = {}; ...

5

Albert Retey has demonstrated in a similar situation that you can use "EventLocator" to detect an event in NDSolve. For example: eqn = {\!$$\*SubscriptBox[\(∂$$, $$t$$]$$u[t, x]$$\) == 1/100 \!$$\*SubscriptBox[\(∂$$, $$x, x$$]$$u[t, x]$$\) - u[t, x] \!$$\*SubscriptBox[\(∂$$, $$x$$]$$u[t, x]$$\), u[0, x] == Sin[2 π x], u[t, 0] == u[t, 1]}; ...

1

You can use ScalingFunctions. It appears in red but works. ParametricPlot[{{x, Erfc[x]}, {x, Erf[x]}}, {x, .05, 10}, PlotRange -> All, ScalingFunctions -> {"Log", Identity}, Frame -> True, AspectRatio -> 0.6]

0

The specifics of your plot don't matter so much here, just that you can make a ParametricPlot but you really want a LogLinearPlot from it. This is most easily done if you simply extract the line from the plot, and feed it to ListLogLinearPlot plotToLogLinearPlot[plot_, opts : OptionsPattern[]] := ListLogLinearPlot[ Cases[ plot, Line[x__] :> x ...

1

The integro-differential equation can be rewritten as s = NDSolve[{x'[t] == Integrate[x[q], {q, t - 10, t - 1}], x[t /; t <= 0] == 1}, x, {t, 0, 20}] In itself, this transformation does not help. But, it does suggest a course of action. First, note that x'[0] == 9. Then note that the DDE can be differentiated to give s = NDSolve[{x''[t] == x[t ...

1

As mentioned in the comments that DSolve will be unable to solve this nonlinear coupled system of two ODE's. Instead you can use NDSolve. Here is my try omega = 1.83465945; a0 = 0; epsilon = 0.5; Eq1 = y1''[x] == (Sqrt[(1 - epsilon^2)/((Sqrt[1 + a0^2] + y2[x])^2 - epsilon^2*(1 + y1[x]^2))]/epsilon^2 - omega^2) y1[x]; Eq2 = y2''[x] == (Sqrt[(1 - ...

3

A slight variant of the code in the question yields s = Simplify[k[q] /. DSolve[{(1/2)*σ^2*k''[q] + μ*k'[q] - λ*k[q] == 0, k'[0] == -mc, k'[b] == me}, k[q], q][[1, 1]]] (* (E^(-((q (μ + Sqrt[μ^2 + 2 λ σ^2]))/σ^2)) (E^((2 q Sqrt[μ^2 + 2 λ σ^2])/σ^2) mc λ σ^2 + E^((2 q Sqrt[μ^2 + 2 λ σ^2] + b (μ + Sqrt[μ^2 + 2 λ σ^2]))/σ^2) me λ σ^2 + E^((2 b ...

1

On the other hand, we can use DifferentialRootReduce[] on LegendreP[1/2 (-1 + Sqrt[17]), x] to see what linear differential equation is satisfied by it: Operate[FullSimplify, DifferentialRootReduce[LegendreP[1/2 (-1 + Sqrt[17]), x], x]] DifferentialRoot[Function[{y, x}, {-4 y[x] + 2 x y'[x] + (-1 + x^2) y''[x] == 0, y[0] == ...

2

NDSolve returned interpolation functions which come from the FEM will evaluate to Indeterminate if queried outiside of the region. In this case, for example: RegionMember[\[CapitalOmega], {10, 50}] (*False*) sol[10, 50] (*InterpolatingFunction::dmval: "Input value {10.,50.} lies outside the range of data in the interpolating function. Extrapolation will be ...

3

I have found my mistake. It was on the initial condition if we take $$\phi(zi)=0$$ and $$\phi'(zi)=0$$ the both methods will give the exact same solution.

10

Code phasePortrait[f_, {{xmin_, xmax_}, {ymin_, ymax_}}] := Plot[ f[x], {x, xmin, xmax}, Frame -> True, PlotStyle -> Directive[Black, Thick], ImageSize -> 500, PlotRange -> {{xmin, xmax}, {ymin, ymax}}, Epilog -> {getMarkers[f], getArrows[f, {xmin, xmax}]} ] right = Triangle[{{2, 0}, {-1, 1}, {-1, -1}}]; left = Triangle[{{-2, 0}, ...

1

I Have finally found what was causing the problem. it was with notation. I define my constant a_o but in the equation I have used a_0. Once I changed that it was working.

2

Update: If you use r[t] instead of r as the second argument of NDSolve you get the desired functions directly: sol2 = NDSolve[{(1 + (4 A t^2)/(r[t]^2 (r[t]^2 - Zh^2)) + Zh^2/(r[t]^2 - Zh^2) + (4 A Zh^4 t^2)/(r[t]^2 (r[t]^2 - Zh^2)^3) + (8 A Zh^2 t^2)/(r[t]^2 (r[t]^2 - Zh^2)^2))* r'[t]^2 + ((-4 A t)/(r[t] (r[t]^2 - Zh^2)) - ...

2

Here is one way to do it. With[{A = 2.23818*^8, Zh = 1*^11, a = 1.496*^11, M = 1.33*^20}, {rLo, rHi} = NDSolve[ {(1 + (4 A t^2)/(r[t]^2 (r[t]^2 - Zh^2)) + Zh^2/(r[t]^2 - Zh^2) + (4 A Zh^4 t^2)/(r[t]^2 (r[t]^2 - Zh^2)^3) + (8 A Zh^2 t^2)/(r[t]^2 (r[t]^2 - Zh^2)^2)) r'[t]^2 + ((-4 A t)/(r[t] (r[t]^2 - Zh^2)) ...

2

If I understand your question correctly, you could solve one PDE over the entire region and have different PDE coefficients active in different parts of the region, like so: sol = NDSolveValue[{Inactive[ Div][-If[x <= 1, {{10}}, {{1}}].Inactive[Grad][ u[x], {x}], {x}] == 1, DirichletCondition[u[x] == 0, True]}, u, {x, 0, 2}]; ...

3

I guess this is worth explaining a little better. Here is what I get running the exact code: You can see the error message and the domain say the integration stopped around 0.0473. The trouble arises here, if you don't notice that and plot over your specified range Plot[h[r] /. First@sol, {r, 10^-18, 1}] you get a plot, but its just garbage past ...

0

This is what I get with MMA10 (Linux). {solh, sols} = {h, s} /. NDSolve[{DiffEq1 == 0, DiffEq2 == 0, h[10^(-18)] == 225, s[10^(-18)] == 10, Derivative[1][h][10^(-18)] == 0, Derivative[1][s][10^(-18)] == 0, WhenEvent[h[r] == 0, Sow[s[r]]]}, {h, s}, {r, 10^(-18), 1}][[1]]; Plot[{solh[x], sols[x]}, {x, 0, .35}] x /. FindRoot[solh[x] == 0, {x, ...

1

What you have, I guess, is DAE in the variable t. If you specify the initial condition g[x, 0] == Cosh[x]/Cosh[Pi], NDSolve will compute a "solution," but warns that "an insufficient number of boundary conditions have been specified for the direction of independent variable x." It then computes different initial values, that lead g to be almost identically ...

3

Mathematica 10.4 has ArcLength. You can you code for yourself: i = ArcLength[Sin[x], {x, 0, s}]; v = {t, Sin[t]}; a = Integrate[Sqrt[D[v, t].D[v, t]], {t, 0, s}, Assumptions -> {s \[Element] Reals}]; TraditionalForm[ Grid[{{HoldForm[Integrate[Sqrt[D[v, t].D[v, t]], {t, 0, s}]], a}, {HoldForm[ArcLength[Sin[x], {x, 0, s}]], i}}, Frame -> All]] ...

2

The system of equations can be solved following the procedure in the accepted answer to question 78641. First, observe that the ODEs in eqns all have the form, a[i]'[t] == - fx[i][t] + fy[i][t] - a[i][t] and so can be written in vector form, a'[t] == - fx[t] + fy[t] - a[t] Consequently, the solution is given by NDSolve[{a'[t] == -a[t] - fCalc[a[t]], ...

3

Your WhenEvent is just fine. If you look at an individual solution you can see where it stopped: (a[.8] /. sol)["Domain"] {{0., 3.6351}} The trouble is Plot extrapolates* past the solution domain, so you need to specify each plot domain individually: Show[Table[ Plot[ #[x] /. sol , Evaluate[{x, Sequence @@ (First@#["Domain"])}], ...

3

This answer will show how to fit the data to your model but be aware of a couple of points. The equation for EquationForFilmPotentialUpperPart has an incorrect sign compared to your previous question. The sign from the previous question will be used. With the parameters that minimize the model and data in a least squares sense, the fit still is not very ...

4

Mathematica is checking to make sure that you have enough equations and unknowns, but the way that you've written them out, it only thinks that you have three equations. This is because you've set them up as {5-component vector} == 0, rather than {5-component vector} == {5-component vector}. There are a couple of ways to fix this. One is to use Thread: ...

2

I think you are looking for MaxCellMeasure in case of the finite element method. t0 = 0; t1 = 10; x0 = 0; x1 = 1; nx = 100; dx = (x1 - x0)/nx; eqs1 = {D[u[x, t], x, x] - D[u[x, t], t] == NeumannValue[1, x == x0 || x == x1], DirichletCondition[u[x, t] == 0, t == t0]}; sol1 = NDSolveValue[eqs1, u, {x, x0, x1}, {t, t0, t1}, Method -> ...

2

Replacing For and it's clutter with Table, you can do this easily: timeMax = 1000; Table[sol = NDSolve[{I*x'[t] == Exp[-((t - tao)/bigT)^2]*y[t], I*y'[t] == Exp[-((t - tao)/bigT)^2]*x[t] + Exp[-((t + tao)/bigT)^2]*z[t], I*z'[t] == Exp[-((t + tao)/bigT)^2]*y[t], x[0] == 1, y[0] == 0, z[0] == 0}, {x, y, z}, {t, 0, timeMax}]; S = Re[1 - ...

9

The integral condition can be thought as a normalization condition to determine the constant of integration. For example f = DSolveValue[{y''[x] + λ y[x] == B^3 Sin[Sqrt[λ] x]^3,y[0] == 0}, y, x] And the constant of integration C[2] can be determined by eqn = Integrate[f[x]*Sin[n π x], {x, 0, 1}] == 0 // Simplify; Solve[eqn, C[2]] // Simplify As ...

2

sol = DSolve[ {y''[x] + λ y[x] == B^3 Sin[Sqrt[λ] x]^3 , y[0] == 0, Integrate[y[z] Sin[n π z], {z, 0, 1}] == 0}, y[x], x]; y[x] /. sol

3

This admittedly strange behavior does not occur at x == 0, as one might suppose, but at x == 9, as can be seen by using, for instance, WhenEvent[x > 40, {z[x] -> 1, kkk[x] -> 1}] for which no error message occurs. For the code as in the question, at x == 9, first z[x] -> 1 is executed, next Piecewise seems to be executed (because its argument ...

2

The PDE can be easily solved numerically if a simple additional boundary condition is imposed. Adding a second bundary condition h[1,t] = 0 we find numerically, without any error message hh[x_, t_] = h[x, t] /. NDSolve[{D[h[x, t], t] == D[h[x, t]^3 D[h[x, t], x], x], h[0, t] == 1, h[1, t] == 0, h[x, 0] == (1 - x)}, h[x, t], {x, 0, 1}, {t, 0, ...

2

It seems that this might be a bug or maybe a weakness of the NDSolvemachinery. One can observe, that with the option "SimplifySystem" -> False the issue does not arise. In fact a lot of settings will cause no problem at all. As far as I can see, the culprit is the option DependentVariables as it seems to influence the sequence of equation simplifications ...

2

Like this, P[g_] := h[#]/h[0.5] & /. NDSolve[{h''[x] == g[x], h[0] == 0, h[1] == 0}, h, {x, 0, 1}][[1]] or like this P[g_] := With[{h = NDSolveValue[{h''[x] == g[x], h[0] == 0, h[1] == 0}, h, {x, 0, 1}]}, h[#]/h[.5] &] Both evaluate as expected, P[f][.5] (* 1. *)

0

This allows you to visualize the (small) changes to the function over the course of the iterations, ClearAll[h]; ClearAll[f]; f[x_] = 0.5 - Abs[x - 0.5]; steps = 4; list = Join[ {{#, f[#]} & /@ Subdivide[1, 100]}, Table[ s = NDSolveValue[{h''[x] == f[x], h[0] == 0, h[1] == 0}, h, {x, 0, 1}]; f[x_] = s[x]/s[0.5]; {#, f[#]} & ...

1

To solve the first issue, write s = NDSolve[{h''[x] == f[x], h[0] == 0, h[1] == 0}, h, {x, 0, 1}][[1]]; instead (notice the final brackets).

5

I am badly placed to critic you question since I use to be as criptic as you. First only an economist can understand your objective since this representation is not so standard as you think. I have tried a day long to change the parameters but it is nearly impossible to change the position of c=0. Using the free add-on of Gianluca Gorni here is the best I ...

4

Following up on @J.M.'s observations in the comments, differentiate $$m(t)=m(0)-\frac{T(t)-T_0}{Q_S}$$ to get $$\frac{dm}{dt}=-\frac{T'(t)}{Q_S}$$ Combine with $$\frac{dm}{dt}=4 \, T(t)^{3}+T(t)^{2}$$ to get a differential equation in T[t]: $$T'(t)=-\text{Qs} \left(4 \, T(t)^3+T(t)^2\right)$$ Use DSolve with initial value T[0] == t0: DSolve[{T'[t] ...

4

I am very scared of big equations. So whenever I see one, I go numeric (sometimes it is faster also). m = 0.25; \[Phi] = 2 \[Pi]/3; k = 0.8; a = 0.3; b = 0.4; h1 = -1 - m*x - a*Sin[2*\[Pi]*(x - t) + \[Phi]] h2 = 1 + m*x + b*Sin[2*\[Pi]*(x - t)] F1 = Q1 + a*Sin[2*\[Pi]*(x - t)] + b*Sin[2*\[Pi]*(x - t) + \[Phi]] Z1 = 0.002; N1 = Sqrt[M1^2 + (1/k)]; I am ...

4

If you do this often why not create a shortcut or template as you mentioned in the question? This has the advantage of formatting directly without having to use Evaluate in Place etc, or introducing a custom notation. Example: Derivative[Placeholder[], Placeholder[]][Placeholder[]] // PasteButton // CreatePalette Makes: If preferred a keyboard ...

5

I've thought out 2 auxiliary functions. A possible improvement for the Derivative approach: d /: u_^d[a__][b__] := Derivative[a][u][b] Then $u^{(1,0)}(0,x)$ can be obtained by u^d[1, 0][0, x] But I'm not sure if typing Shift+6 is simpler than typing [+]… A possible improvement for the D approach: d2[u_, y__] := Module[{pos = Position[{y}, ...

7

Spectral methods I present two general ways to approach a second-order linear BVP of the form $$\gamma(x)\, y''(x) + \beta(x)\, y'(x) + \alpha(x)\, y(x) + \varphi(x) = 0,\ y(0) = y_1,\ y(\infty) = y_2$$ By two changes of variables, it can be put into the following forms, including one with homogeneous boundary conditions: C(t)\, u''(t) + B(t)\, u'(t) + ...

0

It is simple like that: H1 = {{x, y, 0}, {y, x, 0}, {0, 0, x}}; H2 = {{x, y, z}, {y, x, 0}, {z, 0, x}}; x = 2; y = 3; z = 4; n = 20; \[Tau] = 0.5; HI[t_?NumericQ] := Piecewise[{{H1, n \[Tau] <= t <= (n + 1/2) \[Tau]}, {H2, (n + 1/2) \[Tau] <= t <= (n + 1) \[Tau]}}] NDSolve[{\[Psi][n \[Tau]] == {0, 1, 0}, I \[Psi]'[t] == ...

2

I think possible issue here was the fact that Piecewise is used here to distinguish between different matrices inside NDSolve. Since Piecewise remains unevaluated until you put in specific time values, this hides the matrix structure from NDSolve at the initial step where it parses the differential equation. Also, I think the periodicity you want to ...

1

I just had a similar problem where I wanted to have some output variable $y(t)$ be an index of a stock variable, e.g. $y(t) = \frac{x(t)}{x(0)}$. As with the OP's cB[0] $x(0)$ actually is a constant. The general solution in this case could be to declare a separate stock variable as a "memory", e.g. make it a discrete variable (DiscreteVariables) and not ...

2

How about: eq = (-1 + x)(1 + x)^2==(2 (1 + x^2)(1 + x^4))/(-2 x (1 + x + x F[x]) + (-1 + x^3) F'[x]); Collect[Solve[eq, F'@x][[1, 1]], F@x] /. (a_ -> b_ F[x] + c_) :> HoldForm[a - b F[x] == c]

3

I am just showing a way to get$g(x)$ and $h(x)$: exp = 2 (1 + x^2) (1 + x^4)/(-2 x (1 + x + x f) + (-1 + x^3) g); gs = Collect[g /. First@Solve[exp == (x - 1) (1 + x)^2, g], f]; ans = u'[x] == gs /. f -> u[x]; {g[x], h[x]} = {1, -1} ({{0}, {1}} /. FullSimplify[CoefficientRules[ans[[2]], u[x]]]); TraditionalForm[Grid[ {{"DE", ans}, {"h[x]", ...

3

Regarding the first question, Mathematica is returning an arbitrary function of x, y, u, v called C[1]; the arguments of the solution are: sol = K /. First@DSolve[{x D[K[x, y, u, v], u] - u D[K[x, y, u, v], x] + y D[K[x, y, u, v], v] - v D[K[x, y, u, v], y] == 0}, K, {x, y, u, v}]; args = ReplacePart[sol[[2]], 0 -> List]; FullSimplify[args, ...

Top 50 recent answers are included