Tag Info

New answers tagged

1

Did you notice that in In[22], b1 is colored black and b2 is colored blue? That means that b1 has a previously defined value and is not a dependent variable. So you have two equations with only one unknown, which is what the error message is telling you. This sort of thing happens when code gets evaluated more than once without clearing variables that have ...


0

I wonder if the dummy problem is sufficiently representative: The system factors through x, so to speak. In other words, we can first solve for x and then for y. An alternative approach is to solve iteratively, starting with a test function for x to be used for Derivative[1, 0][x] and hoping the iteration converges. If these methods are insufficient, ...


1

The derivative boundary condition is specified with respect to the wrong variable. InitialConditions = { y[s, 0] == 1, x[s, 0] == 0, Derivative[0, 1][x][s, 0] == 0, Derivative[0, 1][y][s, 0] == 0}; BoundaryConditions = { x[0, t] == 0, x[1, t] == 0, y[0, t] == 1 + t^2/2*(1 + Derivative[0, 1][x][0, t]), y[1, t] == 1 + t^2/2*(1 + Derivative[0, 1][x][1, ...


4

$ \def\figA#1{\def\nextfig##1{\figB##1}\def#1{1}#1} \def\figB#1{\def\nextfig##1{\figC##1}\def#1{2}#1} \def\figC#1{\def\nextfig##1{\figD##1}\def#1{3}#1} \def\figD#1{\def\nextfig##1{\figE##1}\def#1{4}#1} \def\figE#1{\def\nextfig##1{\figF##1}\def#1{5}#1} \def\figF#1{\def\nextfig##1{\figG##1}\def#1{6}#1} \def\figG#1{\def\nextfig##1{\figH##1}\def#1{7}#1} ...


0

In an effort to answer the question, I Rationalized all constants. Used WhenEvent to stop DSolvebefore z'[ρ] becomes singular. Solved for both z and z' in the second instance of DSolve to improve the accuracy of the integrand of the subsequent NIntegrate. Commented out the instance of NIntegrate involving fnp, which has no significant effect on the ...


5

The answers by march and John McGee become very slow for larger numbers of iteration, to the extent that I had to abort the calculations when going to 7 or 8 iterations. The reason is that Integrate appears to be trying too many unnecessary simplifications at each level, and these steps proliferate because the integrals are iterated. The following makes ...


3

How are you calculating the velocity around the cylinder I am using Plot[Norm[f[20 + 5 Cos[\[Theta]], 20 + 5 Sin[ \[Theta]]]], {\[Theta], 0, 2 \[Pi]}] to give Which I think is correct. For the pressure we need the correct form for Bernoulli. Where you take the values of pressure at infinity as 0 but ignore the velocity at infinity. I am also ...


4

Generally speaking, one tends to get the most out of Mathematica by trying to avoid explicit loops (e.g. For, Do, etc) in favor of functional expressions (e.g. Map, Fold, Nest, ...). If I understand what you are looking for, all you need is the following: (* YOUR CODE *) Clear[x]; a = 0.1; b = 0.01; k = (10*Cos[t] + 20); years = 3; s = NDSolve[{x'[t] == ...


2

Notwithstanding the starting value of sigma, D[V[S, t], {S, 2}] looks always positive sigma = .3; r = 0; nd = NDSolve[{ D[V[S, t],t] + r S D[V[S, t],S] + sigma^2 S^2 D[V[S, t],{S, 2}]/2 - r V[S, t] == 0, V[S, 2] == Max[S - 100, 0], V[0, t] == 0, V[200, t] == 100}, V, {S, 0, 200}, {t, 0, 2}] Plot3D[D[V[S, t], {S, 2}] /. nd[[1]] /. S -> s, {s, ...


5

Here are some possibilities more in line with Mathematica idioms (i.e. that avoid using procedural loops). Option 1 Clear[h] h = Function[{t}, 1 + Integrate[#^2, {x, 0, t}]][x] & ; NestList[h, 1, 3] (* {1, 1 + x, 1 + x + x^2 + x^3/3} *) Option 2 To set the ys in the process: Clear[y, h] h = Function[{t}, 1 + Integrate[#^2, {x, 0, t}]][x] & ; ...


1

The OP's -- oops, they're bbodfrey's -- pictures suggest the problem is with interpolation, as bbgodfrey also observed. Some of the problem can be ameliorated with the InterpolationOrder option. From InterpolationOrder: In functions such as NDSolve, InterpolationOrder->All specifies that the interpolation order should be chosen to be the same as the ...


4

I believe that the following code does what you want For[{n = 1, y[0][x_] = 1}, n < 4, n++, y[n][x_] = 1 + Integrate[y[n - 1][t]^2, {t, 0, x}];Print[{n, y[n][t]}]]


1

Maybe I now understand your question right, so give it a try. First the series approach. With the series function you can approximate a function with a Taylor-Series. In the first step I calculate the maxima of your solution: seedMax = Table[t, {t, 6, 30, 0.5}]; solsMax = Quiet @ FindMaximum[func[x], {x, #}] & /@ Flatten[seedMax]; xMax = x /. (Last /@ ...


5

The best way (as pointed out by @Guesswhoitis.) is to convert splines into implicit functions. The real issue you are having is that you'd need a second order mesh to get a decent solution. Note that DiscretizeGraphics and DiscretizeRegion create first order meshes. So you'd need to use ToElementMesh. We also would like to have a finer boundary resolution, ...


2

The problem with your original code is that the order argument you specified (4) is in fact not the same as the order of the midpoint method (2). Thus: MidpointCoefficients[2, prec_] := N[{{{1/2}}, {0, 1}, {1/2}}, prec]; For comparison purposes, here's the Butcher table for Heun's method: HeunCoefficients[2, prec_] := N[{{{1}}, {1/2, 1/2}, {1}}, prec]; ...


1

I think if you examine the solutions, you will see that z'[t] -> - Infinity near the point where the integration ends. Manipulate[ With[{ρminmax = Flatten[z["Domain"] /. s[i, d]]}, (* start/stop values *) Plot[ {z[ρ], z'[ρ]} /. s[i, d] // Flatten // Evaluate, (* fn. & deriv. *) {ρ, ρminmax[[1]], ρminmax[[2]]}, PlotLabel -> ...


8

Two problems are involved here. The electric field is ill-behaved at a sharp point, and computational resolution is limited. The first can be seen by plotting the potential, uval, calculated using the code in the Question, for various values of y. Plot[Table[uval[x, y], {y, 0, .2, .02}], {x, -1, 1}, AxesLabel -> {x, u}] Notice the cusp developing ...


3

Your code works fine with a clean kernel. That indicates that previous assignments to c, k, s, and p are interfering with your evaluation of NDSolve. So you should evaluate Clear[c, k, s, p]; before evaluating NDSolve. The main difference between your NDSolve expression and Zviovich's is yours returns interpolating function expressions and his the actual ...


1

Replace c[t],k[t],s[t],p[t] for c,k,s,p sol1 = NDSolve[{dec, dek, des, dep, c[0] == 1, k[0] == 1, s[0] == 1, p[0] == 1}, {c, k, s, p}, {t, 0, 255}]; Plot[# /. sol1, {t, 0, 10}] & /@ {c[t], k[t], s[t], p[t]}


2

This interesting problem can be solved by iterating several times on μ. (WhenEvent cannot be used, because this is a boundary value, not an initial value, computation.) μ[t_] = 0; β = 1/10; c1 = 10; c2 = 30; k1 = 100; k2 = 300; T = 100; δ1 = 1/10; δ2 = 3/10; Subscript[y, 0] = 1000; a = 4000; b = 200; d[t_] = a + b*Sin[(2*π*t/25)]; y3[t_] = ...


2

It's works with the assumed n! Lets n = 5. n = 5; y = Sum[c[i]*x^i, {i, 0, n}] + O[x]^(n + 1); ODE = (D[y, {x, 2}])^2 + 1/2*D[y, x] + 1/2*y - p*x - q == 0; Y = FullSimplify@ Normal[y /. Solve[LogicalExpand[ODE], Table[c[i], {i, 1, n}]]] // Quiet Solution: $${\frac{-10 c(2) x^5 (c(0)+2 p-2 q)^2+3 x^5 (c(0)+2 p-2 q)^3-32 c(2)^3 x^4 (3 x-5) (c(0)+2 ...


0

Unfortunately, simplification is in the eye of the beholder and, therefore, erratic. Try solv = DSolve[{a*u''[y] - b*c*u[y] == d, u'[0] == 0, u[1] == 0}, u, {y, -1, 1}] z = u[y] /. solv[[1]] FullSimplify[FullSimplify[Numerator[z] Exp[(- Sqrt[b] Sqrt[c])/Sqrt[a]]]/ FullSimplify[Denominator[z] Exp[(- Sqrt[b] Sqrt[c])/Sqrt[a]]]] (* (d (-1 + Cosh[(Sqrt[b] ...


2

The problem appears to be associated with interpolation by the InterpolatingFunction produced by NDSolve rather than by NDSolve itself. For instance, with sol = NDSolve[{(R'[t])^2 + 2 R[t] R''[t] == -1, R[1] == 1, R'[1] == 2/3}, {R}, {t, 1, 1.2}, WorkingPrecision -> 100]; a Plot of R and its first two derivatives yields near t = 0 Plot[{R[t], ...


1

There seem to be problems with your use of both Solve and NDSolve. However, ignoring the warnings Mathematica issues and plunging ahead, I get sol = Solve[{α A k^(α - 1) - ρ - δ == 0, A k^α - δ k - c == 0}, {c, k}] // FullSimplify; {csol, ksol} = {sol[[1, 1, 2]], sol[[1, 2, 2]]}; dec = c'[t] == -(c[t]/σ) (A α k[t]^(α - 1) - δ - ρ); dek = k'[t] == -(A ...


3

It seems increasing the number of requested points and the accuracy of NDSolve does the trick? rElectrode = 0.02; lElectrode = 0.6; lCamera = 1.5; rCamera = 1.5/2; voltage = 2.*10^4; domain = RegionDifference[ Rectangle[{-rCamera, -lCamera/2}, {rCamera, lCamera/2}], Rectangle[{-rElectrode, -lElectrode/2}, {rElectrode, lElectrode/2}]]; phi = ...


4

It's a "problem" due to the holding attributes of If[ ]. You may inject the value by using With[{pp=u},If[....]] inside your Sum[] or with something like this: q[u_] := u s = NDSolve[{ (Total[If[# == n[t], n[t] q[#] , q[#]] & /@ Range@2] ) y''[ t] == -100 y[t], y'[0] == 0, y[0] == 1, n[0] == 1, WhenEvent[t > 3.5, n[t] -> 2]}, {y, n}, ...


2

This is not a full answer but what I found so far… Following @user21's link If I use Method -> {"PDEDiscretization" -> {"FiniteElement", "MeshOptions" -> {"MaxCellMeasure" -> 0.0001}, "IntegrationOrder" -> 3}} as in P0 = NDSolveValue[{eqn0, DirichletCondition[P[R, z] == 0, R == 0], DirichletCondition[P[R, z] == 0, z == f[R]]}, ...


0

The following works both for the original question and for the case described in the comment about setting one of c1,c2,...c6 to be nonzero. Note that the error reported by the OP, NDSolve::nderr, does not have very helpful documentation, and the suggestion to use "StiffnessSwitching" in this case leads to another error, NDSolve::nodae, which is unexpected, ...


7

This is a bug (up until version 10.2) in the interpolation code when there are concave curved elements for unstructured query points. Workaround: To work around it one can use the either a "MeshOrder"->1 or set the "ImproveBoundaryPosition"->False both of these get rid of the spikes. Do[ r = 1; rct = Rectangle[{0, 0}, {10, 10}]; rnd[n_Integer] := ...


2

I approached this slightly differently, in an attempt to mimic what's written in a textbook of mine for direction fields. I set the plot as a system of unit vectors, with x and y from this derivation: $$\mathit{x}^2+\mathit{y}^2=1\wedge \mathit{m}=\frac{y}{\mathit{x}}\Rightarrow \\ \\ \mathit{x}=\frac{\mathit{y}}{\mathit{m}}\Rightarrow \\ ...


2

You shouldn't post such a code. Please isolate your problematic chunk first. Anyway. q[t_] := {xb[t], yb[t], θb[t], θ1[t], d2[t], d3[t]}; initu = Thread[q[0] == {0, 0, 0, 0, 1, 1}]; initv = Thread[q'[0] == {0, 0, 0, 0, 0, 0}]; jj = Join @@ ({Thread[M.q''[t] + V + G == {u1[t], u2[t], u3[t], u4[t], u5[t], u6[t]}], initu, initv}) /. {x_} == y_ ...


6

This crash has been fixed in version 10.2. In[1]:= if = NDSolveValue[{D[u[t, x, y, z], t] == 0, u[0, x, y, z] == 0}, u, {x, y, z} \[Element] Ball[], {t, 0, 1}, Method -> "FiniteElement"]; In[2]:= Export["if.wdx", if]; ...


1

Perhaps you want something like: sol = First@NDSolve[eqs, {x, y, θ}, {t, 0, 100}]; Manipulate[Graphics[Rotate[Rectangle[{0, 0}, {y[a], x[a]}], θ[a]] /. sol, Axes -> True], {a, 0.1, 100}]


2

Using the above solution of user21 you might look at the StreamPlot as follows: Show[{ StreamPlot[ Evaluate[{D[Potential, x], D[Potential, y]} /. z -> 0], {x, -1, 1}, {y, -1, 1}] // Quiet, RegionPlot[RegionDifference[Rectangle[{-1, -1}, {1, 1}], Disk[]], PlotStyle -> Opacity[1]] }] yielding the following: Here the code ...


4

This works for me: R2 = Cylinder[{{0, 0, -0.1}, {0, 0, 0.1}}, 1]; DBC1 = {DirichletCondition[ u[x, y, z] == 0, (-1 <= x <= -0.8 \[And] Abs[y] <= 0.6 \[And] Abs[z] == 0.1)], DirichletCondition[ u[x, y, z] == 1, (0.8 <= x <= 1 \[And] Abs[y] <= 0.6 \[And] Abs[z] == 0.1)]}; Potential = NDSolveValue[{Laplacian[u[x, y, ...


1

As noted in the comments only the first Epilog option will be used by Show. You could instead use a function that combines Prologs and Epilogs manually, if that is desired. myShow[gr__] := Show[gr, Join @@ Map[Options[#, {Prolog, Epilog}] &, {gr}] // Merge[List] // Normal ] Example: g1 = Plot[Style[2 Sin[x], Green], {x, -4, 4}, Epilog -> ...


3

I couldn't get your code to show anything as posted. After quite a bit of debugging I came up with this: m1 = 1; m2 = 1; lc1 = 1; lc2 = 1; l1 = 2; l2 = 2; Ix2 = 1; Iy2 = 1; Iz1 = 1; Iz2 = 1; m11[t_] := m1*(lc1)^2 + m2*(l1 + lc2*Cos[θ2[t]])^2 + Ix2*(Sin[θ2[t]])^2 + Iy2*(Cos[θ2[t]])^2 + Iz1; m22[t_] := m2*(lc2)^2 + Iz2; V11[t_] := 0; V12[t_] := ...


3

It's a good idea to include the error you got in your question. It gives a clue and might prompt someone to investigate: NDSolve::ndinid: Initial condition {0} is not in the range specified by the discrete variable NDSolve`s$147246. >> Now Sign is discontinuous and will cause NDSolve to invoke special processing of the ODE. I suspect that the strange ...


12

There is the as yet undocumented FEM function (see this answer, or read the user-interface with Definition after clearing the ReadProtected attribute) ElementMeshPlot3D[valuesOnMeshCoordinates, elementMesh, options] We can use this to plot the surface (note Head[slv] is just the pure InterpolatingFunction of the solution so we can apply to methods; see ...


3

I think the problem is with your mesh. Note that the "boundary condition" you're having trouble with is not actually on the boundary of the mesh; instead, it's in the interior. You need to explicitly specify that you have a boundary at what would otherwise be "interior" points, and ToBoundaryMesh can help you do that: mesh = ToBoundaryMesh["Coordinates" ...


3

I applied Rationalize to every decimal constant feeding into the computation of Soln and rm, and replaced AccuracyGoal -> 10, PrecisionGoal -> 10 by WorkingPrecision -> 60. The change in rm was negligible, {3.69158*10^6, {t -> 2.10981*10^7, p -> 0.938622}} before, and {3.69179*10^6, {t -> 2.10981*10^7, p -> 0.938622}} after these ...


3

As noted in comments on question 87963, a formal solution to these coupled equations can be obtained from the substitution, {u[x, t] -> u0 Exp[d1 t + d2 x], v[x, t] -> v0 Exp[d1 t + d2 x]} eq1 = Collect[(Unevaluated[D[u[x, t], t] + a1 D[u[x, t], x] - (c + k1) u[x, t] + k1 v[x, t]] /. {u[x, t] -> u0 Exp[d1 t + d2 x], v[x, t] -> v0 ...


5

The error message is misleading. NDSolve fails, because not enough boundary conditions in t have been supplied. If, for instance, (D[f[x, t], t] /. t -> 0) == 0 is added, then sol = First@NDSolve[{D[f[x, t], x, x] - D[f[x, t], t, t] == f[x, t]^3, f[x, 0] == Sin[2*Pi*x], (D[f[x, t], t] /. t -> 0) == 0, f[0, t] == 0, f[1, t] == 0}, f, {x, 0, ...


8

NMinimize[{Norm[{xm[t][p], ym[t][p]} - {xsc[t][p], ysc[t][p]}] /. soln, 0 < t < tmax && 0 < p < 5}, {t, p}, Method -> "SimulatedAnnealing"] (* {71729.9, {t -> 118.095, p -> 5.}} *)


2

The constant c can be eliminated from the equations by a standard transformation. eq1 = (Unevaluated[D[u[x, t], t] + (a + b x) D[u[x, t], x] - (c + k1) u[x, t] + k1 v[x, t]] /. {u[x, t] -> uu[x, t] E^(c t), v[x, t] -> vv[x, t] E^(c t)})/E^(c t) // Simplify (* -(k1*uu[x, t]) + k1*vv[x, t] + Derivative[0, 1][uu][x, t] + a*Derivative[1, 0][uu][x, ...


0

With k[r] = (1 - (r^2 - 1 - 10^-4)^20)/r^2 Use sol = ParametricNDSolveValue[{R'[t]^2 + 2 R[t] R''[t] == -r^2 k[r], R[1] == r (1 - r/10)^2/3, R'[1] == (2/3) 4/(1 - r/10)^(1/3)}, R, {t, 1, 3}, {r}]; dsol = Derivative[1][sol] and then plot, for example, R[1][t], R'[1][t], and (to verify that this really is the derivative with respect to r), ...


5

As you've seen, a definition like u = u[x,y,z] is not generally appropriate in Mathematica because the principle of the Mathematica evaluator is to repeatedly apply all known definitions to an expression until the result no longer changes. Here, the recursive definition is repeatedly applied, with no termination condition. If you're just looking for a ...


2

I believe that NeumannValue[-xload, x == span], as given in the question, is correct, as can be seen from the following simple test, for which the solution is obvious. test[Y_, ν_] := Inactive[Div][({{Y, 0}, {0, Y}}.Inactive[Grad][u[x, y], {x, y}]), {x, y}]; sol = NDSolveValue[{test[Ey, n] == NeumannValue[-xload, x == span], u[0, y] == 0}, u, {x, 0, ...


2

== is needed instead of = in eqn, and a space needs to be inserted in ut. With these changes, sol = DSolve[eqn, u, t] returns unevaluated. This is not surprising, because DSolve generally can solve only equations that are known to be solvable analytically. Instead, try sol = NDSolveValue[{(eqn /. {p -> 1, n -> 0}), u[1] == 1, u'[1] == 0}, u, {t, ...


4

A small remark on the error: CoefficientArrays::poly: -(1 + 3.27432/(1 + 0.092 Ccu)^2) Ccu11498 - (3 Ccu11499)/200 + 1.38465 Ccu$11500 is not a polynomial. >> First note that Ccu is your dependent variable in your PDE. The expression being complained about has several variables, Ccu and ones like Ccu$11498.. (The ones like Ccu$11498 are internal, ...



Top 50 recent answers are included