New answers tagged

2

I tried solving the equation with DSolve by disregarding boundary conditions, but couldn't get an analytic solution. So I think the specific equation is not solvable, which only leaves the question of how to impose a boundary conditions at infinity. This can be done by doing the transformation of variables $$y = \tan(x)$$ All I can do with this here is to ...


2

To answer your question Why doesn't Mathematica automatically do this transformation for me? Mathematica don't know that x is a function of t. But you can solve your system directly: sol = NDSolveValue[{y'[x] == (x - y[x])/(1 - y[x] - x), y[0] == 0}, y, {x, 0, 1}] You get an error message: NDSolveValue::ndsz: At x == 0.603939625832659`, step ...


6

This works with a couple of subtle changes. Notable WhenEvent needs to return just the string "StopIntegration", not a list with that among other things. From the looks of it you are maybe trying to use {} for grouping things, where the curly brackets are only for lists in mathematica. f[x_] := 0.1 + 0.05*Sin[2*Pi*(x + 1/3)]; xxold = yold = 0; tmax = 400; ...


2

What about: StoppingTest -> (Apply[ Or, Table[EuclideanDistance[Coordinates[s], Source[i]] < 1, {i,1,NumSources}], {0}])


2

As I noted in comments above, NDSolve has boundary value problems. It needs boundary conditions at t = -Tsim for the first derivatives of F and H with respect to time, and it cannot have spatial boundary conditions involving derivatives of F with respect to r. In the absence of additional information, I modified the arguments of NDSolve as follows. sol = ...


3

Can help further this? {xsol, ysol} = NDSolveValue[{y1''[x] == -1/2 (x - y1[x]), y2''[x] == -1/4 (x - y2[x] - 5), y1[0] == y2[1], y1[1] == y2[0], y1'[0] == y2'[1], y1'[1] == y2'[0]}, {y1, y2}, {x, 0, 1}] Plot[Evaluate[{xsol[x], ysol[x]}], {x, 0, 1}]


0

Maybe this help: Set up a very large system of equations: Clear["Global`*"] (Format[#[n_]] := Subscript[#, n]) & /@ x; X[k_] := x[k]; n = 1000; vars = Table[X[i][t], {i, n}]; eqns = Table[j = Mod[i, n] + 1; {X[i]'[t] == 1/(X[i][t] + X[j][t])^2,X[i][0] == 1/i}, {i, n}]; Solve for all of the dependent variables, but save only the solution for ...


6

Another alternative is to package your constant vector parameters as DiscreteVariables. In the OP's case, it necessary only to chnage e since b occurs inside Cross, which will not evaluate until all its arguments are vectors. Note that in the equation we changed e to e[t] and set its value with e[0] == {0, 0, 1}. b = {1, 0, 0}; (*e={0,0,1};*) q = 1; m = 1; ...


8

Alternative method: b = {1, 0, 0}; e = {0, 0, 1}; q = 1; m = 1; sol = NDSolve[{e + Cross[pos'[t], b] == m/q pos''[t], pos[0] == {0, 0, 0}, pos'[0] == {0, 0, 0}}, pos, {t, 0, 10}, Method -> {"EquationSimplification" -> "Residual"}]; ParametricPlot3D[pos[t] /. sol, {t, 0, 10}, PlotRange -> All]


12

The main problem is that your pos is not seen as a 3D vector. The cross product is therefore interpreted as a scalar: q*Cross[D[pos[t], t], b] when adding this to the vector q.e this 'scalar' term is added to each of the vector components: q*e + q*Cross[D[pos[t], t], b] This won't work, instead do: b = {1, 0, 0}; e = {0, 0, 1}; q = 1; m = 1; ...


4

Sometimes a manual approach to the shooting method makes a BVP easier to solve. Set up with ParametricNDSolveValue: zmin = 0; zmax = 2; psol = ParametricNDSolveValue[{ D[ϕ[z], z, z] == 4*λ*ϕ[z]*(ϕ[z]*ϕ[z] - v^2) + 2*γ*χ[z]*χ[z]*ϕ[z], D[χ[z], z, z] == 2*γ*χ[z]*(ϕ[z]*ϕ[z] - μ^2) + 4*β*γ*χ[z]*χ[z]*χ[z], ϕ[zmin] == phi[zmin], ϕ'[zmin] == phip, ...


1

You can control the automatic switching between when a control (e.g. slider) is actively being moved and when it has been releeased with ControlActive. Better rendering takes more time, so it is up to the programmer to balance quality and speed, if the Automatic setting is unsatisfactory. See also PerformanceGoal. sol = DSolve[{D[u[t, x], t] - x*D[u[t, ...


4

Here is one way (but I remain interested in other ways to solve the problem). The indefinite integral can still be reinterpreted as a differential equation, of the form $$ \frac{\partial F}{\partial t}(t,t')=f(t,t') \quad \text{under }F(0,t')=0 $$ and, though this isn't obvious, it can still be handled as a differential equation by NDSolve - except this ...


4

Indeed, NDSolve cannot solve this equation as written. However, it is easy enough to eliminate y from the system. {x'[t] == y[t] + x[t] y[t] + z[t], z'[t] == 2*y[t]} /. y[t] -> 1 + z[t] - 2 x[t] and then solve and plot s1 = NDSolve[{Derivative[1][x][t] == 1 - 2 x[t] + 2 z[t] + x[t] (1 - 2 x[t] + z[t]), Derivative[1][z][t] == 2 (1 - 2 x[t] + ...


0

Try this: L1[u_] := D[u, x, \[Theta]]; L2[u_] := D[u, {x, 3}]; L3[u_] := L1[L2[u]]; L3[y[x, \[Theta]]] yielding Have fun!


7

You can use RotationTransform. With[{rot = funs[[3]] /. Inner[Rule, {x, y}, RotationTransform[π/2][{x, y}], List]}, ContourPlot[rot, {x, -.5, .5}, {y, -.5, .5}] ] Hope this helps. Also with Manipulate Manipulate[ With[{rot = funs[[3]] /. Inner[Rule, {x, y}, RotationTransform[θ][{x, y}], List]}, Quiet@ContourPlot[rot, {x, -.5, .5}, {y, -.5, ...


5

rotation = {x, y}.{{Cos[t], Sin[t]}, {-Sin[t], Cos[t]}}; f[t_] = funs[[3]] /. {x -> rotation[[1]], y -> rotation[[2]]}; Manipulate[ ContourPlot[f[t], {x, -.3, .3}, {y, -.3, .3}], {t, -\[Pi], \[Pi]}]


2

The phase portrait gives you $y'$ as a function of $y$ in multiple pieces (all those intervals where the former is actually a unique function). In each such piece, you can in principle find the functional form $dy/dt = y' = g(y)$ by inspection. Next, how to get the time? Use $$t-t_i = \int \frac{dy}{g(y)} $$ which is then solvable for $y(t-t_i)$ in ...


2

NDSolve as used in the question has too many boundary conditions in x and none in t. (One periodic boundary condition in x for each dependent variable fully meets the need for boundary conditions in that dimension.) Not knowing what boundary conditions are desired in t, I made some up. e = 0.1; k = -4.47675; eqns = {D[y1[t, x], {t, 1}] + k/Pi * D[y1[t, ...


0

Only numerically,and that under certain circumstances. eqn = y*D[u[x, y], x] + (x^3 + x - u[x, y])*D[u[x, y], y] == u[x, y]^2 + u[x, y]; sol = NDSolve[{eqn, u[x, 1] == -1/2, u[1, y] == -1/2}, u[x, y], {x, 1, 4}, {y, 1, 4}, PrecisionGoal -> 10, MaxStepSize -> 0.001]; Plot3D[Evaluate[u[x, y] /. sol], {x, 1, 4}, {y, 1, 4},PlotRange -> All] ...


0

You need to specify at least two reasonable boundary conditions, such as equations for u(x,0) and u(0,y) or u(0,0) and u(L,L).


0

Your two ordinary differential equations coupled can be rephrased from a single partial differential equation. Such equations require a Fourier Series solution where the boundary conditions imply the type of eigenfunctions and the initial condition implies the relationship between the series term coefficients. That's what you're running up against in your ...


0

Because of the differential boundary condition the circular eigenfunctions, which result from a separation of variables approach, do not have linear Fourier series coefficients. You will likely need to look for the cross points in the eigenvalues of two trigonometric functions. To figure out which ones assume that there is a function of U is explicitly a ...


3

It's a confirmed bug in event processing. Try Method -> {Automatic, "DiscontinuityProcessing" -> False} as a workaround. NDSolve[ Join[eqxy, {x[0] == 0, x'[0] == 1, y[0] == 1, y'[0] == 1}], {x, y}, {t, 0, 1}, Method -> {Automatic, "DiscontinuityProcessing" -> False}]


3

How about changing the domain {x,0,b} and adding an "ExtrapolationHandler" to your NDSolve, as: sol = ParametricNDSolve[{y'[x] == b y[x], y[0] == 1}, y, {x, 0, b}, {b}, "ExtrapolationHandler" -> {Indeterminate&, "WarningMessage"->False}] Plot[Evaluate[Table[y[b][x] /. sol, {b, 0.1, 0.3, 0.1}]], {x, 0, 0.3}]


4

You can use a custom Piecewise function for the plotting, Plot[Evaluate[ Table[Piecewise[{{y[b][x], x <= b}}, Null] /. sol, {b, {0.3, 0.2, 0.1}}]], {x, 0, 0.3}]


2

sol = ParametricNDSolve[{y'[x] == b y[x], y[0] == 1}, y, {x, 0, 0.3}, {b}] Show@Table[Plot[y[b][x] /. sol, {x, 0, 0.6}], {b, {0.6, 0.4, 0.2}}] supplement You can plot it according to your needs. Show@Table[Plot[y[b][x] /. sol, {x, 0, b}], {b, {0.3, 0.2, 0.1}}] Plot[Evaluate[Table[y[b][x] /. sol, {b, {0.3, 0.2, 0.1}}]], {x, 0, 0.3}, PlotRange ...


17

Why the original matrix approach fails The question originally showed an attempt at a solution based on converting the differential operator (the Hamiltonian) into a matrix (HMax) by forming a Table of overlap integrals. The functions used in these integrals were the bound-state eigenfunctions of the hydrogen radial equation. Although the matrix obtained in ...


12

Although the question singles out the square, it is made clear that the actual applications includes other polygonal shapes as well. This means that it's impossible to give a general answer based on the assumption of separability. The square is separable in Cartesian coordinates, but the pentagon (e.g.) is not. This is why I'm focusing this answer on the ...


0

This function lst[inp_] := Module[{apt, expr}, expr = inp; apt[x_] := {x[[1]], x[[2, 2, 1]]}; SetAttributes[apt, Listable]; expr[[0]] = List; SortBy[apt[expr], Last] ] lst[a*Exp[k1*t] + b*Exp[k2*t] + c*Exp[k3*t]] returns a list sorted by k1,k2,...: {{a, k1}, {b, k2}, {c, k3}}. This may only work when a,b,c,k1,k2,k3 are numbers due to ...


0

Try this: Coefficient[a, E^(-0.03056065153782187` t)] Coefficient[b, E^(-0.03056065153782187` t)] (* {0.678839} {-0.660328} *) Have fun!


3

You're experiencing the typical and, in the simple example, expected limitations of searching for roots. The two FindRoot results are easily understood in terms of Newton's method. The best way to proceed, assuming given the example is typical, is to use WhenEvent. sol = NDSolve[{y''[t] == -y[t], y[0] == 1, y'[0] == 0, WhenEvent[y[t] == 0, firstzero = ...


1

Cases[a, coeff_.*e^(-0.0305607 t) :> coeff, 2] {0.678839} Cases[b, coeff_.*e^(-0.0305607 t) :> coeff, 2] {-0.660328} The pattern coeff_. would work even if the coefficient were 1, e.g. Cases[{e^(-0.0305607 t)}, coeff_.*e^(-0.0305607 t) :> coeff, 2] {1} because the dot, signifying default value, defaults to 1 in the case of a ...


3

This due to a simple typo. If you look at {{LIxx, LIxy, LIxz}, {LIyx, LIyy, LIyz}, {LIzx, LIzy, LIzz}} // MatrixForm You'll see that the LIyx entry is not quite right. If you change that to LIxx = FullSimplify[({{λ + 2 μ, 0, 0}, {0, μ, 0}, {0, 0, μ}})]; LIxy = FullSimplify[({{0, λ, 0}, {μ, 0, 0}, {0, 0, 0}})]; LIxz = FullSimplify[({{0, 0, λ}, {0, ...


0

So, putting it together form the comments: xmax=6;tmax=30; schrodingerEq=-(1/2) D[ψ[x,t],{x,2}]+(1/2) x^2 ψ[x,t]==I D[ψ[x,t],t]; ψinit[x_]:=(1/π)^(1/4) Exp[-1/2 (x-1)^2]; sol=NDSolve[{schrodingerEq,ψ[x,0]==\[Psi]init[x],ψ[xmax,t]==0,ψ[-xmax,t]==0}, ψ,{x,-xmax,xmax},{t,0,tmax}]; solution=ψ/. sol[[1]]; ...


3

Another possibility is sol = Solve[s^2 + a*s + b == 0, s]//Flatten; Sum[C[i] Exp[sol[[i, 2]] t], {i, Length[sol]}] But, why not just DSolve[y''[t] + a y'[t] + b y[t] == 0, y[t], t][[1, 1, 2]] both of which give (* E^(1/2 (-a - Sqrt[a^2 - 4 b]) t) C[1] + E^(1/2 (-a + Sqrt[a^2 - 4 b]) t) C[2] *) Addendum A bit more compact is ...


3

There are many possibilities. You could do something like sols = Flatten@Module[{i=1}, Solve[s^2 + a*s + b == 0, s] /. s :> s[i++]]; (* {s[1] -> 1/2 (-a - Sqrt[a^2 - 4 b]), s[2] -> 1/2 (-a + Sqrt[a^2 - 4 b])} *) Alternatively, sols = Solve[s^2 + a*s + b == 0, s]; exprs = {c1 Exp[s t], c2 Exp[s t]}; Plus @@ MapThread[#1 /. #2 &, {exprs, ...


4

There are two problems in your code : v1[t_] should be replaced by v1[t_?NumericQ] . The idea is to prevent NDSolve[..v1[t]...]to ask what is v1[t] with t purely symbolic. See for example this link. Your system of equation contains equalities between variables without derivatives and thus is interpreted as a Differential-Algebric system. Mathematica ...


6

h[t_?NumericQ] := signal[[Floor[100*t + 1]]]; sol = NDSolveValue[{components, connections, ic, WhenEvent[Mod[t, 1/100]*100 - h[t] == 0, v1[t] -> Unitize[v1[t] - 1]]} /. params, {vC, v1}, {t, 0.0, 0.2}, DiscreteVariables -> {v1}]; Plot[Through[sol[t]], {t, 0, .2}, Evaluated -> True] The above solution seems correct,but it ...


3

Partial derivatives should work on interpolation functions just fine, and I cannot see why your interpolating function should be any different. But it is. Here is a ridiculous workaround ufem2 = Interpolation[ Flatten[Table[{{x, t}, ufem[x, t]}, {x, 0, 10, .1}, {t, 0, 1, .02}], 1]]; loc2 = Derivative[1, 0][ufem2]; Plot[{ufem[x, .2], loc2[x, ...


4

The $\theta(t-\Delta)$ makes it a Delay Differential Equation, which the documentation here shows how to solve. You have to specify a history function like this: u[t /; t <= 0] == f[t] For example: NDSolve[{u''[t] + u[t - 1] == 0, u[t /; t <= 0] == 1}, u, {t, 0, 10}] Plot[u[t] /. First[%], {t, 0, 10}]


1

To solve the differential equation,there should be a initial condition. After solving the differential eq find the derivarive and then use plot. For an example I have taken here $y(0)=4, a=2, d=5$ In[1]:= y[a_, d_, c_] := DSolve[{y'[x] + a*y[x] == d, y[0] == c}, y[x], x] In[13]:= y[2, 5, 4] Out[13]= {{y[x] -> 1/2 E^(-2 x) (3 + 5 E^(2 x))}} ...


5

c = 0.01333 // Rationalize; Ang[x_] = -I Log[-Exp[I x]]/2; y[x_, t_] = FullSimplify[ DSolveValue[{ u''[t] + (4 (c t - Cos[x])^2 + 4 Sin[x]^2 + I 2 c) u[t] == 0, u'[0] == I 2 Cos[x] Cos[Ang[x]] - I 2 Sin[x] Sin[Ang[x]], u[0] == Cos[Ang[x]]}, u[t], t], {Element[t, Reals], -Pi <= x <= Pi}]; The above definition is in terms of ...


8

As march predicted in a comment above, the noise in the plots is a precision issue. A small improvement can be obtained by setting c to a rational number, c = 4/300 and applying FullSimplify to y[x, t]. before plotting. Nonetheless, even at t = 0, the solution is quite noisy. To illustrate, compare the initial condition on u with y[x, 0]. p0 = ...


7

Depending on your use-case, there are different possibilities. I typically think of operators as taking functions to functions, rather than functions to values, so I will define the operators as taking the functions u and w to pure functions, and you can attach variables after the fact. Here's one possibility: ClearAll[L22, L11, u, w] L11[u_] := D[u[##], ...


3

Because something is wrong with the boundary at $x=0$. Let's solve the equation with DSolve. Since DSolve has trouble in dealing with f[0] == 1, we first use a more general b.c. f[a] == b: eq = f''[r] + r^-1 f'[r] - r^-2 f[r] + (1 - r^2) f[r] == 0 {generalasol} = f[r] /. DSolve[{eq, f[a] == b, f[1] == 1}, f[r], {r}]; and take the limit: asol = ...


2

The problem here is that your equation has terms singular at r=0, while you fix one of the boundary conditions exactly in this point. The workaround may be in shifting the first boundary condition a bit out of this point: ClearAll[r]; eq = f''[r] + f'[r]/r - f[r]/r^2 + (1 - r^2) f[r] == 0; nds = NDSolve[{eq, f[0.1] == 1, f[1] == 1}, f[r], {r, 0, 1}] // ...


1

I don't know what value of k you are using, so in the code below I set it to 0.1. Also, fixed the RK4 code so that it works, but now it's pretty slow. (* set k to your value for k *) k = .1; f[y_, mu_] := -1/(1 + Exp[(Abs[y] - mu)/k]) + 1; mu[n_] := mu[n] = 0.5 + 0.1 Sign[y[n] - y[n - 1]]; x[0] = 0.0; y[0] = 0; y[1] = 0.1; x[n] = 2; h = .01; x[n_] := x[n] ...


1

First, define the equation and take LaplaceTransform, implementing the initial condition along the way: eqn = D[T[x, t], t] - D[T[x, t], {x, 2}] == 0 LaplaceTransform[eqn, t, s] /. T[x, 0] -> Sin[π x] In the second term, we actually can interchange the order of integration and differentiation to see that it's just D[LaplaceTransform[T[x, t], t, s], ...


1

With your new f[x], I made the event Mod[t,1], with the action to compare the current state against the previous one saved in xxold and yold. f[x_] := 0.1 + 0.05*Sin[2*Pi*(x + 1/3)]; xxold = yold = 0; tmax = 200; ressol = NDSolve[{xx'[t] == 0.2*xx[t]*y[t] - f[t]*xx[t], y'[t] == (1 - y[t]) - 0.5*xx[t]*y[t], xx[0] == 0.5, y[0] == 0.5}, {xx, y}, {t, ...



Top 50 recent answers are included