Tag Info

New answers tagged

0

If we think about it, step-wise solvers will start by solving for the highest order derivative, and start integrating from the initial conditions. You can check this with Mathematica. Try solving for the second derivatives and sticking in the initial conditions. Solve[{diffeqs, {Subscript[θ, 1]''[t], Subscript[θ, 2]''[t]}] /. {Subscript[θ, 1][t] -> 0, ...


1

For what it's worth, using the same substitution as Chip Hurst in his Apr 22 answer, and after some coaxing, I got to this solution: solx = Function[x, 1/(4 Sqrt[ m^2]) (2 C[1] (1 + 2 Sqrt[m^2] Cos[x]) Cot[x/2]^(-2 Sqrt[m^2]) - ( 2 C[2] (Sqrt[m^2] - 2 m^2 Cos[x]) Cot[x/2]^(2 Sqrt[m^2]))/(-1 + 4 m^2) + ((m^2)^( 3/2) (1 + 2 m Cos[x] + ...


1

Not sure if this is what you're after. The following is the steady state supposing null divergences except at the source: g = DirectedGraph[CompleteGraph[5], "Acyclic", VertexLabels -> "Name"] in[n_] := Tr[v[#]/VertexOutDegree[g, #] & /@ Complement[VertexInComponent[g, n, 1], {n}]] Solve[Join[{v[1] == 1}, Table[v[n] == in[n], {n, 2, ...


2

I think I have solved this ODE (I didn't verify the solution). The problem with DSolve is Integrate was not terminating for this inhomogeneous equation. So what I did was solve the homogeneous equation, then applied variation of parameters described here: homode = -16c*m^2Cos[x]k[x] - c(Sin[3x] - 7Sin[x])k'[x] + 4c*Cos[x]Sin[x]^2k''[x] == 0; homsol = ...


4

NDSolve and now, in V10, DSolve, too, can handle differential equations with discontinuous coefficients. The coefficients have to be in terms of functions that will be recognized as discontinuous. Procedural programs such as in the definition of eqilValue above will not be recongnized and will be treated as numerical black boxes. Piecewise will be ...


3

I believe it's better to cope with discontinuous functions in NDSolse[] by using WhenEvent[] and DiscreteVariables ->. In your case: tauArr = {50, 100, 150, 200, 250}; whens = WhenEvent @@@ MapIndexed[{t == #1, ep[t] -> If[#2 == {5}, -5, #2[[1]]]} &, tauArr] sol = NDSolve[{f''[t] + gamma*f'[t] + kappa*(f[t] - ep[t]) == 0, whens, ...


1

Just for illustrative purposes: exp = x^4 + 2 x^3 + 3 x^2 + 4 x; Coefficient[exp, x, #] & /@ Range[0, 4] CoefficientList[exp, x] CoefficientRules[exp] yields: {0, 4, 3, 2, 1},{0, 4, 3, 2, 1}, {{4} -> 1, {3} -> 2, {2} -> 3, {1} -> 4} respectively You need to Print if you use Do to get output of evaluation, or use Table, or Map as above. There are many ...


7

Easier by using ParametricNDSolve[]: params = {γ, a, b}; model = x /. ParametricNDSolve[{x''[t] + γ x'[t] + a x[t] + b x[t]^3 == 0, x[0] == 2, x'[0] == 0}, x, {t, 0, 20}, params]; fit = FindFit[data, model[Sequence @@ params][x], params, x, PrecisionGoal -> 4, AccuracyGoal -> 4] (* {γ -> 0.339787, a -> ...


2

How do I plot the derivatives of the solution You can simply tell NDSolve to also solve for the derivative: sol = First@NDSolve[{x''[t] + x'[t] + 10 Sin[x[t]] == 3, x[0] == 0, x'[0] == 1}, {x[t], x'[t]}, {t, 0, 20}]; Plot[{x[t] /. sol, x'[t] /. sol}, {t, 0, 20}, PlotStyle -> {Red, Blue}, PlotRange -> All, Frame -> True, PlotLegends ...


1

There are several little issues that conspire to trip up your code here and there. Let me just point out a couple of the major things to think about. First, keep clearly in mind the difference between a function f and the expression f[t]. I know from teaching mathematics that these tend to get conflated in ordinary conversation, but you cannot get away ...


1

As stated on the Evaluate help page (Possible Issues section): Evaluate works only on the first level, directly inside a held function: Your first version -when used with Hold- looks like this: Evaluate[#[t] /. sol] & /@ vec // Hold // FullForm Hold[Map[Function[Evaluate[ReplaceAll[Slot[1][t],sol]]],vec]] The second function: ...


1

This is a bit subtle. I assume that your sol is something like sol={{x->3}} Evaluate is used to overrule an Hold attribute (not for evaluating expressions). The command Function has attribute HoldAll. So in your first situation you map Function[ Evaluate[#[t] /. sol]] (* {#1[t]}& *) In the second situation, Evaluate is in a Times expression, ...


0

I would say that you misread the documentation for NeumannValue. I found the documentation fairly difficult to fathom. This was mainly my fault because what they do is substantially different than what I expected. I was trying to cram the round peg that is NeumannValue into the square hole that is my brain. If you can write the PDE as Div J = 0 (the ...


6

As mentioned in the comment above, handling irregular region with FDM is cumbersome and frustrating in my view, actually that's where I stopped my self-learning of FDM and turned to finite element method (FEM), which is more suitable for this task, and finally write this. (Have a look at this post for more information. ) Nevertheless, there seems to be no ...


2

Mathematica finds the general solution for any u[x] simply by using DSolve: sol = DSolve[{y''[x] + a*y[x] == -b*u[x], y[0] == 0, y'[0] == 0}, y[x], x]; yy[x_] = y[x] /. First[sol] /. {K[1] -> t, K[2] -> t} $-\text{Cos}\left[\sqrt{a} x\right] \int_1^0 \frac{b \text{Sin}\left[\sqrt{a} t\right] u[t]}{\sqrt{a}} \, dt+\text{Cos}\left[\sqrt{a} x\right] ...


4

Remove {t, 0, 2 Pi} from your SpC1 to get a 3D parametrized line SpC1b = ParametricPlot3D[{r[th] Cos[th], z[th], r[th] Sin[th]}, {th, 0, thmax}, PlotStyle -> {Thick, Magenta}, PlotLabel -> "SPACE_CURVE"]; Show[SpC1b, SpC2] Or, to get fancier, Show[SpC1b /. {Magenta -> Orange, Line -> (Tube[#, .1] &)}, SpC2 /. Line -> ...


2

I´m not quite sure whether I understood your problem right, but I increased the Mesh, set the PlotPoints higher (I just choose a higher number) and MaxRecursion to 1, i.e.: SpC1 = ParametricPlot3D[{r[th] Cos[th], z[th], r[th] Sin[th]}, {t, 0, 2 Pi}, {th, 0, thmax}, PlotStyle -> {Thick, Magenta}, PlotLabel -> SPACE_CURVE, Mesh -> 100, ...


3

However, evaluating gf does not seem to work When Mathematica returns DifferentialRoot as solution to a differential equation, it really means M could not solve the ODE. This is not the necessarily the case with DifferenceRoot as you found out (I do not know much about DifferenceRoot, but I've seen DifferentialRoot before many times). Here is an ...


2

Using Method->"ExplicitRungeKutta" with a larger value of the option "DifferenceOrder" allows recovering more terms of the series expansion.


1

This question really belongs on physics.stackexchange.com. You can post your propagation equations there using TeX. TeXForm[] will do the conversion for you if you don't know TeX. For a 2-D case around a non-rotating spherical planet as you appear to be attempting, I use these propagation equations with NDSolve[]: {v'[t]==-Sin[\[Gamma][t]] ...


0

r = ParametricNDSolve[{eq, c[0] == 0}, c, {t, 0, 25}, w]; Plot[Flatten[{Re@#, Im@#} &[Table[c[w][t] /. r, {w, 1, 4}]]], {t, 0, 25}, Evaluated -> True]


1

a = 1; d = 0.13; s = 0.4; f = .1; eq = c'[t] + I a (Abs[c[t]])^2 c[t] + d (Abs[c[t]])^2 c[t] - s (Abs[c[t]])^2 c[t] - f Exp[-I w t] == 0; r = ParametricNDSolve[{eq, c[0] == 0}, c, {t, 0, 25}, {w}]; Plot[Table[Through@{Re, Im}@c[w][t] /. r, {w, 1, 10, .1}], {t, 0, 25}, Evaluated -> True] Update: various views pre0 = Plot[Table[Re@c[w][t] /. r, ...


1

This is just an extended comment. If you use (Full)Simplify there is no long string of terms even with b[n,x] being evaluated. Clear[a, b] b[n_, x_] = (x^n/n!)/Sum[x^k/k!, {k, n, Infinity}] // FullSimplify Limit[x^2 D[b[n, x], {x, 2}] + (3 x^2 + (1 - 3 n) x) D[b[n, x], x] + (2 x^2 + (1 - 4 n) x + 2 n^2) b[n, x], x -> 0] 2*n^2 a[n_, x_] ...


2

The problem is that the definition of b is being substituted (and some of the factorials are being converted to Gamma). You need to keep b from being evaluated. Without knowing how you wish to use the result, here is a possibility: a[n_, x_] := Inactivate[ x^2*D[D[b[n, x], x], x] + (3 x^2 + (1 - 3 n) x) * D[b[n, x], x] + (2 x^2 + (1 - 4 n) x + 2 ...


2

I can only imagine doing this with two controlling events, one to turn the system off (and reset) and one to turn the system back on. I made up a simple example, which I hope you can adapt to whatever your code is. The basic idea of the example is a harmonic oscillator system which can have damping turned on or off and which will reset when the energy ...


0

Ok dude, if you want to get convergence on this type of stiffness you need a "more well posed problem", you can't have too much pendulus and little friction at the same time,for avoid confusion this is just a numerical issue. In other words if you want more Pendulos take there biggers! The problem converge on n=4 if r=10.. I personally think this is a ...


2

From the docs, solConstraint2[x0_, p0_, m_, ω_, time_] := NDSolve[{x'[t] == p[t]/m, p'[t] == -m ω^2 x[t], x[0] == x0, p[0] == p0}, {x, p}, {t, 0, time}, Method -> {"TimeIntegration" -> {"Projection", "Invariants" -> energy[x[t], p[t], m, ω]}}] This keeps the energy to within about 0.12 of its starting value. Not great, but it does not ...


3

I do not know offhand what is a good way to recast as a DAE. One way to enforce the algebraic constraint, without getting an overdetermined (albeit consistent) system, is to use the projection method. I cribbed some of the submethod settings from advanced documentation in tutorial/NDSolveProjection. sol2[x0_, p0_, m_, ω_, time_] := NDSolve[{x'[t] == ...


1

Try this: eq = -n*b[x]^2 == (x - n)*b[x] + x*b'[x]; DSolve[eq, b[x], x] The result is here: {{b[x] -> (E^-x x^n)/(C[1] - n Gamma[n, x])}} Here C[1] is the arbitrary constant. Have fun!


6

I'm not sure why DSolve fails, but the differential equation can be solved in the usual way of separating the variables.* So t will be equal to solt = Integrate[1/(LL^(-3/2) - 1/10), {LL, 10, L}, Assumptions -> 10^(2/3) < L < 10]; (* complicated output omitted - see below *) We can use InverseFunction to get L in terms of t: solL = L -> ...


2

In addition to Stephen Luttrell's proposal your example can be treated as follows. Letting z = y-t the system becomes x' = 2 x - 3 z z' = 5x + z + 1 which is independent of t, and we can do the StreamPlot StreamPlot[{2 x - 3 z, 5 x + z + 1}, {x, -3, 3}, {z, -3, 3}] (* 141102_streamplot.jpg *) Regards, Wolfgang


2

There are two syntax flaws that I see; one of which should have been addressed by your previous question. First, in this line eqn[i, F] = p[i]'[t] == (i + 1) t p[i][t]; I suspect you intend i and F to be variables. But, as it is, you are making a definition for eqn[i, F], verbatim. To make them amenable to substitution, you need to use patterns, e.g. ...


0

eqn[i_] := p[i]'[t] == (i + 1) t p[i][t]; (**) system = Table[eqn[i], {i, 0, 4}]; initialvalues = {1, 2, 3, 4, 5}; initialcondition = Table[p[i][0] == initialvalues[[i + 1]], {i, 0, 4}]; (**) funcs = Table[p[i], {i, 0, 4}]; sol = NDSolve[{system, initialcondition}, funcs, {t, 0, 2}] You should take your time to learn the basic syntax


1

I'm not clear on all the details of your problem, but here is a general setup: system = Table[node[i, F], {i, 0, F}]; (* equations *) initialvalues = {p0, p1, ... (* fill in as appropriate with actual numbers *)}; initialcondition = Table[p[i][0] == initialvalues[[i+1]], {i, 0, F}]; funcs = Table[p[i], {i, 0, F}]; (* functions to solve for *) sol = ...


1

As b.gatessucks suggested you can use ParametricNDSolve, here is my attempt: sol = ParametricNDSolve[{y'[x] == A* y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}, {A}] Integrate[Evaluate[Table[y[x][A] /. sol, {x, 0, 30, 1}]], {A, 1, 10}] I obtained: {9., 2.45807, 1.26895, 0.899877, 0.722946, 0.61851, 0.549178,0.504711, 0.473531, 0.454667, 0.335436, ...


2

Although replacng Module with Block can deal with this problem, it is fussy and inconvenient. As @J. W. Perry said, the built-in Mathematica function InterpolatingPolynomial OP's solution polyInterpolation[tb_, tf_, θb_, θf_, θbDot1_, θfDot1_, θbDot2_, θfDot2_] := Block[ {InterpolationResult, u, θ, θDot1, θDot2, c0, c1, c2, c3, c4, c5, ...


0

Just for fun and using DynamicModule and only looking at integer exponents: DynamicModule[{p}, Framed[Column[{ Dynamic[With[{h = p}, sol = First@Quiet[ DSolve[{y'[x] == y[x]^h, y[0] == 1}, y[x], {x, 0, 2}]]; Plot[y[x] /. sol, {x, 0, 2}, Evaluated -> True, PlotStyle -> Red, Epilog -> Text[Style[y[x] ...


2

Manipulate[ Plot[y[x] /. sol[n], {x, 0, 2}, Evaluated -> True], {n, 0, 4}, Initialization -> {sol[h_] := Quiet@NDSolve[{y'[x] == y[x]^h, y[0] == 1}, y[x], {x, 0, 2}]}]



Top 50 recent answers are included