3
$\begingroup$

I am attempting to solve a system of ODEs where a, b, cv1 and cv2 are vectors.

Tu = {{-3 / 4, 1 / 4}, {5, -6}}`
tu = {2/4, 1}
pu = {.7, .3}

a[y_] = {Subscript[a, 1][y], Subscript[a, 2][y]};
b[y_] = {Subscript[b, 1][y], Subscript[b, 2][y]};
cv1[y_] = {Subscript[cv1, 1][y], Subscript[cv1, 2][y]}
cv2[y_] = {Subscript[Subscript[cv2, 1][y], 1], Subscript[Subscript[cv2, 2][y], 2]}

(* Ode system *)
a'[y] == a[y].Tu
b'[y] == Tu.b[y]
cv1'[y] == Tu.cv1[y] + Subscript[a, 1][y].tu
cv2'[y] == Tu.cv2[y] + Subscript[a, 2][y].tu*)

S = 
  NDSolve[
    {a'[y] == a[y].Tu,
     b'[y] == Tu.b[y],
     cv1'[y] == Tu.cv1[y] + Subscript[a, 1][y].tu,
     cv2'[y] == Tu.cv2[y] + Subscript[a, 2][y].tu, a[0] == pu, 
     b[0] == tu, cv1[0] == cv2[0] == 10^-5}, 
   {a[y], b[y], cv1[y], cv2[y] }, {y, 0, ∞}]

I am getting an output informing me that there (incorrectly) exist more dependent variables than equations. How should I specify this system?

Edit

I fixed the initial code (the above is now the updated version); the previous error no longer occurs, though I now receive the following:

NDSolve::ndnco: The number of constraints (6) (initial conditions) is not equal to the total differential order of the system plus the number of discrete variables (8).

EDIT:

Note that using the system as specified in the answer will not retrieve the correct cv1 and cv2 expressions. Instead specify those in the system as:

cv1'[y] == 
 Tu.cv1[y] + (MapIndexed[Indexed[a[y], #2] &, Range[2]] // First)*tu,
cv2'[y] == 
 Tu.cv2[y] + (MapIndexed[Indexed[a[y], #2] &, Range[2]] // Last)*tu
$\endgroup$
  • $\begingroup$ There is no initial data. $\endgroup$ – Alex Trounev Jan 22 at 0:01
  • $\begingroup$ My bad, I updated it with the correct initial data and am getting new errors as will be listed $\endgroup$ – BayesIsBaye Jan 22 at 1:04
  • $\begingroup$ It's just unclear to me what system you're trying to solve. Is Subscript[a, 1][y] and Subscript[a, 2][y] scalar? If so, why there exists Subscript[a, 1][y].tu in the system? (Dot (.) is for products of vectors, matrices, and tensors. ) Is cv2 just a vector like a, b and cv1? If so, why is it defined in such a strange way? Can you show us the system in traditional math notation? $\endgroup$ – xzczd Jan 25 at 5:26
3
$\begingroup$
Tu = {{-3/4, 1/4}, {5, -6}};

tu = {2/4, 1};
pu = {.7, .3};
ym = 1;


(*Ode system*)
eq = {a'[y] == a[y].Tu, b'[y] == Tu.b[y], 
   cv1'[y] == Tu.cv1[y] + First[a[y]]*tu, 
   cv2'[y] == Tu.cv2[y] + Last[a[y]]*tu};
ic = {a[0] == pu, b[0] == tu, cv1[0] == cv2[0] == {10^-5, 10^-5}};



S = NDSolve[{eq, ic}, {a, b, cv1, cv2}, {y, 0, ym}]

{Plot[a[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "a"}], 
 Plot[b[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "b"}, 
  PlotRange -> All], 
 Plot[cv1[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "cv1"}], 
 Plot[cv2[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "cv2"}]}

fig1

If we change the code, excluding First and Last, the result will change, although in symbolic form the equations look the same.

(*Ode system*)
eq = {a'[y] == a[y].Tu, b'[y] == Tu.b[y], 
   cv1'[y] == Tu.cv1[y] + (a[y].{1, 0})*tu, 
   cv2'[y] == Tu.cv2[y] + (a[y].{0, 1})*tu};
ic = {a[0] == pu, b[0] == tu, cv1[0] == cv2[0] == {10^-5, 10^-5}};
S = NDSolve[{eq, ic}, {a, b, cv1, cv2}, {y, 0, ym}];
{Plot[a[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "a"}], 
 Plot[b[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "b"}, 
  PlotRange -> All], 
 Plot[cv1[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "cv1"}], 
 Plot[cv2[y] /. S, {y, 0, ym}, AxesLabel -> {"y", "cv2"}]}

fig2

I assume that functions First and Last are ignored when solving equations. @Janeiro offers its solution.

$\endgroup$
  • $\begingroup$ A colleague who had coded this in R had noted that he had different forms for CV1 and CV2 -- is the First[] and Last[] commands here proper in the system of equations wrt a's elements? $\endgroup$ – BayesIsBaye Jan 24 at 16:57
  • 1
    $\begingroup$ Problem solved. Use : cv1'[y] == Tu.cv1[y] + (MapIndexed[Indexed[a[y], #2] &, Range[2]] // First)*tu, cv2'[y] == Tu.cv2[y] + (MapIndexed[Indexed[a[y], #2] &, Range[2]] // Last)*tu (will update question) $\endgroup$ – BayesIsBaye Jan 24 at 17:14
  • $\begingroup$ The result is the same. What is the point of adding? $\endgroup$ – Alex Trounev Jan 24 at 18:33
  • $\begingroup$ @Janeiro You are right, really NDSolve[] ignores First[] and Last[]. I published the second solution. $\endgroup$ – Alex Trounev Jan 24 at 19:20
  • $\begingroup$ NDSolve doesn't ignore First and Last, because they've already disappeared when the eq=… line is executed: First@a[y] evaluates to y immediately. Notice most functions for list manipulation are not limited to List manipulation e.g. try {First@f[x], Most@f[x,y,z]}. $\endgroup$ – xzczd Jan 25 at 5:08

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.