1

I need to solve a diferential equation of the form w'=g(t,w(t)) where g is defined as follows

g[t_, w_] := {f1[t, {w[[3]], w[[4]]}], f2[t, {w[[3]], w[[4]]}], w[[1]],w[[2]]};

and f1, f2 are

f1[t_, y_] := Sum[\[Mu][[i]] (s[[i]] - y)/Norm[s[[i]] - y]^2, {i, 1, 5}][[1]];

f2[t_, y_] := Sum[\[Mu][[i]] (s[[i]] - y)/Norm[s[[i]] - y]^2, {i, 1, 5}][[2]];

Everything else is defined properly and is not the cause of the error. Yet when I use

sout = NDSolve[{y'[tvar] == g[tvar, y[tvar]], 
y[0] == {Cos[Pi/6], Sin[Pi/6], 0, 0}}, y, {tvar, 0, 2}, Method -> "ExplicitRungeKutta"];

I get the error

Part::partw: Part 3 of y[tvar] does not exist.
Part::partw: Part 4 of y[tvar] does not exist.

I have looked in other questions and none of them solved this problem.

Dmitry
  • 6,716
  • 14
  • 37
  • 39
  • 1
    setting up so that mathematica undersfands that `y` is a vector function is tricky. see here https://mathematica.stackexchange.com/q/78641/2079 and ask on that site if you need more help – agentp Dec 15 '17 at 12:43

1 Answers1

1

You want to find a function in $R^4$ satisfying a differential equation.

I don't think DSolve and NDSolve have a standard way of manipulating vectorial differential equations except by representing each component with an explicit name or an index for the dimensions.

Here is a working example, that can be executed without Method specification in dimension 4 with notations similar to your problem:

sout={w1[t],w2[t],w3[t],w4[t]} /. NDSolve[{
  w1'[t]== t*w2[t],
  w2'[t]== 2*t*w1[t],
  w3'[t]==-2*w2[t]+w1[t],
  w4'[t]== t*w3[t]-w1[t]+w2[t],

  w1[0]==0,
  w2[0]==1,
  w3[0]==1,
  w4[0]==0
},{w1[t],w2[t],w3[t],w4[t]},{t,0,2}]


ParametricPlot[{{sout[[1, 1]], sout[[1, 3]]}, {sout[[1, 2]], sout[[1, 4]]}}, {t, 0, 2}]

I think you will be able to adapt this working example to your needs.

I didn't use your original problem as I wanted to focus on the specification for Mathematica, not on the mathematics of your equation. There are constants involved such as Mu and s that you do not give.

ogerard
  • 735
  • 9
  • 15