# System of differential algebraic equations with one of the variables as an argument of the other varaibles

This is my first question here and I don't even know what to search for to find a solution. So I'd appreciate it even if someone can point me in the right direction. EDIT: My post had many problems, so I decided to explain better with a few examples. I hope it is allowed. My main question is still the same.

Suppose we have a simple ODE:

sol1 = NDSolveValue[{D[u1[x], x] == Sin[x], u1[0] == 1},
u1, {x, 0, 1}]


with has this solution:

and another simple ODE:

sol2 = NDSolveValue[{D[u2[x], x] == Cos[x], u2[1] == 0},
u2, {x, 0, 1}]


with the following solution:

If we evaluate their difference at x=0.5:

sol1[0.5] - sol2[0.5]


results in approximately 1.48446.

Now here is the main question I have. How can we solve both of the ODEs simultaneity and find the location where their values are 1.485 units apart? One of the issues is the cut-off error ,i.e., there might not be any solutions to satisfy the exact difference value of 1.485. But I am assuming if I decrease the required tolerance to lets say 1.5, with accepting the introduced error in the exact location, this won't be an issue anymore. If I can find the correct way to formulate the problem, I can worry about other issues (existence, accuracy etc.) later. The best I could come up with was:

NDSolveValue[{D[u1[x], x] == Sin[x], u1[0] == 1,
D[u2[x], x] == Cos[x], u2[1] == 0, u1[t] - u2[t] == 1.485}, {u1, u2,
t}, {x, 0, 1}]


which makes the kernel non-responsive whenever I run it. I know this could be completely wrong. A possible method I found in other posts was writing a Module that calls NDSolve and then using FindRoot but that sounds very complicated. Can anyone suggest a way to avoid all those complexities and modify the formulation of the problem to be solvable only by using NDSolve?

It might be helpful to mention that eventually, I want to make a piece-wise function that is equal to u1 from x=0 to that unknown t location and then it becomes equal to u2 from there to x=1.

• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Mar 15 '16 at 0:10
• I don't understand your question, but you have a lot of syntax errors there. Here you have them corrected. The "main" question isn't solved eqns = { D[y1[x], x] == y1[x] + z1[x] , D[y1[x]*z1[x], x] == 0 , D[y2[x], x] == y2[x] - z2[x], D[y2[x]*z2[x], x] == 0, y1[x0] == 0.5 y2[x0]}; vars = {y1, y2, z1, z2, x0}; sol = NDSolve[{eqns, y1[0] == 0, z1[0] == 0, y2[0] == 1, z2[0] == 1}, vars, {x, 0, 1}] Mar 15 '16 at 0:16
• In addition to what @Dr.bel said (you are missing commas in between your equations, notice that the last of your equations y2[x0] is really not an equation at all; you should provide a value as you did with the y1[x0] variable. Mar 15 '16 at 0:33
• Thanks for the responses. I have used other syntax conventions (separation of equations etc) but this one is exactly the way official documentation starts the DAE section (please refer to reference.wolfram.com/language/tutorial/…). Also, the main issue (I think) is the last equation not being recognized as an equation. The physical meaning is like this: two of the solutions (y1 and y2) have a relationship at a point X0 that we don't know where it is. The right and left hand BC is specified and the middle one should satisfy y1[X0]==y2[x0]/2. Mar 15 '16 at 2:38
• Examine the output of the input you posted: NDSolve[{Derivative[1][y1][x] == y1[x] + z1[x] (z1[x] Derivative[1][y1][x] + y1[x] Derivative[1][z1][x]) == 0 == y2[x] - z2[x] (z2[x] Derivative[1][y2][x] + y2[x] Derivative[1][z2][x]) == 0 == 0.5 y2[x0], True, True, False, False}, {y1, y2, z1, z2, x0}, {x, 0, 1}] -- The True and the False is what Mathematica is complaining about, which comes from syntax errors in your input. Fix it as Dr. bel has shown you. Note also the zeros in the first argument. You should check that that is what you want. Mar 15 '16 at 12:40

sol1 = NDSolve[{D[u1[x], x] == Sin[x], u1[0] == 1}, u1, {x, 0, 1}]