Tag Info

Hot answers tagged

11

WhenEvent is working. Try WhenEvent[x[t] < 0, Print[t]; x[t] -> 0] to see that every crossing is detected. The problem is that it only detects crossings. So changing x[t] -> 0 does not reset the event. At the next step x[t] becomes negative and no event is detected. (This is how it is supposed to behave.) The way to deal with this is to use ...


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, ...


5

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] == ...


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 ...


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] & ; ...


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]}]]


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} ...


4

We have seen this problem posted by you before. This time you don't seem to understand that you can't have more equations than you have dependent variables. You have three equations b1'[z] - 1 I*beta1*b1[z] - C1*b2[z] == 0 b2'[z] - 1 I*beta2*b2[z] + C1*b1[z] == 0 (b1[z])^2 + (b2[z])^2 == 1 and only two dependent variables, b1 and b2. That one of the ...


3

Your ODE is linear, so whether it can satisfy your constraint |b1|^2+|b2|^2 <= 1 depends primarily on the eigenvalues of the coefficient matrix, as well as the initial condition. The coefficient matrix is the second array returned by CoefficientArrays. ode = {b1'[z] - 1 I*beta1*b1[z] - C1*b2[z] == 0, b2'[z] - 1 I*beta2*b2[z] + C1*b1[z] == 0} /. ...


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 ...


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, ...


2

It's not independent. The following is the same as your code, just edited for taking fg as a parameter Clear[w, z, x, y, t, a, b, c, d, ope2h, fg] a = 0.5; b = 0.001; c = 0.7; d = 0.5; ope2h = ParametricNDSolve[{ w'[t] == 1/4 + x[t]/a - w[t]*(1/a + 1/b) + y[t] fg, x'[t] == 1/2 + w[t]/a - x[t]*(1/a + 1) + z[t] fg, y'[t] == w[t]/b - y[t]/c - y[t] ...


2

The the function y is the integral of a logarithmic singularity, so it is relatively easy to understand. The function JacobiCN[s, 7/10] is relatively flat near s == EllipticK[7/10], so that the integral of its reciprocal can be approximated by a logarithm: y[s]/JacobiCN[s, 7/10] ~= y0 / (jp (s - EllipticK[7/10])) where y0 ~= y[s] at s == EllipticK[7/10] ...


2

My question is: how to set that NDSolve will not save whole InterpolationFunction for the result? There is actually a very simple way to do this: instead of specifying a list of functions in the second argument, specify an empty list instead. This now begs the question of how one can obtain results. The solution is to use the event location ...


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 ...


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, ...


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 ...


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 /@ ...



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