Tag Info

New answers tagged

0

Edit Because of the question's title, I assumed initially that you're interested in the general case of time-dependent driving. This complication is briefly addressed in the first part of my answer. However, the actual system of differential equations in the question has purely time-independent coefficients and is therefore easier to solve in principle. ...


0

In the Second line of code you wrote the Derivatives but in the first one you didn´t specify them. DSolve recognizes this form $Y´[t]$ or this one: $D[Y[t]]$ as a Derivative.


4

J.M. in a comment above alluded to this possibility. Using Series and DifferentialRoot seems like a great way to expand linear differential equations in series. It seems worth putting down in an answer due to its simplicity: lde = {y''[x] - x*y'[x] + Sin[x] == 0, y'[0] == 1, y[0] == 0}; Series[DifferentialRoot[Function @@ {{y, x}, lde}][x], {x, 0, 15}] ...


1

Given that the plot of h[-(Sqrt[2]*π)/2, t] looks something like this, and that the differential equation has a singularity at h == 0, one might expect that NDSolve ought not to continue the solution to the max time the OP sets, which is t == 6. NDSolve might do it, but that would be because of numerical error when h is close to zero (insufficient ...


3

Looks like homework, but anyway. The idea is to take derivatives, substituting from lower derivatives to rewrite e.g. x'' in terms of x' (which you can already rewrite in terms of x). Below I show this for x''[0]. Similar substitutuins, keeping track of past derivative rewrites, can be used to get higher derivatives to evaluate at t=0. xprime[t] := -k1 x[t] ...


2

Search the documentation for Taylor, first hit is Series. Solve Differential equation, sol = x[t] /. First@DSolve[ { D[x[t], t] == -k1 x[t] + (1 - x[t]) k2 Exp[-k2 t] , x[0] == 0 } , x[t], t]; You can get the series by Series[sol, {t, 0, 3}] but you are interested only in the 2nd and 3rd order coefficients, so you see at the ...


2

I think the problem is not with Mathematica or your understanding of it but with the mathematics of that equation and it isn't even a singularity which would show for Epsilon->0. The problem is that your equations have a problem when the derivative w'[x] becomes 0, and that does happen already for much higher values of Epsilon (I have renamed that to eps ...


2

The problem is that the solution takes the other branch of the square root. Look at this: f = u[t] /. First@DSolve[{u'[t] == Sqrt[u[t]] + 1/(n + 1), u[0] == 0}, u[t], t] fp = D[f, t] Plot[Evaluate[{fp, Sqrt[f] + 1/(n + 1)} /. n -> 3], {t, 0, 1}] Note that Mathematica warns you that some solutions may not be found.


1

While working with NDSolve whenever I see a square root of first order I get rid of it immediately by squaring and raising the order or power of ODE... as a Rule. It could be beneficial with DSolve also. Better to raise the power or order of ODE rather than bring in the power of Mathematica into an otherwise easily doable reconfiguration. c= 1/(1+n) ; ...


3

I could not verify the solution given by M either. Maple solved this and verifies the solution. But the solution is given as implicit. Here is the solution fyi in case it might help see what is the problem: restart; eq:=diff(u(t),t)=sqrt(u(t))+1/(n+1); ic:=u(0)=0; sol:=dsolve({eq,ic},u(t)); DEtools[remove_RootOf](sol); ...


1

DSolve[e t''[e] + (1 - Pr/b^2 (1 + bs) + e) t'[e] == 0 && t[Pr/b^2] == 1 && t[0] == 0, t, e] // TraditionalForm // TeXForm $$\left\{\left\{t\to \left(\{e\}\to \frac{\Gamma \left(\frac{(\text{bs}+1) \Pr }{b^2},0\right)-\Gamma \left(\frac{(\text{bs}+1) \Pr ...


2

This is how you can set the time step: mdfun = NDSolveValue[{D[u[t, x], t] == 0.5 D[u[t, x], x, x] + u[t, x] D[u[t, x], x], u[t, -Pi] == u[t, Pi] == 0, u[0, x] == Sin[x], WhenEvent[u[t, Pi/2] > -.1, "StopIntegration"]}, u, {t, 0, 10}, {x, -Pi, Pi}, Method -> \ {"MethodOfLines",(*"DiscretizedMonitorVariables"->True,*) Method -> {"FixedStep", ...


5

Actually a very simple modification would make your approach work: Plot[Evaluate[u[4., x] /. %], {x, 0, 1}] the problem is that for pattern matching (which is what ReplaceAll (/.) does in the background) 4 (with head Integer) and 4. (with head Real) are two different things. You even might meet cases where using 4. would not be enough to make this work, ...


1

Use ParametricPlot: NDSolve[{x''[t] + x[t] == 0, x[0] == 1, x'[0] == 0}, x, {t, 0, 2 Pi}] {X[u_], XD[u_]} = {x[u], x'[u]} /. First[%] ParametricPlot[{X[t], XD[t]}, {t, 0, 2 Pi}, AxesLabel -> {x[t], x'[t]}, PlotStyle -> {Blue, Thick}]


2

There is actually a somewhat cryptic but very simple way to make NDSolve only return the solution at the end point: sol = NDSolve[{ r''[t] == -G r[t]/Norm[r[t]]^3, r[0] == {1, 0, 0}, r'[0] == {0, 2 Pi // N, 0} }, r, {t, 1, 1}, Method -> "ExplicitRungeKutta", MaxStepSize -> (1/365 // N) ] As it is easy to oversee: the difference is ...


3

I realize from the idiomatic way this program was written that Mathematica is not a language you're very familiar with yet, at least not with the efficient and readable ways Mathematica can address your project. I won't try to suggest every possible improvement but focus on the specific problem of getting the functions you want into the Plot. The following ...


5

Building on @SjoerdC.deVries answer you can use: sol = NDSolveValue[{D[u[x, y], x, x] + D[u[x, y], y, y] == 0, DirichletCondition[u[x, y] == 100., x == 40 && 40 <= y <= 60 || x == 60 && 40 <= y <= 60 || 40 <= x <= 60 && y == 40 || 40 <= x <= 60 && y == 60], u[x, 0] == u[x, 100] == ...


14

You need a DirichletCondition (new in V10) here. Using regions (also from V10): Ω = RegionDifference[Rectangle[{0, 0}, {100, 100}], Rectangle[{40, 40}, {60, 60}]]; sol = NDSolveValue[{ D[u[x, y], x, x] + D[u[x, y], y, y] == 0, DirichletCondition[u[x, y] == 100., x == 40 && 40 <= y <= 60 || x == 60 && 40 <= y <= ...


6

Yes! fun = NDSolve[{u ρ'[u] + ρ[u - 1] == 0, ρ[u /; u < 1] == 1}, ρ, {u, 0, 20}, WorkingPrecision -> 40, PrecisionGoal -> ∞, AccuracyGoal -> 40, Method -> "StiffnessSwitching"][[1, 1, 2]]; fun[15] (* 7.5899080042980595046528227779709126741*10^-20 *) DickmanRho[15] (* 7.5899080042980595047*10^-20 *) It works not only in V10 (in ...


1

After solving your DE, do Table[{x, u[x]} /. %, {x, -3, 3, 0.01}] and save the output to a file "u.dat", which should make it a double column table.


7

The curvature and torsion are rates of turning of the Frenet-Serret frame and can be used to integrate the frame using an Euler-type method. The unit tangent vector of the frame is the velocity and can be used to integrate the position. Set up some initial data: the initial Frenet-Serret frame (randomly chosen below), initial point s0, the change in ...


1

Quite often a differential equation may be viewed as an algebraic problem. In such a view, the integration constant C[1] might naturally be viewed as an element of the projective line. But in the natural Mathematica point of view, the constant is taken to belong to an affine subspace, namely the real number line. One could approach finding a solution by ...


10

Here are a couple of suggestions. First let's look at the mesh generation with is documented with ToElementMesh and in the mesh generation tutorial. Needs["NDSolve`FEM`"]; x2 = 2; y2 = 1; r = 1/8; reg = ImplicitRegion[ 0 <= x <= x2 && 0 <= y <= y2 && (x - x2/2)^2 + (y - y2/2)^2 >= r^2, {x, y}]; For the mesh ...


2

The finite element method can be used on this problem if we make a change of variables to convert the domain $[0, \infty)$ to a finite interval. I believe only MachinePrecision is available in FEM. Since AiryAi vanishes so rapidly, it will make a precise result for a large argument difficult to obtain. Another difficulty in obtaining a precise solution is ...


1

Your equation describes the damped harmonic oscillator. The general form is $ \frac{\mathrm{d}^2x}{\mathrm{d}t^2} + 2\zeta\omega_0\frac{\mathrm{d}x}{\mathrm{d}t} + \omega_0^{\,2} x = 0$, where $\omega_0$ is a frequency (note that this is like k in your case) and $\zeta$ is a damping parameter. In your textbook the author chose to change variables form ...


1

One can also use FindInstance or with V10 NumberLinePlot: c = 1.1111; y[x_] = x - c Sin[x]; sol = FindInstance[y[x] == 0 && -10 < x < 10, x, Reals, 15] // Values // Flatten; {-0.786647, 0, 0.786647} p = Point @ Transpose[{sol, Table[0, {Length @ sol}]}]; Plot[y[x], {x, -1, 1}, Epilog -> {PointSize[0.02], Red, p}] ...


4

NSolve and Reduce can solve this equation by restricting search. As can be seen by inspection: x=0 is a solution and there are two other solutions symmetric about the origin (a plot reveals and noting if r is a root then so is -r: $c \sin(-r)- (-r)= -(c\sin(r)-r)=0$. Quiet@Reduce[y[x] == 0 && Abs@x < 1, x] yields: x == -0.786647 || x == 0 || ...


2

As it can be seen in Mathematica's help, NSolve deals primarily with linear and polynomial equations. A more general function dealing with numerical methods is FindRoot (starting points are based on the plot you've attached to your post): FindRoot[y[x], {x, 1}] (*{x -> 0.7866465}*) FindRoot[y[x], {x,-1}] (*{x -> -0.7866465}*) For x=0 ...


1

It is much easier and more general. Your equation system = {D[x1[t], {t, 2}] == -ν1 D[x1[t], t] - ω1^2 x1[t] + F Cos[ω t]}; without specifying neither the initial conditions nor the parameters (except of course v1 > 0, ω1^2 > 0) is solved by xx[t_]=x1[t]/. DSolve[System, x1[t], t][[1]]; The behaviour of the solution at large t is simply given by ...


1

If you want to include the case where the derivative is zero everywhere (which is not a differential equation), you can use Join[ DSolve[y'[x]^2 + y[x]^2 == 1, y[x], x], Solve[y[x]^2 == 1, y[x]]] {{y[x] -> -Sin[x - C[1]]}, {y[x] -> Sin[x + C[1]]}, {y[x] -> -1}, {y[x] -> 1}} Although, DSolve does not complain about the lack of a derivative in the ...


2

Second answer -- OK, the first answer was hogwash (the curious can inspect the edit history). It pays sometimes to write out the equation and think about it first. The code for this one looks so complicated, but the equations basically have the form (here d = 80000) rc'[t] == 2.05594*10^-10/rc[t] - 8189.14 rc[t] + 80000. rm[t], rm'[t] == -80000. rc[t] + ...


2

sol = NDSolve[{ x'[t] == -x[t - Pi] + y'[t - 1], y'[t] == -y[t - Pi] - x'[t - 1], x[t /; t <= 0] == Cos[t], y[t /; t <= 0] == Sin[t]}, {x, y}, {t, 0, 18}]; Plot[Evaluate[{x'[t], y'[t]} /. First[sol]], {t, 0, 18}, PlotRange -> All] ParametricPlot[Evaluate[{y'[t], x'[t]} /. First[sol]], {t, 0, 18}]


4

The problem is that NDSolve is not HoldAll or HoldFirst. Therefore the differential equation is evaluated symbolically before it is passed to NDSolve. Thus the differential equation that NDSolve sees is {R*Q'[t] + Q[t]/C2 == newfSign[t], Q[0] == 0} (* {4.54545*10^6 Q[t] + 2000 Derivative[1][Q][t] == 5, Q[0] == 0} *) The reason that one does not see the ...


4

For me it looks like the OddQ function behaves unexpected If it is replaced by OddQ2[n_] := If[Mod[n, 2] == 1, True, False] then s = NDSolve[{R*Q'[t] + Q[t]/C2 == newfSign[t], Q[0] == 0}, Q, {t, 0, 4 \[Tau]}] Plot[Q[t]/C2 /. s, {t, 0, 4 \[Tau]}, PlotRange -> Full] outputs As I stated in my comment, for functions with fast oscillations there are ...


1

This is just an observation and a workaround for now. Instead of using OutputResponse with {t,0,limit}, just use t. This forces M to give an analytical solution using DSolve (not as fast as numerical with the limit, but it does avoid the problem you see with t=0. This is why NDSolve also fails, since when using the limit, NDSovle is used vs. DSolve sol = ...


1

You can integrate the mean square error mse at the same time as computing u[x]. s = NDSolve[{ u''[x] == (h*L*L/(d*d))*phi[x]*phi[x]*u[x] - F*L*L*(1 - phi[x]), u[-W*d/L] == 0, u[1 + W*d/L] == 0, mse'[x] == (u[x] - vE[x])^2, mse[-W*d/L] == 0}, {u, mse}, {x, -W*d/L, 1 + W*d/L}, Method -> "StiffnessSwitching", WorkingPrecision -> 40, ...


0

Sorry, I formulate my comments here, because there is not enough space in the comment section. 1) The dimension question cannot be ignored. The original Schrödinger equation should look like $-\frac{h^2}{2m} \left(\frac{d}{\text{dx}}\right)^2 u(x)+A \sin ^2\left(\frac{2 \pi x}{L}\right) u(x)+B x v(x)=a u(x)$ Letting $x \to q z$ and $u \to p U, v \to p V$ ...


8

params = {ν1 -> 1, ω1 -> 10, F -> 4}; system = {D[ x1[t], {t, 2}] == -ν1 D[x1[t], t] - ω1^2 x1[t] + F Cos[ω t], x1[0] == 1, x1'[0] == 0}; soln = DSolve[system /. params, x1[t], t][[1, 1]]; (* and the steady state is*) lim = ((List @@ (Expand@soln[[2]])) /. x_ /; (Limit[x, t -> Infinity] == 0) :> 0) steadyState = Simplify@Together[Plus @@ lim] ...


3

One can do it semi-automatically. Let us introduce a normalized variable $$ \xi = \frac{x}{s(t)}, \quad \xi \in [0,1] $$ and make a simple finite difference method over $\xi$. The differential equation in new variables is ClearAll[u, s, x, t, ξ] D[u[x/s[t], t], t] == D[u[x/s[t], t], x, x] /. x -> ξ s[t] If we divide the interval $[0,1]$ by $n$ ...


3

The linear system is easily solved generally by first calulating the MatrixExp. Then we can extract the real and imaginary parts. Here we go The complex matrix A = {{0, 1}, {-2, -I}}; The matrix exp At = MatrixExp[t A] (* {{1/3 (2 Cos[t] + Cos[2 t] + I (2 Sin[t] - Sin[2 t])), 1/3 (I (-Cos[t] + Cos[2 t]) + Sin[t] + Sin[2 t])}, {1/ 3 (2 I (Cos[t] ...


0

No one seems to want to explain to you why or how this answer doesn't compute, only that it doesn't compute. It's a very quick-fix. The syntax of DSolve works like this: DSolve[{eqn1,eqn2,...},function[var],var] But here, var indicates only the independent variable you are looking for and not the other variables with respect to which you are not solving ...


7

With eqn[{k_, r_, H0_, P0_}] := {H'[t] == r (1 - H[t]/k) - d H[t] P[t], P'[t] == -s P[t] + e H[t] P[t], H[0] == H0, P[0] == P0} d = 0.01; s = 0.3; e = 0.02; I would define one simulation as sim := Module[ {k = RandomVariate[NormalDistribution[150, 20]], r = RandomVariate[NormalDistribution[0.4, 0.003]], H0 = RandomVariate[UniformDistribution[{50, ...


9

Here is what I think the issue is: Let's look at what NDSolve parses. Needs["NDSolve`FEM`"] {state} = NDSolve`ProcessEquations[{op == 0, bc}, u, {x, y} \[Element] reg, Method -> {"FiniteElement", "MeshOptions" -> {MaxCellMeasure -> 0.005}}]; femData = state["FiniteElementData"]; femData["PDECoefficientData"]["All"] {{{{0}}, {{{{0}, ...


1

You need to specify numeric values for the parameters U, R, c (normally one avoids starting names with capital letters in Mathematica). Since you did not, I made them up. As for the principal problem, one approach is to use the DiscreteVariables option to switch between your differential equation and the equation uc'[t] == 0. U = R = c = 1; uf[t_] := ...


0

Your syntax c[x > 0, 0] is not valid, try this: Diff = D[c[x, t], t] - D[c[x, t], {x, 2}] == 0; ic = {c[x, 0] == If[x != 0, 0, 1], c[0, t] == 1, Derivative[1, 0][c][1, t] == 0}; s1 = NDSolve[{Diff, ic}, {c[x, t]}, {x, 0, 1}, {t, 0, 1}]; You get a solution, however note that B.C. is ill conditioned in that the soluion must go sharply from ...


5

You can use Method -> "FiniteElement" such as: h = 10.6; F = 0.001; d = 1.0; L = 100*d; phi[x_] := Piecewise[{{0.5*(1 - Tanh[x]), x < L*0.5/d}, {0.5*(1 + Tanh[x - L/d]), x > L*0.5/d}}] s = NDSolveValue[{u''[x] == (h)*phi[x]*phi[x]*u[x] - F*d*d*(1 - phi[x]), u[-2.5] == 0.0, u[L + 2.5] == 0.0}, u, {x, -2.5, L + 2.5}, Method -> ...


3

It seems to me that using MakeBoxes in this case is overkill. How about this simpler definition? supressVariable[f_Symbol] := Format[f[t, x], TraditionalForm] := Interpretation[f, f[t, x]] SetAttributes[supressVariable, Listable] supressVariable[{v, ρ, p, f}]; This doesn't encounter the issue you faced, because the symbol f is passed directly to ...


3

InterpretationBox holds its arguments (it has HoldAllComplete). You must evaluate ToBoxes[f] outside of this head, easily accomplished with Function as follows: supressVariable[f_Symbol] := f /: MakeBoxes[f[t, x], TraditionalForm] := InterpretationBox[#, f[t, x]] & @ ToBoxes[f]


5

Use the method option Method -> {"IndexReduction" -> {Automatic, "ConstraintMethod" -> "Projection"}} This forces the equations to be incorporated as constraints. See tutorial/NDSolveDAE#128085219. Depending on the version, you might need to us Rationalize to make the coefficients exact to avoid 1/0 errors. (In general, I avoid machine ...


2

Another remedy is to take the limit as y'[0] -> 1: sol = DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x, y'[0] == a}, y[x], x]; Limit[y[x] /. sol, a -> 1] (* {E^x, E^x} *)



Top 50 recent answers are included