I need to numerically solve several differential equations, with several constraints, like this :

Coordinates[s_] := {x[s], y[s], z[s]}

    x'[s] == F[s], 
    y'[s] == G[s], 
    z'[s] == H[s], 
    x[0] == DataX, 
    y[0] == DataY, 
    z[0] == DataZ}, {x, y, z}, {s, 0, 500}, 
    Method -> Automatic, MaxSteps -> Automatic, 
    StoppingTest -> (
        EuclideanDistance[Coordinates[s], Source[1]] < 1 || 
        EuclideanDistance[Coordinates[s], Source[2]] < 1 ||
        EuclideanDistance[Coordinates[s], Source[3]] < 1 ||
        EuclideanDistance[Coordinates[s], Source[NumSources]] < 1

Now, there are NumSources constraints of this type :

    EuclideanDistance[Coordinates[s], Source[k]] < 1

where k = 1, 2, 3, ..., NumSources.

How can I simplify that long part of constraints in the NDSolve defined above ?

This is probably basic, but I don't see how to simplify this.

UPDATE : Just a picture to show off. The magnetic field lines of an arbitrary number of magnetic dipoles (magnetized spheres) :

6 magnetized balls

  • $\begingroup$ Isn't this a duplicate of your previous question, mathematica.stackexchange.com/questions/105869/…? $\endgroup$ – Michael E2 Feb 9 '16 at 14:46
  • $\begingroup$ It is related to that question, but it isn't the same. Not a duplicate. Or maybe it is ? At first, I made that code just for 2 sources. Now, I want to generalize the code for an arbitrary number of sources. $\endgroup$ – Cham Feb 9 '16 at 14:49
  • $\begingroup$ The first question was about some aspects for just 2 constraints. Now, I'm trying to generalize the code for an arbitrary number of constraints. Maybe it should be in the same question. $\endgroup$ – Cham Feb 9 '16 at 14:51
  • $\begingroup$ On a practical note, I don't suppose you can upgrade? My feeling is that the differential equations folks no longer have access to V7, and things have changed so much that no one can test any ideas they might have. $\endgroup$ – Michael E2 Feb 9 '16 at 14:53
  • $\begingroup$ So can you answer your previous question, then? Your solution might help others suggest one to this question. $\endgroup$ – Michael E2 Feb 9 '16 at 14:54

What about:

StoppingTest -> 
   Table[EuclideanDistance[Coordinates[s], Source[i]] < 1, {i,1,NumSources}],
| improve this answer | |
  • $\begingroup$ It doesn't appear to work well. I'm getting lots of warning messages, and the output is all messy. Is this compatible with Mma version 7 ? And why the {0} in the Apply ? $\endgroup$ – Cham Feb 9 '16 at 14:47
  • $\begingroup$ The {0} specifies the level. You can omit it (I copied and pasted it from another code). Despite the fact that the Apply command is updated in Mma version 10.3 it should work in this context in Mma 7. Have you defined the parameter s within Coordinates. Maybe s is a table and thus you have to give it as s[[i]] $\endgroup$ – demm Feb 9 '16 at 15:02
  • $\begingroup$ Oh boy ! I just found the source of my problem ! This was trivial ! My bad ! Your suggestion appears to be working great now ! $\endgroup$ – Cham Feb 9 '16 at 15:05
  • $\begingroup$ I'll mark your answer as THE answer in a few days, just in case someone give a simpler answer. $\endgroup$ – Cham Feb 9 '16 at 15:06
  • $\begingroup$ By the way, what should I use instead of StoppingTest ? Apparently, this is an obsolete command. $\endgroup$ – Cham Feb 9 '16 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.