Tag Info

New answers tagged

2

The code as written contains a syntax error. Additionally, there is no need to used SetDelayed. Finally, the calculation needs to begin slightly beyond u == 1. With these changes and NDSolveValue used for convenience, M = 1; m = 1; p = 2; q = 1; Q = √3 ; d = 3; L = 1; k = 1; ω = 1; f[u] = 1 - M u^(-d); vneg[u] = (1/√f[u]) (ω + Q q (1 - u^(2 - d))) - Q p ...


2

A = 3; p = 2; B = 4; sol = NDSolve[{ D[v1[x, t], t] + 1/2 D[v1[x, t]^2, x] == (A + p B)*v2[x, t] - p B v1[x, t], D[v2[x, t], t] + 1/2 D[v2[x, t]^2, x] == (A + p B)*v1[x, t] - p B v2[x, t], v1[x, 0] == 2, v2[x, 0] == 2, v1[0, t] == 2, v2[0, t] == 2 }, {v1, v2}, {x, 0, 5}, {t, 0, 60}]; Plot[Evaluate[v1[2, t] /. sol], {t, 0, 60}, PlotRange -> ...


1

Your problem is the fact that the lines in your list of lines are not contiguous, or in other words the points in your fldd list generated from the lines variable are not each other's nearest neighbors. Another issue may be the nested For loops. If you find yourself using procedural constructs such as looping constructs, you might want to rethink your ...


4

The second curve is irregular, because the s42 calculation yields the desired second solution for some values of λ and the first solution for others. To obtain only the desired second solution, use s42 = Table[{λ, f''[0] /. NDSolve[{equations, initialconditions /. {λ1 -> -0.5, η -> 20, s -> 4}}, {f'', g', θ}, {t, 0, 20}, Method -> ...


4

As promised: And here are the nodes: Now to outline the process. [This first part has no Mathematica.] First, I found an image of a guitar using Google's Image Search. I then went into GIMP (although you can use any image editing software, or even draw the image yourself) and used it as a template to create a silhouette (it's okay if the edges are a ...


2

sol = DSolve[x'[t] == -x[t], x[t], t]; f = x[t] /. sol[[1]] /. C[1] -> x1; p1 = ContourPlot[ Evaluate[Table[x == f, {x1, {-.1, .1, 1, -1}}]], {t, -5, 5}, {x, -2, 2}]; points = Join @@ (Table[{i, j}, {i, -5, 5}, {j, -2, 2, .5}]); line = Rotate[{Gray, Line[{# - {.3, 0}, # + {.3, 0}}]}, ArcTan[-#[[2]]]] & /@ points; p2 = Graphics[{line, ...


1

I used the answer here and set the independent variable t as first argument. It looks now close to your book f[t_, x_] := -x StreamPlot[{1, f[t, x]}, {t, -2, 2}, {x, -.5, .5}, Frame -> False, Axes -> True, AspectRatio -> 1/GoldenRatio]


0

Apparently a syntax error: I assume by t you meant x in the Sin and exponential. The exponential constant e in Mathematica is E not e. The error you are getting is mainly because during the evaluation of the NDSolve equations, Mathematica ends up with t and e, which at this stage are undefined symbols, hence it is not a numerical expression and ...


0

The OP still left out a definition (WL), but the problem is that Integrate generates a ConditionalExpression, on which NDSolve chokes. 2*I*Integrate[Exp[-y^2.0 + 2.0*I*y*x], {y, 0, Infinity}] (* ConditionalExpression[ 2 I E^(-1. x^2) (0.886227 + (0. + 0.886227 I) Erfi[(1. + 0. I) x]), ((0. - 2. I) x ∈ Reals && Re[(0. + 2. I) ...


2

I think you just have to rewrite your "r" equations. I took your code: Te[ϕ_] := 2200 + 440*Cos[ϕ] Ra[ϕ_] := 2 + 0.25*Cos[ϕ + π] t[r_, ϕ_] := Te[ϕ]*(1 - Sqrt[1 - (Ra[ϕ]/r)^2])^(1/4) k1[r_, ϕ_] := (6.99*10^-14)*((t[r, ϕ]/300)^2.8)* Exp[-1950/t[r, ϕ]] k2[r_, ϕ_] := (1.59*10^-11)*((t[r, ϕ]/300)^1.2)* Exp[-9610/t[r, ϕ]] k17[r_, ϕ_] := ...


0

I believe you've mistyped the differential equation as well by using u'[t] instead of u[t]. It should probably be: In which case you get an answer which should match your book: de4 = {u''[t] + u[t] == .5 Cos[.8 t], u[0] == 0, u'[0] == 0} soln5 = Simplify[DSolve[de4, u[t], t]] Plot[u[t] /. soln5, {t, 0, 60}, PlotRange -> {-3, 3}] The solution ...


0

First of all, you should not use 0.5 and 0.8 when you are looking for an analytic solution. Then, when you use u[t] in your equation, why do you use y[t] in the plot? This will never work and you could have found out by replacing Plot with e.g. blot which is an undefined function plot[Evaluate[y[t] /. solution5], {t, 0, 60}, PlotRange -> {-2, 2}] (* ...


1

This worked for me. I hope it helps. I used ParametricNDSolveValue k1 = 20; k2 = 200; k3 = 0.03; tmax = 2000; ode = {S'[t] == -k1 Eu[t] S[t] + k2 ES[t], Eu'[t] == -k1 Eu[t] S[t] + k6 EP[t] + k2 ES[t], ES'[t] == k1 Eu[t] S[t] - (k2 + k3) ES[t], EP'[t] == k3 ES[t] - (k4 + k5 + k6) EP[t], Ec'[t] == k4 EP[t], P'[t] == k6 EP[t], S[0] == 100, ...


1

Without understanding what is happening conceptually, I'm afraid that Mathematica probably won't help you much. You have a 2-by-2 system of differential equations, which I would recommend researching in general. However, I like using Mathematica to visualize what is happening in a system, so here's some code! k1 = 0.5; k2 = 2; n = 10; StreamPlot[{.5/(1 + ...


2

You could try something like this (but this question is likely to be closed because it has been asked 10 000 times) eqn1 = D[A[t], t] == 1/2/(1 + (B[t]/k1)^n) - 2/10 A[t] eqn2 = D[B[t], t] == 1/(1 + (A[t]/k2)^n) - 2 B[t] You can then solve for A[t],B[t] sol=NDSolveValue[{eqn1, eqn2, A[0] == 0, B[0] == 0} /. {n -> 10, k1 -> 1/2, k2 -> 2}, ...


3

Just another way: rk[fun_, {x_, y_}, h_] := {x + h, y + FoldList[fun[x + #2, y + #2 #1] &, fun[x, y], {h/2, h/2, h}].{1, 2, 2, 1} h/6} Testing (as per Shutao Tang): g[x_, y_] := y x^2 - 1.2 y Grid[Prepend[ Thread[Prepend[Transpose[NestList[rk[g, #, 0.1] &, {0, 1}, 10]], Range[0, 10]]], {"n", "\!\(\*SubscriptBox[\(x\), \(n\)]\)", ...


3

The Formula Implementation rungeKuttaOrderFour[{xn_, yn_}, step_, func_] := Module[{K1, K2, K3, K4}, K1 = func[xn, yn]; K2 = func[xn + 1/2 step, yn + 1/2 step K1]; K3 = func[xn + 1/2 step, yn + 1/2 step K2]; K4 = func[xn + step, yn + step K3]; {xn + step, yn + 1./6 step (K1 + 2 K2 + 2 K3 + K4)} ] Testing f[x_, y_] := y*x^2 - 1.2*y; ...


1

A mundane but effective approach is to use the Shooting Method built into NDSolve. x0 = .01; xMax = 11.5; k = .4; c = N[D[(BesselK[1, x]/x), x]/(BesselK[1, x]/x) /. x -> xMax]; sol = NDSolveValue[{y''[x] + 3/x y'[x] - y[x] + 3/2 y[x]^2 - k/2 y[x]^3 == 0, y'[xMax] == c y[xMax], y'[x0] == 0}, y, {x, x0, xMax}, Method -> {"Shooting", ...


6

The short answer is: It's a common sense that (at least currently) DSolve is very weak on solving PDE and it simply can't handle this problem, period. However, with a little effort, you can solve it with LaplaceTransform: eqn = ϵ D[y[x, t], {x, 4}] + μ D[y[x, t], {t, 2}] == 0; ic = {y[x, 0] == Sin[x/L Pi], Derivative[0, 1][y][x, 0] == 0}; bc = {y[0, t] == ...


5

You can help Mathematica solve this partial differential equation by telling it to use separation of variables, as in DSolve doesn't find a solution (this may be a duplicate, but I decided to answer in order to show how to adapt my linked answer here): op = Function[y, ϵ D[y, {x, 4}] + μ D[y, {t, 2}]]; ansatz = ψ[x] f[t] (* ==> f[t] ψ[x] *) eq2 = ...


1

This is not a direct answer to your problem, but rather a generalization of @Jens' code from double to n-tuple pendulums. Meaning you can also use it for double pendulums if you like. I'm providing it due to popular demand. Needs["VariationalMethods`"] n = 10; (* number of pendulum segments *) rate = 10; (* animation frame rate *) Clear[s, ϕ, t, g, m]; ...


2

You can numerically solve this with n = 10; k1 = 0.5; k2 = 2; interpol = NDSolve[{a'[t] == (0.5/(1 + (b[t]/k1)^n)) - 0.2*a[t], b'[t] == (1/(1 + (a[t]/k2)^n)) - 2*b[t], a[0] == b[0] == 0}, {a, b}, {t, 0, 120}] That produces an interpolating function called interpol. You can plot parametrically as ParametricPlot[Evaluate[{a[t], b[t]} /. interpol], {t, ...


1

It seems that the ode under discussion has only trivial solution. I checked it with both Mathematica and maple and got what was expected. Mathematica output Plot[y[x] /. sol, {x, xmin, xmax}] Maple output restart:with(plots): ode:=-diff(y(x),x$2)+x^2*y(x)-abs(y(x))^2*y(x)=0; ics:=y(-500)=0,y(500)=0; p:=dsolve({ode,ics},numeric); odeplot(p);


3

A sample numerical solution is m = 1; a = 1; g = 1; k = 1; sol = NDSolve[{m x''[t] == m (a + x[t]) (θ'[t])^2 + m g Cos[θ[t]] - k x[t], m (a + x[t]) θ''[t] + 2 m x'[t] θ'[t] == -m g Sin[θ[t]], x[0] == 1, θ[0] == .2, x'[0] == 1, θ'[0] == 0}, {x, θ}, {t, 0, 10}]; Plot[Evaluate[{x[t], θ[t]} /. sol], {t, 0, 10}]


2

ParametricNDSolveValue is made for such problems: sol = ParametricNDSolveValue[{y1'[t] == -k1*y1[t]*y2[t] + k11*y3[t], y2'[t] == -k1*y1[t]*y2[t] + k3*y5[t] + k11*y3[t], y3'[t] == k1*y1[t]*y2[t] - k2*y3[t]*y4[t] + k22*y5[t] - k11*y3[t], y4'[t] == -k2*y4[t]*y3[t] + k22*y5[t], y5'[t] == k2*y3[t]*y4[t] - k22*y5[t] - k3*y5[t], y6'[t] == ...


0

Here is a quick example to get you started. You'll have to create a list of values for kA and kB. Just do table from 0.001 to 1.0 for both of them. kA=Table[i,{i,0.001,1.0,0.001}]; kB=Table[i,{i,0.001,1.0,0.001}]; Manipulate[ { eqA = A'[t] == -kA[[i]]*A[t]; eqB = B'[t] == kA[[i]]*A[t] - kB[[i]]*B[t]; eqC = c'[t] == kB[[i]]*B[t]; soln = NDSolve[ ...


2

Here's a quick one. It'd be wise to solve the equations for a set of variables k1,...,k22 just once. This is possible with dynamic programming revised1[k1_, k2_, k3_, k11_, k22_] := revised1[k1, k2, k3, k11, k22] = NDSolve[{y1'[t] == -k1*y1[t]*y2[t] + k11*y3[t], y2'[t] == -k1*y1[t]*y2[t] + k3*y5[t] + k11*y3[t], y3'[t] == k1*y1[t]*y2[t] - ...


1

Here's a way that gets fairly close. Perhaps further tweaking could improve the result. Block[{K1 = 1}, {sol} = NDSolve[deqsys, f, {x, 0, 2}, Method -> {"Shooting", "StartingInitialConditions" -> {f[0] == 10^-4, f'[0] == 1, f''[0] == 0.1, f'''[0] == -0.1}, Method -> "StiffnessSwitching"}] ] This avoids the singularity ...


0

If you look at the output of: y[4.4]/.sol you will find that that is an interpolating function which is valid from x=0.01 to roughly 5.14. If one plots that result from x=0.01 to 5.14 that shows that 5.14 is the point where the derivative becomes zero. So it looks like NDSolve does the right thing. What happens when you Plot from x=0.01 to xMax=20 is that ...


0

Specifying initial conditions (as per gwr) resolves matters: sol = ParametricNDSolve[{2*I*a'[t] == -0.1*w* b[t]*(Exp[I*(0.1*w)*t] + Exp[-I*(2.1*w)*t]), 2*I*b'[t] == -0.1*w*a[t]*(Exp[-I*(0.1*w)*t] + Exp[I*(2.1*w)*t]), a[0] == b[0] == 1}, {a, b}, {t, 0, 1000}, w]; f[w_] := a[w] /. sol Manipulate[Plot[Evaluate[Abs[f[w][t]]]^2, {t, 0, 1000}], ...


4

This can actually be solved analytically (DSolve), noting it is only algebraic in t: urt[r_, t_] = Simplify[(u /. First@DSolve[{kh t D[u[r], r] - 2 Pi a u[r] + 2 Pi a == 0, u[302] == 21/100}, u, r])[r]] 1 - 79/100 E^((2 a Pi (-302 + r))/(kh t)) Plot3D[urt[r, t] /. {kh -> 10^-6, a -> 300}, {t, 10, 200}, {r, 298, ...


1

Here is a short sketch of how I would do it. Since I am not a physicist this is more or less simply a how to get a function plot advice. ;-) parSol = ParametricNDSolve[ { 2 I a'[t] == -0.1 w b[t] (Exp[ I (0.1 w) t] + Exp[-I (2.1 w) t]), 2 I b'[t] == -0.1 w a[t] (Exp[-I (0.1 w) t] + Exp[ I (2.1 w) t]), (* initial conditions *) a[0] == b[0] ...


2

Using Event-Handling and Euler method Expanding the solution given by Michael E2 one might figure that using EventSeries is coming closest to the "real thing" which after all is a series of discrete events: eventTimes = Range[ 0, 10, 1 ]; (* example *) isEventTimeQ[ t_?NumericQ ] := Piecewise[ Table[ { 1 , t == eventTime }, {eventTime, eventTimes}], ...


5

First, you're not using a fixed step method. (An Euler scheme may be applied to any step size and to one that varies.) To get a true fixed step method you have to turn off "DiscontinuityProcessing" when you have a discontinuous ODE; otherwise, NDSolve will try to adapt the steps to account for the discontinuity. The "DiscontinuityProcessing" stage resets ...


4

As noted in my comment, {x, y, z} must be defined in order for ItoProcess to work. Even then, the solution is unstable for the parameters chosen in the question. Stable parameters are, for instance, sigma = .01 and a RandomFunction step size of 0.1. In all, the modified code sigma = .01; trajectory = ItoProcess[{\[DifferentialD]v[t] == (a*δ*to[t] - ...


0

Here is way to use Piecewise, which might well be what Guess who it is. had in mind. ti = 0; tf = 30; eq1 = y1''[t] + 0.5 y2'[t] + 0.7 y1[t] + A[t] == 0; eq2 = y2''[t] + 0.3 y1'[t] + 1.3 y2[t] == 0; {sol} = NDSolve[{ eq1, eq2, y1'[ti] == 1, y1[ti] == 0, y2'[ti] == 1, y2[ti] == 0, A[t] == Piecewise[{{Sin[t], y1[t] > y2[t]}}, 0]}, {y1, y2, A}, ...


1

ParametricNDSolve is a numerical solver. You need to give it enough numerical values for the parameters and domain that the solver can come up with a unique InterpolatingFunction representing the numerical solution of your equation. First, your differential equation of course has a family of $y(t)$ functions as solutions. How can ParametricNDSolve choose ...


0

Only a partial solution.NDSolve can't solve with this initial conditions y(1) = 0.5 sol = NDSolve[{(1 + x)*(0.5*y[x]^(-0.5)*(x - y[x])^0.5 - 0.5*y[x]^0.5*(x - y[x])^(-0.5)) == -y[x]*(x - y[x])/y'[x], y[0.99] == 0.5}, y, {x, 0, 2}, AccuracyGoal -> 30, PrecisionGoal -> 30, WorkingPrecision -> 55] // Quiet; ODEequations[x_] := y[x] /. sol; g1 = ...


0

I believe that all you need to do is select the following method option in NDSolve Method->{"PDEDiscretization"->{"MethodOfLines",{"SpatialDiscretization"->"FiniteElement"}}}


2

The solution to this problem was a simple one: BC1 was defined at [t,0], and BC2 was also defined at [t,0]. Change the location of BC2 to [t,2*L] and the problem is solved. I.e. both boundary conditions were defined for the same point.


1

Not an answer but too long for comment: If I modify slightly your input and choose 'n=2` n = 2; Solve[Table[{Subscript[β, 1] (1 - Subscript[a, i] - Subscript[b, i] - Subscript[c, i]) Sum[ Subscript[A, i, j] (Subscript[a, j] + Subscript[c, j]), {j, 1, n}] - Subscript[δ, 1] Subscript[a, i] + Subscript[δ, 2] ...


0

paramSol = ParametricNDSolve[{y1'[t] + y1[t]/t1 - f[t] == 0 , y1[0] == 0, y2'[t] + y2[t]/t2 - f[t] - a*y1[t] == 0 , y2[0] == 0}, {y1, y2}, {t, 0, 10}, {a, t1, t2}]; model = Evaluate[a1 y1[a, t1, t2][t] + a2 y2[a, t1, t2][t] /. paramSol]; nlm = NonlinearModelFit[data, model, {a, a1, a2, t1, t2}, t]


2

There are two issues going on here, though only one of them is preventing your plot from working in the Manipulate. The first is, as noted by xzczd in comments, that you need to get Mathematica to see that the \[Beta] in the expression for x[t]/. s is the same one you are using as the variable to be manipulated. You can see this is an issue with a slight ...


1

Below is the answer: Manipulate[Plot[ Evaluate[x[t] /. NDSolve[{x''[t] + 2 \[Beta] x'[t] + 4 x[t]== 0, x'[0] == 0, x[0] == 1}, x, {t, 0, 4}]], {t, 0, 5}], {\[Beta], 0,4,0.1}] thank you for asking


1

Here I present my first working solution that uses the components of NDSolv. (I hope posting a new answer is the right way to do this.) The goal is to use the "ion drive" for awhile, and then "coast" from where that leaves us up to the vicinity of the Moon. This first block initializes some constants: G = 6.672*10^-11; M = 5.97219*10^24;(*Mass of Earth*) ...


6

In a sense, the returned solutions are valid, but only over a restricted domain. We can determine the domain for each solution with something like Reduce[ode && -Infinity < t < Infinity /. sol, t] We can join the domain with the corresponding solution via ConditionExpression. ode = {x'[t] == Sqrt[x[t]], x[0] == 4}; dsol = DSolve[ode, x, ...


3

Why not {sol} = NDSolve[{f'[x] == g[x], g'[x] == f[x], f[0] == 1, g[0] == 0}, {f, g}, {x, 0, 1}] omitting the definition of f? Check: {Inactivate@NIntegrate[g[x0], {x0, 0, x}], f[x]} /. sol /. x -> 0.5 // Activate (* {0.521095, 0.521095} *)


2

Works when you specify constants and rename Xg to g as Xg would introduce a new dependent. M = 1; L = 1; vg = 1; Rd = 1; MX = 1; Rn = 1; r0 = 1; eqns = {D[g[z, t], z] == (1/vg) (M*L - (r0^2/(Rd^2*f[z, t]^3)) + M*(1 + Rn*(r/r0)^2) a^2/((1 + g[z, t]/f[z, t]^2)^(3/2))) (D[ g[z, t], t] - ((2*g[z, t]/f[z, t])*D[f[z, t], t])) - ...


0

Define: polarToCartesian[r_,theta_]:=r*{Cos[theta],Sin[theta]} Then, after you solve the differential equation, use ParametricPlot: ParametricPlot[polarToCartesian[r[t],theta[t]],{t,0,t0}] UPDATE polarToCartesian[{r_, theta_}] := r*{Cos[theta], Sin[theta]} s = ParametricNDSolve[ {r'[t] == r[t] (1 - (r[t])^2) (4 - (r[t])^2), theta'[t] ...


1

It's being caused by a misplaced ')'. Nested tables are frequently a bad idea. Here: Table[C'[i][t] == (B.Table[C[i][t], {i, 1, 10}])[[i]], {i, 2, 9}] + ... You can't do that with the plus on the end. In the equation you're feeding into NDSolve, essentially you have (stuff == moreStuff) + extra which makes no sense. Once I correct for that the error goes ...



Top 50 recent answers are included