Hot answers tagged

12

The main problem is that your pos is not seen as a 3D vector. The cross product is therefore interpreted as a scalar: q*Cross[D[pos[t], t], b] when adding this to the vector q.e this 'scalar' term is added to each of the vector components: q*e + q*Cross[D[pos[t], t], b] This won't work, instead do: b = {1, 0, 0}; e = {0, 0, 1}; q = 1; m = 1; ...


8

Alternative method: b = {1, 0, 0}; e = {0, 0, 1}; q = 1; m = 1; sol = NDSolve[{e + Cross[pos'[t], b] == m/q pos''[t], pos[0] == {0, 0, 0}, pos'[0] == {0, 0, 0}}, pos, {t, 0, 10}, Method -> {"EquationSimplification" -> "Residual"}]; ParametricPlot3D[pos[t] /. sol, {t, 0, 10}, PlotRange -> All]


6

Another alternative is to package your constant vector parameters as DiscreteVariables. In the OP's case, it necessary only to chnage e since b occurs inside Cross, which will not evaluate until all its arguments are vectors. Note that in the equation we changed e to e[t] and set its value with e[0] == {0, 0, 1}. b = {1, 0, 0}; (*e={0,0,1};*) q = 1; m = 1; ...


5

Examine your integrand (which is suggested by the error, after all). PiecewiseExpand will collect all terms under one piecewise function. c*h[c, k1, t1]*(1 - H[c, k2, t2])*(1 - H[c, k3, t3]) // PiecewiseExpand (* Power::infy, Infinity::indet errors... *) You can see that the function does not have numeric values for c > 1. How to fix it is ...


4

Sometimes a manual approach to the shooting method makes a BVP easier to solve. Set up with ParametricNDSolveValue: zmin = 0; zmax = 2; psol = ParametricNDSolveValue[{ D[ϕ[z], z, z] == 4*λ*ϕ[z]*(ϕ[z]*ϕ[z] - v^2) + 2*γ*χ[z]*χ[z]*ϕ[z], D[χ[z], z, z] == 2*γ*χ[z]*(ϕ[z]*ϕ[z] - μ^2) + 4*β*γ*χ[z]*χ[z]*χ[z], ϕ[zmin] == phi[zmin], ϕ'[zmin] == phip, ...


4

Your F wrapper function is doing nothing for you in your code, so I removed it and replaced it with direct calls to F1. NIntegrate in the argument to FindMinValue should not be evaluated unless it is passed explicitly numerical arguments, so it is best to wrap it in a function protected by NumericQ (functiontominimize below). Since all the other functions ...


3

From the description of the question it seems to me that using the (undocumented) option IntegrationMonitor to obtain integration intervals and estimates might be very useful. Here is an example: t = Reap[NIntegrate[Sin[x]/Sqrt[x], {x, 0, 100}, PrecisionGoal -> 6, Method -> "MonteCarlo", IntegrationMonitor -> (Sow[ ...


3

You want to hunt down the error? Here is the best piece of advice: don't plot a function until you know it works. Okay, that's out of the way, now let's go through the process of finding out why your code gives an error. First we can look at just one integral, Λ = 10^-6; Δ = 10^-3; θ = 1/2 ArcTan[Δ/δ]; h = 10^-1; t = 10^3; s = -h Sqrt[Δ^2 + δ^2] ...


3

This is a fairly common problem to encounter and in this case was a bit subtle due to having an outer and inner function both in need of being defined only for explicitly numeric input. So I'll repost my comment as an answer and make it a Community wiki. The FindMinumum objective itself needs to be defined only for numeric input. Which can be done as ...


2

What about: StoppingTest -> (Apply[ Or, Table[EuclideanDistance[Coordinates[s], Source[i]] < 1, {i,1,NumSources}], {0}])


2

I only address your question about the integration. I tried your code for the integral for t=1. Indeed there was such a message: NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small I think a good idea would be ...


1

I computed the PDE system solutions without the MaxStep specification. (As suggested by user21.) The numerical integration seems to be fast enough with the default NIntegrate options. If I use AccuracyGoal -> 6 the integration becomes 3 times faster. If I remove the integration at $t=0$ I do not get messages. As Alexei Boulbitch suggested we can try ...



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