# Tag Info

46

OK, there is good news and there is bad news. In the current version 10 there is no way to do this directly. That's the bad news. The good news is that finite element framework used within NDSolve is exposed and documented; for maximum "hackability" convenience. Let's start with a region that @MarkMcClure would consider interesting. We load our favorite ...

29

I've encapsulated the code of the mysterious user21 into a helmholzSolve command. The code is at the end of this post. It adds very little to user21's code but it does allow us to examine multiple examples quite easily, though it has certainly not been tested extensively and could be improved quite a lot I'm sure. It should be called as follows: ...

8

The problem - Genericity of soutions The problem we encounter here is that DSolve can return only a general solution however that general solution cannot satisfy such an initial condition as y'[0] == 1. The issue is related to an arbitrary choice of constants of integration i.e. such constants that are specific to certain types of a differential equations ...

7

Your ODE $$u''(x)+\frac{1}{A} u(x) = 0$$ with constant coefficients has the characteristic polynomial $$p(\lambda)=\lambda^2 + \frac{1}{A} \stackrel{!}{=} 0$$ with the corresponding zeros $\lambda_{1/2} = \pm \frac{i}{\sqrt{A}}$. The general (real) solution can be written as $$u(x) = U_1 \sin{\frac{x}{\sqrt{A}}} + U_2 \cos{\frac{x}{\sqrt{A}}}$$. Your ...

6

You can force NDSolve to use the finite element method: uif = NDSolveValue[{-u''[x] == UnitBox[(x - 0.5) 0.5/0.2], u[0] == 0, u'[1] == 0}, u, {x, 0, 1}, Method -> {"PDEDiscretization" -> "FiniteElement"}]; Possibly, this might be the default. In any case if you compare to the analytical solution: aif = DSolveValue[{Rationalize[-u''[x] == ...

5

You can use ParametricNDSolve to implement a shooting method. Define a finite version of "infinity". inf = 5; Define the differential equation and its initial conditions, parameterised by the initial gradient y'[0] == dy0. For simplicity, I set y[0] == 1. deqn = {y''[x] - x y[x] == 0, y[0] == 1, y'[0] == dy0}; Compute the numerical solution ...

5

As @b.gatessucks said in the comments, there are two issues with your code. First, you'll need to define z as a function with SetDelayed, and also add in ComplexExpand: z[x_, y_] := ComplexExpand @ Abs[((1/3 x + I y) - 2 x)/(I y + 1/x)]; z[x,y] Sqrt[(25 x^2)/9 + y^2] / Sqrt[x^-2 + y^2] Additionally, ContourPlot holds its arguments (i.e. it doesn't ...

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 ...

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 -> ...

4

This ODE system can't be solved symbolically with the given information. First let's define the differential equations: dg1 = y1'[t] == -k1 y1[t] - k2 y1[t] dg2 = y2'[t] == k2 y1[t] - k3 y2[t] dg3 = y3'[t] == k1 y1[t] + k3 y2[t] - k4 y3[t] dg4 = y4'[t] == k4 y3[t] - k5 y2[t] y4[t] + k6 y5[t] dg5 = y5'[t] == k5 y2[t] y4[t] - k6 y5[t] Now the first three ...

4

eqn1[w_, x_, y_, z_] := 3 x y'[x] - 2 z^2 + 3 w y[x] == 5 x eqn2 = eqn1[1, x, y, 2] sol = NDSolve[{eqn2, y[1] == 2}, y, {x, 1, 2}] Then, to get x when y[x] is 3: Solve[(y[x] /. sol) == 3, x] {{x -> 1.556466}} OR as suggested by Mr.Wizard, you can use FindRoot FindRoot[(y[x] /. sol) == 3, {x, 1}] {x -> 1.556466}

4

NDSolve has already detected the largest such intervals for you, which is why the resulting InterpolatingFunctions have restricted domains. You can use InterpolatingFunctionDomain to extract those domains. I'd do something like so Clear[x1, x2, y] eqn = {x1'[t] == -x1[t]^2 - x2[t] + y[t]^3, x2'[t] == x1[t] - x2[t] + x1[t]^2 x2[t]^2, y'[t] == x2[t]^2 ...

4

If you replace your input with pdes = { \!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]$$u[t, x, y]$$\) - Laplacian[u[t, x, y], {x, y}] == 0.6 u[t, x, y] - v[t, x, y] - u[t, x, y]^3, \!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]$$v[t, x, y]$$\) - Laplacian[v[t, x, y], {x, y}] == 1.5 u[t, x, y] - 2 v[t, x, y] ...

4

From the comments, we can set up the OP's DEs as follows and show they can be solved exactly. First the system is the direct product of two independent systems, so let's separated them. γ = 6; g = -98/10; yIVP = {y''[t] + γ*(y'[t])^2 == g, y[0] == 0, y'[0] == 15/10}; qIVP = {q''[t] == -γ*(q'[t])^2, q[0] == 0, q'[0] == 7}; nysol0 = NDSolve[yIVP, {y}, {t, ...

3

One problem is that the equations evaluate to ones with inconsistent dimensions, because Plus threads the components of the constant vector/list term with the unevaluated Dot product. Since NDSolve is not HoldAll or HoldFirst, what the equation evaluates to is relevant. (V9.0.1 actually issues a warning about inconsistent dimensions). {x'[t] == 0. {{0}, ...

3

This has been addressed before and up to Mathematica 9 (I only have 10 at work at the moment and it's a hassle to switch computers) you couldn't handle symbolic, non-explicit matrices in the generic way you want to. I suggest that if you are happy with the answer to that post you delete this as duplicate or if you are using mathematica 10 (which is ...

3

As it is (unspecified k[t], A) NDSolve will not work. However the equations can be handled analytically. After a simple manipulation you can decouple them and get : rawx[t_] = x[t] /. DSolve[{k[t] x'''[t] - k'[t] x''[t] == -k[t]^3 x'[t]}, x[t], t] rawy[t_] = y[t] /. First@DSolve[{D[#, {t, 2}]/k[t] == y'[t]}, y[t], t] & /@ rawx[t] Now you can check ...

3

With the slightly modified input pde1 = 3*D[z[w, x, y], y] == 2 (z[w, x, y] - 1) + (1 - y^2 w) x soln1 = z[w, x, y] /. First@DSolve[pde1, z[w, x, y], {w, x, y}] soln5 = soln1 /. {x -> 0} eqn1 = soln5 == 2.7*soln1 and a replacement of the integration constant ContourPlot[ x /. Solve[eqn1 /. {C[1][w, 0] -> 1, C[1][w, x] -> 1}, x, Method -> ...

3

Here is a systematic approach to this problem, starting from the Lagrangian: I denote the initial radial distance by r0 = 5. and use this value in writing the initial values for the other variables. The time of the simulation is tmax = 30. Everything starts by defining the radius vector rVec in terms of spherical coordinates. Inserting this into the kinetic ...

3

An extended comment that is too long for the comment section. Amplifying on the comment by Stephen Luttrell: eqn = y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x; The generic solution solnG = DSolve[eqn, y[x], x][[1, 1]] y[x] -> E^x + 1/(-x + C[1]) Verifying that the generic solution satisfies the equation eqn /. NestList[D[#, x] &, solnG, 1] ...

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]

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 ...

2

Your post indicates that this is a question about differential equations, so I assume you are attempting to plot a slope field of some type for the DE $y'=sin(x-y)$. In that case, you will want to use the second of your two lines of code. The functions VectorPlot, StreamPlot, etc. all expect vector input. The direction field / slope field / whatever at any ...

2

Assuming that I interpreted the input correctly, koff = 5. 10^-5; kon = 1. 10^4; koff2 = 1. 10^-5; kon2 = 1. 10^4; kcg = 1.2 10^-5; ndsolKRH = NDSolve[{ ag'[t] == -kon2*ag[t]*b[t] + koff2*cg[t] - kcg ag[t], a'[t] == -kon*a[t]*b[t] + koff*c[t], cg'[t] == kon2*ag[t]*b[t] - koff2*cg[t], c'[t] == kon*a[t]*b[t] - koff*c[t], b'[t] == ...

2

added some numeric interval limits for y Clear@"`*" eqn2[w_, x_, y_, z_] := 3*z'[y] == 2 (z[y] - 1) + (1 - y^2 w) x eqn3 = eqn2[1, 1, y, z] sol = NDSolve[{eqn3, z[0] == 1}, z[y], {y, 1, 5} (*added interval*)] Plot[Evaluate[z[y] /. sol], {y, 1, 5}, PlotRange -> All] z3 = z[y] /. sol /. y -> 3

2

The condition x[t] == 0 && p[t] > 0 is not true very often, if at all, for the initial conditions tried in the OP's differential equation. It would not explain why your session would encounter a such a problem. (I haven't gotten such an error in a very long time. I always associated it with a bug. It was often unreproducible. If you can ...

2

There are at least two approaches by which you could obtain a closed form emulation of your answer. Both involve extracting a list of points that are part of the solution. 1. Inexpensive but takes you outside Mathematica. Export the list of points to a CSV file. Obtain (free trial) a program called Eureqa (http://www.nutonian.com/products/eureqa/) that ...

2

If you do not define all constants Plot cannot produce any points - how woud it know what to compute? Try sol = DSolve[y'[x] == r y[x] (1 - y[x]/k) (y[x]/a - 1), y, x]; Plot[Evaluate[ y[x] /. sol /. {C[1] -> 1, a -> 1, k -> 1/2, r -> 1}], {x, .51, 1}, PlotRange -> All]

2

The reasons for the change in the behavior of ParallelTable are subtle. The main source of the problem is that in funcB, the argument k_ is not protected with ?NumericQ like this: funcB[t_?NumericQ, k_?NumericQ] := (* a solution *) funcB[t, k] = Exp[NIntegrate[funcA[et, k], {et, tini, t}]] But more on that later. The problem does not appear in the ...

2

There is a problem with boundary conditions. Changing them and fixing a few typos you can get: eq = {-f[x]^2 + f[x]^4 + x^4 Derivative[1][f][x]^2 + (x^3) /(-1 + x) f[x] ((1 - 2 x) f'[x] - (-1 + x) x f''[x]) == 0, f[1/10] == 1, f'[1/10] == -1/10}; eq // Column // TraditionalForm s = NDSolve[eq, f, {x, 1/10, 9/10}]; Plot[Evaluate[f[x] /. ...

Only top voted, non community-wiki answers of a minimum length are eligible