Tag Info

Hot answers tagged

18

Usage: dChange[expresion, {transformations}, {oldVars}, {newVars}, {functions}] You can also skip {} if a list has only one element. (Update) Examples: 0. wave equation in retarded/advanced coordinates dChange[ D[u[x, t], {t, 2}] == c^2 D[u[x, t], {x, 2}], {a == x + c t, r == x - c t}, {x, t}, {a, r}, {u[x, t]} ] c Derivative[1, 1][u][a, r] == ...


8

At a simple algebraic calculus level, one could do this: exactQ[{P_, Q_}, {x_, y_}] := D[P, y] == D[Q, x] // Simplify; exactQ[{P_, Q_, R_}, vars_] := Curl[{P, Q, R}, vars] == {0, 0, 0} // Simplify; exactSolve[vf_, vars_] /; exactQ[vf, vars] := Fold[#1 + Integrate[#2[[1]] - D[#1, #2[[2]]], #2[[2]]] &, 0, Transpose[{vf, vars}]] Example: p = Exp[x] ...


7

To verify that matrix is a zero of its characteristic polynomial, The Characteristic polynomial of the matrix is found, then evaluated for the matrix. The result should be the zero matrix. Clear[x] a = {{-1, -4, -2}, {0, 1, 1}, {-6, -12, 2}}; n = Length[a]; p = CharacteristicPolynomial[a, x]; (Sum[ Coefficient[p, x, i] MatrixPower[a, i], {i, 0, Exponent[p, ...


7

I began this thinking of adding a comment to the answer by bbgodfrey, who points out mathematical fixes to the OP's problem. But each idea led to another test and another idea. Aside from the unceremonious crashing of the kernel, there is more evidence below of a bug or bugs in the parsing of the equations. The fix by bbgodfrey works, it seems, because it ...


6

It appears that NDSolveValue is failing, because too few boundary conditions have been specified. For instance, with a boundary condition at x = 1 and a second boundary condition at t = 0 specified as follows, ans = NDSolveValue[ {-Derivative[0, 2][Φ][x, t] + Derivative[2, 0][Φ][x, t] == Sin[Φ[x, t]], Φ[x, 0] == 0, Derivative[0, 1][Φ][x, 0] ...


6

Since there is no spatially or temporally varying potential energy term in the differential equation, it's not efficient to apply NDSolve with the method of lines. The Dirichlet boundary conditions are in principle also inconsistent with the Gaussian initial condition, so one should choose an initial condition that is forced to be zero at the boundary. The ...


5

NDSolve is smart enough to handle the denominator going to zero. However, it can't integrate past the discontinuity. Instead, let's tell it to stop when x == 0 with a WhenEvent: DynamicModule[{z, tfinal = 0}, Manipulate[ z = NDSolveValue[{x'[t] == -b x[t]/Sqrt[x[t]^2 + y[t]^2], y'[t] == a - b y[t]/Sqrt[x[t]^2 + y[t]^2], x[0] == c, y[0] == 0, ...


5

We can solve (approximately) for the initial conditions of solutions that approach an equilbrium by comparing the displacement vector from the equilibrium with the vector field of the ODE. Such trajectory is characterized by the condition that these two vectors become parallel as the solution nears the equilibrium. I used a similar idea before, which is ...


4

You can use "MaxBoundaryCellMeasure" for that: L = 10; a = 1; k = 1/2; mesh = 0.06; BoxL = x == L || x == -L || y == L || y == -L; reg = ImplicitRegion[(-L <= x <= L && -L <= y <= L) && (x^2 + y^2 >= a^2), {x, y}]; bcθ = {DirichletCondition[u[x, y] == ArcTan[x, y] k, x^2 + y^2 == a^2], DirichletCondition[u[x, y] == 0, ...


4

Something like this? Make the rhs a "black box" so it does not show explicit dimenions. Use it in NDSolve. f[vals : {_?NumberQ ..}] := {vals[[1]]^2*vals[[2]], -vals[[1]]* vals[[2]]^2} vsoln = NDSolveValue[{x'[t] == f[x[t]], x[0] == {1, 1}}, x[t], {t, 0, 1}] (* Out[275]= InterpolatingFunction[{{0., 1.}}, <>][t] *) Obviously that black box ...


4

This is a very simple way to do it. I modified your code very little to add the condition, that is inside a hole, then set the solution to be the boundary condition at the edge of the hole inside, which I set to be zero. Added one line: startRow = 4; endRow = 6; startCol = 4; endCol = 6; Which tells the boundaries of the hole. And inside the Table ...


4

Mathematica can also solve this differential equation if you help it with the choice of variable substitution: Clear[y,λ,x,z,u,v] eqn = y''[x] == λ y[x]/Sqrt[-1 + x] (* ==> (y^\[Prime]\[Prime])[x] == (λ y[x])/Sqrt[-1 + x] *) u[x_] := Sqrt[x - 1] y[x_] := z[u[x]] eqn2 = Simplify[eqn /. x -> InverseFunction[u][v], v > 0] (* ==> 4 v^2 λ z[v] + ...


4

Mathematica actually has a function purpose-built for the operation you're looking for. MatrixFunction[f, m] gives the matrix generated by the scalar function f at the matrix argument m. In your case, MatrixFunction[p, A] will return the 3-by-3 zero matrix, as desired.


4

The typical solution of such expressions proceeds as in the following example. Suppose f[x, y] = Exp[x^2 + y^2] Cos[x + y] + x + y^3 (* x + y^3 + E^(x^2 + y^2)*Cos[x + y] *) From these we construct p and q. p[x, y] = D[f[x, y], x] (* 1 + 2*E^(x^2 + y^2)*x*Cos[x + y] - E^(x^2 + y^2)*Sin[x + y] *) q[x, y] = D[f[x, y], y] (* 3*y^2 + 2*E^(x^2 + ...


4

You should not wrap a Manipulate expression with Module. Read the comments to this question to learn why. You can fix your problem by clearing r and making a definition of r[t] in the initialization section of your Manipulate expression. Like so: r = 42; Manipulate[ Show[ ParametricPlot[r[t], {t, 0, 80}, PlotRange -> {{0, 140}, {0, 100}}], ...


4

I ve modified slightly your problem to one which works: I used exact numbers w = 2; T = 2 Pi/w; a = 4/10; b = 4; d = 3/10; A = T {{0, 1}, {-a - b Cos[2 t], -d}} I then drop the Initial condition on derivatives which are redundant given the order of your equation: sol = NDSolve[{x'[t] == A.x[t], x[0] == {1, 2}},x[t] , {t, 0, 1}] then I plot the ...


4

Here's a workaround. I'm not sure why the variables s1[t], s2[t] are not reset in my first answer (see edit history). We can take care of things manually by making s1 and s2 numerical functions. Block[{ti = Log@100, tf = Log@(10^9), a0 = 3.05917*^7, b0 = 3.05242*^7, s1, s2, s10 = 1, s20 = 1}, s1[t_?NumericQ] := s10; s2[t_?NumericQ] := s20; {{sol}, ...


4

This is a long comment that answers the question, What is the problem? I don't have an answer to the question, What is the fix?, at this point. The problem is, I believe, condition 1. I'm afraid my background in PDEs is weak, but numerically, using the method of lines (the default in this case), condition 1 is not integrated. Basically, the initial value ...


4

What the OP is trying to code is already in Mathematica in the form of ParametricNDSolveValue. myodessystem = ParametricNDSolveValue[{y'[x] == k1 y[x] Cos[k2 x + y[x]], y[0] == 1}, y, {x, 0, time}, {k1, k2, time}] (* ParametricFunction[<>] *) mysolve = myodessystem[1, 1, 30]; mysolve[1] (* 0.991387 *)


4

Correct sin/cos to Sin/Cos. Define your functions properly: w1[y_] :=.... Then put your conditions to Solve and done. w1[y_] := (E^(β*y))*(A1*Cos[β*y] + A2*Sin[β*y]) + (E^(-β*y))*(A3*Cos[β*y] + A4*Sin[β*y]); w2[y_] := (E^(-β*y))*(A5*Cos[β*y] + A6*Sin[β*y]); vars = Symbol["A" <> ToString[#]] & /@ Range[6] {A1, A2, A3, A4, A5, A6} ...


3

The problem of treating a system of ODEs in vector form can be solved defining a vector equality operator thus vEq[a_, b_] := Equal @@@ Transpose[{a, b}] where a and b must be vectors (lists) of equal length. Its action is vEq[Array[a, 3], Array[b, 3]] (* Out[232]= {a[1] == b[1], a[2] == b[2], a[3] == b[3]} *) Now we use this function in the ODE ...


3

You are trying to solve a set of Ordinary differential equation but you forgot to set up initial conditions. This is just to get you started. Your equation eqn = { x1'[t] == x2[t], x2'[t] == -4*y2[t]*y1[t]^2 + (2*x2[t]*y2[t])/ y1[t] - (y2[t]^2*y1[t]^2)/x1[t]^3, y1'[t] == y2[t], y2'[t] == 4*x2[t]*x1[t]^2 + (2*y2[t]*x2[t])/x1[t] - ...


3

After correcting the typo in the argument to sol ({x0_, y_ 0} to {x0_, y0_}), I cannot reproduce your problem: $Version "10.1.0 for Mac OS X x86 (64-bit) (March 24, 2015)" f[x_, y_] = 1 - y; g[x_, y_] = x^2 - y^2; sol[{x0_, y0_}] := NDSolveValue[{x'[t] == f[x[t], y[t]], y'[t] == g[x[t], y[t]], x[0] == x0, y[0] == y0}, {x[t], y[t]}, {t, 0, 15}] ...


3

Note change at end of your function... you might also want to add checks to ensure that there was a solution so as not to return a nonsense function. myodessystem[k1_, k2_, time_] := Module[{odes, y, x, sol, myfun}, odes = {y'[x] == k1 y[x] Cos[k2 x + y[x]], y[0] == 1}; sol = NDSolve[odes, y, {x, 0, time}]; myfun = First[y /. sol]]; mysolve = ...


3

I just wanted to point out that all the routes above will work if there is only one differential equation: data = NDSolveValue[{ x''[t] - k1*(1 - x[t]^2)*x'[t] + k2*x[t] == 0, x[0] == 2, x'[0] == 0} /. {k1 -> 1., k2 -> 1.}, Table[{t, x[t] + RandomReal[{-.3, .3}]}, {t, 0, 10, .2}], {t, 10}]; dataT = data\[Transpose]; ti = dataT[[1, ...


2

This bug is fixed in Mathematica 10.1.0. (Mac OS X 10.10.3) DSolve[(x^2 + y^2) D[u[x, y], x] + 5 x y D[u[x, y], y] == 0, u[x, y], {x, y}]// AbsoluteTiming Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. >> {0.086166,{{u[x, y] -> C[1][Log[-((4 x^2 - ...


2

If you evaluate: Laplacian[u[r],{r,phi},"Polar"]/.r->0 Power::infy: "Infinite expression 1/0 encountered." You can use: if = NDSolveValue[{Laplacian[u[r], {r, phi}, "Polar"] == r^2, DirichletCondition[u[r] == 0, r == 1]}, u, {r, 10^-6, 1}, Method -> "FiniteElement"]; Plot[if[r], {r, 10^-6, 1}] To get: Here is a different way to do ...


2

As mentioned by Albert Retey in the comment above, you can't expect that NDSolve makes use of your parallel kernels, period. However, since your equation set is just a system of 1st order linear ODEs, you can turn to MatrixExp, which seems to parallelize automatically: coe = gamma - DiagonalMatrix@Total@gamma; init = ConstantArray[0., 816]; init[[-2]] = ...


2

I might approach it like this. First I like to use the replacement Rule form of NDSolve. Since the solution is used as a vector, it makes sense to have NDSolve return the vector solution r. Using With to inject the solution removes the dependence of the Manipulate on an external symbol. Then sol can be reused without affecting this Manipulate. For ...


2

Perhaps this: inhom = Plus @@ Table[a[i] Exp[b[i] x], {i, 1, 100}]; eq[inhom_] := {u''[x] + u[x] + inhom == 0, u[0] == 0, u[1] == 0}; sol = u -> ParallelMap[DSolveValue[eq[#], u[x], x] &, inhom] (* u -> -(1/(1 + b[1]^2)) a[1] (-Cos[x] + E^(x b[1]) Cos[x]^2 + Cot[1] Sin[x] - E^b[1] Cos[1] Cot[1] Sin[x] - E^b[1] Sin[1] Sin[x] + ...



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