# Tag Info

## New answers tagged differential-equations

2

Notice the details of the error: NMinimize::nnum: The function value [...] is not a number at {k,x0} = {1.91862,1.66351}. >> You need to be sure that objfn doesn't evaluate until is given a Real value as argument. For that, change objfn[k_, x0_] to objfn[k_Real, x0_Real]. You can also avoid the substitution Rule and evaluate the functions directly. ...

5

The PropertyValue::pvobj messages emitted are a bug, however they do not affect the functionality. The EquationTrekker GUI window should still open and operate normally (I've tried it on Windows, though Linux may have further problems). EquationTrekker is based on GUIKit which is being deprecated as far as I know, so this bug may not get a fix.

4

Here's how I would do this, using WhenEvent to find the times you're looking for while solving the differential equation and Sow and Reap to extract them. Clear[bsp] bsp[c_ /; c > 1, d_] := With[ {t1 = First @@ Last@Reap@NDSolve[{ x'[t] == -x[t] + d , x[0] == c , WhenEvent[x[t] - 1.01 d == 0, {Sow[t], "StopIntegration"}] } , ...

3

This is a nice exercise. First of all, we write down the system of equations in vector form as follows (letting m->1, k->1 for simplicity, and without loss of generality) vx''[t] == ma.vx[t] + vf[t]; where vx[t_] = {xA[t], xB[t], xC[t]}; ma = {{-1, 1, 0}, {1, -2, 1}, {0, 1, -1}}; and vf[t_] = {FD[t] - xk, 0, xk}; Check that the vector equation is ...

1

This equation also can be solved using the substitution v[y] -> u[y]^(1/4). Clear[a, b]; eq = y^2 v[y]^3 v''[y] + v[y]^3 y v'[y] + 2 y^2 v[y]^2 v'[y]^2 - a v[y]^4 + b; First@Solve[{u''[y] == D[v[y]^4, {y, 2}], u'[y] == D[v[y]^4, {y, 1}]}, {v''[y], v'[y]}]; equ = eq /. % /. v[y] -> u[y]^(1/4) (* 10 - 4*u[y] + (y*Derivative[1][u][y])/4 + ...

2

NDSolve It has problems with equation.Why? I don't No.Solution with $MAPLE.$ Let's try analytically. $$-a v(y)^4+b+y^2 v(y)^3 v''(y)+2 y^2 v(y)^2 v'(y)^2+y v(y)^3 v'(y)=0 \tag{1}$$ By making the substitution $y=exp(t)$. When subbing for the independent variable, we need to make careful use of the chain rule to express $v(y),v′(y),v″(y)$ in terms of ...

3

i = 4; R2 = 0.001 // Rationalize; RL = 100000; RS = 100000000; R1 = 0.04834 // Rationalize; C1 = 8.48 // Rationalize; C2 = 3.44 // Rationalize; s = DSolve[{V1[t] == RS/(RS + R1)*V2[t] + RS*R1*i/(RS + R1), V2'[t] == 1/C1*(i R2 RL RS - (R2 RL + R1 (R2 + RL) + (R2 + RL) RS) V2[t] + RL (R1 + RS) V3[t])/(R2 RL (R1 + RS)), V3'[t] == ...

0

As mentioned by bbgodfrey in a comment, you can use ParametricNDSolve. As a toy example, let's do the following: sols = ParametricNDSolve[{ x'[t] == -x[t] , y'[t] == -y[t] , e'[t] == -e[t] + x[t]/y[t] , x[0] == a, y[0] == b , e[0] == 0 } , {x, y, e} , {t, 0, 5} , {a, b} ] Then ContourPlot[Evaluate[e[a, b][c] /. sols /. c -> 1], {a, 0, 1}, ...

10

The choices allowed for "ParametricSensitivity" can be seen from the following error message ParametricNDSolveValue[{y'[t] == 1, y[0] == a}, y[1], {t, 1}, a, Method -> {"ParametricSensitivity" -> "?"}]; (* ParametricNDSolveValue::bdsmtd: Method ? for solution stage ParametricSensitivity is not one of {Automatic, None, ForwardSensitivity, ...

0

The functions q2 and q2' should not be here in the conditions of "If". In other words, the differential equations in "NDSolve" should be determined. It is my fault The function "If" can be understand by "NDSolve". The core issue is that the definition of variable "SGN1" is wrong. The value of "SGN1" when t=0 can not be calculated, because it is a ...

0

By advice @Alexei Boulbitch,but works only for interval 0 < x < 4. sol = With[{\[Epsilon] = 1/1000000}, First@NDSolve[{u''[x] + u'[x]/x - u[x]/x^2 + u[x] - u[x]^3 == 0, u[\[Epsilon]] == 0, u[4] == 1}, u[x], {x, \[Epsilon], 4}, Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 5}, InterpolationOrder -> All]]; Plot[{1, ...

1

It is highly unlikely that your equations can be solved with DSolve, because they are nonlinear. Instead use, NDSolve To do so, P[z] and newIC[z] must be defined. For now, I set them to zero. Also, boundary conditions must be defined at surfaces, not corners, which I also fixed. Finally, there was one occurrence of v without arguments in fr, which I ...

0

The analogous 1D problem, NDSolveValue[{D[u[x], x] == -u[x], D[v[x], x] == -v[x], u[0] == 1, v[1] == u[1]}, {u, v}, {x, 0, 2}] integrates across x == 1 without difficult. Therefore, I expected that NDSolveValue[{D[u[x, t], t] + D[u[x, t], x] == -u[x, t], D[v[x, t], t] + D[v[x, t], x] == -v[x, t], u[x, 0] == E^-x, v[x, 0] == E^(1 - x), ...

6

The code in this question can be written as eq = Sqrt[1 - (r[t] - T^2/r[t])^2/(2 a)^2]/(r[t] - T^2/r[t])/(2 a) == r'[t]/r[t]; DSolveValue[{eq, r[0] == T}, r[t], t] // FullSimplify (* InverseFunction[((-Sqrt[-T^4] ArcTan[(2 a^2 + T^2 - #1^2)/ Sqrt[4 a^2 #1^2 - (-T^2 + #1^2)^2]] + T^2 (-2 Log[#1] + Log[-2 T^4 + 2 (2 a^2 + T^2) #1^2 + 2 ...

2

The error message is very descriptive: you haven't specified a boundary condition, but a condition on the middle of the region. If you amend the {x, 0, 2} to {x, 0, 1} it works correctly (but points out that your conditions are inconsistent, which they are). You should be able to impose conditions on the inside of the region by splitting the region in two, ...

3

In the absence of definitions for several functions and constants, I chose v[t] = 1; vdot[t] = 1; todaya = .8; EQfraca = .5; ωa = 1; ρ0 = 1; mina = 0.9; maxa = 1.3; NDSolve then yields two InterpolatingFunctions (* {{a -> InterpolatingFunction[{{0.5, 0.8}}, <>]}, {a -> InterpolatingFunction[{{0.5, 0.8}}, <>]}} *) which in turn ...

1

This system of equations is missing boundary conditions for u in r. Here, let us assume u[0.01, t] == 0, u[1, t] == 0 with r in the range {r, 0.01, 1} to avoid the singularity at r == 0. Also, it is necessary to correct the typo in k1: Replace exp by Exp. Then, {su, sy} = NDSolveValue[{EQ1, EQ2, u[r, 0] == 0, y[r, 0] == 0.1, u[0.01, t] == 0, u[1, ...

4

You cannot have a variable c in your equations that doesn't has a value when you use NDSolve. The function NDSolve is a numerical solver and all parameters need to be specified. Furthermore, you are missing some boundary conditions for your problem. They are needed to be specified accordingly. Here is a working example of your problem: eq = { D[y[x, t], ...

1

For the specific parameters in the question, rmax = 15 kf^-1; mesh = ToElementMesh[Ball[{0, 0, 0}, rmax], MaxCellMeasure -> {"Length" -> 1.2}] (* ElementMesh[ ..., {TetrahedronElement[<10795>]}] *) MaxMemoryUsed[sol = NDSolveValue[{op == 0, DirichletCondition[u[x, y, z] == boundary[l, m, kf, x, y, z] , True]}, u, {x, y, z} ∈ mesh]] // ...

2

The Shooting Method is not strictly necessary here. In addition to MicheaelE2's solution: t0 = 2; M = 8; f[t_] := t^2 - M/t; Solution = NDSolve[ {x''[t]+(f'[t]/f[t]+2/t) x'[t]+(y[t]^2/f[t]^2+2/f[t])x[t] == 0, y''[t] + 2/t y'[t] - 2 x[t]^2/f[t] y[t] == 0, x[t0 + .01] == -3/2 t0 x'[t0 + .01], y[t0 + .01] == 0, y[100000 + .01] == 10, ...

4

This system can be solved exactly with DSolve $Version "10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)" ClearAll["Global*"] i = 4; R2 = 0.001 // Rationalize; RL = 100000; RS = 100000000; R1 = 0.04834 // Rationalize; C1 = 8.48 // Rationalize; C2 = 3.44 // Rationalize; s = DSolve[{V1[t] == RS/(RS + R1)*V2[t] + RS*R1*i/(RS + R1), V2'[t] == ... 4 Basically, there are syntax errors. Fix those and it seems to work. In particular, read the tutorial/DefiningFunctions carefully. Also, all the equations of your differential equation problem should be enclosed in {}. Finally, you have a r0 which I interpreted to be a typo and read it as t0. ClearAll[f]; f[t_] := (t^2) - (M/t); (* <-- N.B. the ... 2 NDSolve is complaining, because v[0, t] == u[1, t] appears to link boundary conditions at x == 0 and x == 1. This can be circumvented by redefining x as 1 - x for v, so that the code becomes, {su, sv} = NDSolveValue[{ D[u[x, t], t] == D[u[x, t], x, x] - u[x, t], D[v[x, t], t] == D[v[x, t], x, x] - v[x, t], u[x, 0] == 1, v[x, 0] == ... 5 You can use WhenEvent[ ] function, maybe it's not the perfect (not very accurate) solution but it works. sol = With[{eps = 10^5}, First@NDSolve[{y'[x] == y[x]^2 + 1, y[0] == 0, WhenEvent[{y[x] == eps, y[x] == -eps}, y[x] -> -y[x]]}, y, {x, -10, 10}]]; Plot[{y[x] /. sol, Tan[x]}, {x, -6, 6}, PlotLegends -> {"NDSolve", "Tan[x]"}, PlotStyle -> ... 1 I've not answered any questions with this example, but I added tmin, tmax, xmin, xmax, and adjusted when to halt the integration. I don't know yet how to handle the Check command in MichaelE2's comment, so that still remains in the code. Manipulate[ClickPane[Show[Plot[g, {t, tmin, tmax}, PlotRange -> {{tmin, tmax}, {xmin, xmax}}, Frame -> ... 12 We can treat the variable$y$as an element$[y_1 \colon y_2]$of the projective line. In code, this means replacing y[x] by y1[x]/y2[x]. For an IVP$y' = f(x, y), \ y(x_0) = y_0$, we translate the initial condition as$y_1(x_0) = y_0, \ y_2(x_0) = 1$. Since the substitution yields an equation in two variables$y_1$,$y_2\$, ...

0

After trying many ways to fit the -numerically solved- model described above, with lots of help from fellows, it turned out that -for this kind of model at least- fitting is much faster if ParametricNDSolve is used, instead of NDSolve, to solve the ODEs of the model. This is just what 'Guess who it is' slightly suggested in a comment to my original question. ...

0

You can use the finite element method with the method of lines as @toadatrix suggested, but for the FEM method to work, you need to do a little more. The Neumann boundary conditions need to be specified using NeumannValue. h[x_] := x*(30 - x)/900; op = D[u[t, x], t] - D[u[t, x], x, x]; begin = 0; end = 30; bc = {u[0, x] == 100*h[x]}; neumann = ...

0

I think this might have been a bug. At least as of V10.0.0, the following works without incident: simplesys = {r'[t] == Piecewise[{{1, 0 <= t <= 10}, {0, 10 <= t <= 20}}, 0], r[0] == 0}; {state} = NDSolveProcessEquations[simplesys, r, t]; Here we reinitialize three times and plot the results of each: Module[{newstate, sol}, ...

3

As the Norm is positive, you don't really need the constraint to determine one minimum for p and t: nm = NMinimize[{ (Norm[{xm[t][p], ym[t][p]} - {xsc[t][p], ysc[t][p]}] - 10^7)^2 /. Soln, TOF - 10 (86400) < t < TOF + 10 (86400) && 0.8 < p < 1}, {t, p}, Method -> "NelderMead"] (* {0.000155262, ...

2

It is quite tricky! Piecewise[ ] functions work only with "EquationSimplification" -> "Residual"... I'll try to dig up why simplesys = {r'[t] == Piecewise[{{1, 0 <= t <= 10}, {0, 10 <= t <= 20}}, 0], r[0] == 0}; state = First@ NDSolveProcessEquations[simplesys, r, t, Method -> {"EquationSimplification" ...

3

Never use Subscript when debugging Mathematica code, because it is difficult to read. The code can be rewritten for clarity as, coupledlorenz = NDSolve[{ x1'[t] == 10*(x1[t] - x2[t]), x2'[t] == 40 x1[t] - x2[t] - x1[t] x3[t], x3'[t] == x1[t] x2[t] - (8/3) x3[t], y1'[t] == 10 (y2[t] - y1[t]) + 0.1 (x1[t] - y1[t]), y2'[t] == 35 y1[t] - y2[t] - ...

1

Here's another way: Have all the functions stored in one. The following computes 100 solutions to an ode satisfying 100 differential initial conditions. {sol} = NDSolve[{x'[t] == Sin[x[t]], x[0] == Range[100]/8}, x, {t, 0, 7}] Since they're wrapped up in one function, they're a bit hard disentangle: Plot[x[t] /. sol // Evaluate, {t, 0, 7}] But ...

0

The following is perhaps elegant but not that fast. The main problem is that your ODE is increasing in complexity at each iteration. Applying N[...] at each step helps with that but sooner or later (fatally) you'll lose precision and the thing will stop converging to the desired solution. k = 3955/100; w = 1; phi[x_] := (1/2) (1 - Sin[Pi/2 x/w]) pcw[x_] := ...

4

To convert ODEs (or difference equations) to state-space form you can use the functions StateSpaceModel, AffineStateSpaceModel, or NonlinearStateSpaceModel. The input signatures of all three functions are the same. The first argument is the set of equations, the second argument is the set of states, the third argument is the set of inputs, the fourth ...

2

Imagine you want to solve (* {3 f[1][t]+ f[2][t]+ f[3][t]+2 f[1]′[t]+3 f[2]′[t]+4 f[3]′[t]==1, 4 f[1][t]+4 f[2][t]+ f[3][t]+2 f[1]′[t]+ f[2]′[t]+ f[3]′[t]==1, f[1][t]+4 f[2][t]+ f[3][t]+3 f[1]′[t]+ f[2]′[t]+ f[3]′[t]==4} *) and then you have the matrices for the coefficients: funM = {{3, 1, 1}, {4, 4, 1}, {1, 4, 1}}; deriM = {{2, 3, 4}, {2, ...

3

Here is how to do it for a smaller working example: eqs = {x''[t] == -y[t], y''[t] == x[t]}; {eqs2, {velocities}} = Reap[eqs /. Derivative[n_][f_][t] :> Derivative[n - 1][Sow[Subscript[v, f], derivs]][t], derivs] (* ==> {{Derivative[1][Subscript[v, x]][t] == -y[t], Derivative[1][Subscript[v, y]][t] == x[t]}, {{Subscript[v, x], ...

2

ε = .1; a = 5; trip = -2 a {1, 1, 1}; dt = .2; s = NDSolve[{ε*u'[t] == -u[t] - 1/3*v[t]^3 + v[t], v'[t] == u[t] + a, u[0] == 0.5, v[0] == 0.5, WhenEvent[Mod[t, dt] == 0, trip = Join[{u[t]}, Rest@RotateRight@trip]; If[Norm[trip + a] < .1, u[t] -> u[t] + a, u[t] -> u[t]]] }, {u, v}, {t, 10}, MaxSteps -> ...

2

Here you have a way without using neither UnitStep nor PieceWise that improves the performance by 75% wrt your code. It computes 200 functions in a very reasonable time for your toy example. The main trick is to use a numeric (black box) function to be able to take Part[... ] inside it. n = 200; af = Array[f, n]; taf[t_] := Through[af[t]] bb[i_?IntegerQ, ...

4

Re NDSolve::ndsz: Using WhenEvent, one can stop the integration before the solution reaches an infinite singularity, which is what is happening with the example differential equation. I removed the Quiet so one might test it. If the differential equation is changed, then it would be possible to get the message to appear. Use Quiet to suppress it, Check to ...

2

The following turns off the warning messages, but is not really a good solution, since it doesn't deal with the root problem of the trouble NDSolve is having with your differential equation. sf[eq_, A_, B_] := VectorPlot[{1, eq /. {a -> A, b -> B}}, {t, -2, 2}, {x, -2, 2}, VectorPoints -> 17, VectorScale -> {0.03, Automatic, None}, ...

3

I think your Quiet is not in the right place, and you may need another one. For f: f[t_, a_, b_, t0_, x0_] := Quiet[u[t] /. First[NDSolve[{u'[t] == ODE, u[t0] == x0}, u, {t, -2, 2}, Method -> "StiffnessSwitching"]]]; gets rid of the NDSolve warning. Then add another Quiet around the Plot: Quiet[Plot[g, {t, -2, 2}, PlotRange -> 2, ...

2

As noted by the OP, adding the constraint, Norm[{xm[t][p], ym[t][p]} - {xsc[t][p], ysc[t][p]}] > 10000000 /. Soln triggers error messages, probably because p typically must be given a numerical value before t is given one in expressions such as xm[t][p]. See the documentation for ParametricFunction. This can be accomplished by defining ...

3

Here is something to get you started: The idea is to use a 2D cross section of the orifice plate in the xz-direction (not the xy-direction, as then you could not apply the surface force). a = 10*10^-3; b = 5*10^-3; \[Nu] = 1/3; p0 = 0.1*10^6; Ey = 200*10^9; h = 1*10^-3; De = (Ey h^3)/(12 (1 - \[Nu]^2)); planeStrain = {Inactive[ Div][{{0, ...

8

I think there's a bug in the internal function NDSolveSPRKDumpCheckSeparability that leads NDSolve to conclude that the system is not separable. I think you should report it and see if WRI can verify it (they would probably appreciate a link to this Q&A). It's a fair amount of work to track it down, and there is a lot of nearly unreadable stuff to ...

3

DSolve seems to have a general solution to linear first-order ODEs that uses an integration that starts at 1. It then solves the boundary condition for the constant of integration. In this case, the constant involves the integral from 1 to the initial value for t, namely 0. Block[{DSolveprint = Print}, DSolve[{x'[t] + y[t] x[t] == 0, x[0] == x0}, x[t], ...

4

Not precisely what you asked for, but I usually do something like this and interpret the results: a =.; DeleteDuplicates@Cases[ eqn, s_Symbol /; Context[s] === "Global", Infinity, Heads -> True] (* {x, s, a, b} *) a = 2; DeleteDuplicates@Cases[ eqn, s_Symbol /; Context[s] === "Global", Infinity, Heads -> True] (* {x, s, b} *)

1

As I find your expressions difficult to work with, let me rewrite them somewhat: Clear[modelo]; modelo[k1_?NumberQ, ki1_?NumberQ, k2_?NumberQ, ki2_?NumberQ, k3_?NumberQ, ki3_?NumberQ, aR_?NumberQ, aRH1_?NumberQ, aRH2_?NumberQ, aRH3_?NumberQ, Ht_?NumberQ, Rt_?NumberQ] := modelo[k1, ki1, k2, ki2, k3, ki3, aR, aRH1, aRH2, aRH3, Ht, Rt] = ...

2

Right now (V10.2) NDSolve uses FEM for elliptic PDEs and that code does up to 2nd order spatial derivatives. The fact that this PDE can be viewed as a time dependent ODE is a coincidence in 1D as pointed out by @MichaelE2 and time dependent ODE are specified via explicit bounds. Another, harder, issue is that it is not trivial to write a general test to see ...

3

One way to do it is to specify an ExtralopationHandler (see section on extrapolation) and have it return 0. for queries outside the domain. For example: nds1 = NDSolveValue[{Inactive[Div][ Inactive[Grad][u[x, y], {x, y}], {x, y}] == 0, DirichletCondition[u[x, y] == 0, y == 0], DirichletCondition[u[x, y] == 1, y == 1]}, ...

Top 50 recent answers are included