0

I am trying to solve the motion equations for the Trojan Asteroids in Sun-Jupiter system. However, i am getting this error

Syntax: '(' cannot be followed by 'x[t],y[t]'

in this code

Alpha = 0.000953875;
r_1 = Sqrt[(x - Alpha)^2 + y^2];
r_2 = Sqrt[(x + 1 - Alpha)^2 + y^2];
x_0 = -0.509;
y_0 = 0.883;
u_0 = 0.0259;
v_0 = 0.0149;


NDSolve[
    {x'[t] == u[t],

    y'[t] == v[t],

    u'[t] == -(1 - Alpha) (x[t] - Alpha)/r_1 (x[t],  y[t])^3 - Alpha (x[t] + 

    1 - Alpha)/r_2(x[t], y[t])^3 + x[t] + 2 v[t],

    v'[t] == -(1 - Alpha) y[t]/r_1 (x[t], 

    y[t])^3 - Alpha y[t]/r_2 (x[t], y[t])^3 + y[t] - 2 u[t],

    x[0] == x_0, y[0] == y_0, 

    u[0] == u_0, v[0] == v_0},

    {x, y, u, v}, {t, 0, t_max}]

Of course, i am extremely average at coding, so any kind of help will suffice

Thanks

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 4
    The _ has a predefined meaning in MMA. Try removing all those that you have used inside variable names and see how much that helps. – Bill Sep 03 '18 at 06:33
  • 4
    My advice is to learn the basics before trying to do something complicated: go through a tutorial. Here you started to guess at the syntax (instead of looking it up), and of course not every guess was correct. At this stage, it's too early to ask questions on Mathematica.SE. Please make sure you have at least a basic understanding of the language before you ask. – Szabolcs Sep 03 '18 at 09:08
  • Thank you everyone for the advice, i will definitely study basics before trying more complex things – Hector Manuel Chacon Carrillo Sep 03 '18 at 19:42

1 Answers1

2

In addition to _ there is still a misuse of functions in () instead of []

Alpha = 0.000953875;
r01[x_, y_] := Sqrt[(x - Alpha)^2 + y^2];
r02[x_, y_] := Sqrt[(x + 1 - Alpha)^2 + y^2];
x00 = -0.509;
y00 = 0.883;
u00 = 0.0259;
v00 = 0.0149;
tmax = 100;

sol = NDSolve[{x'[t] == u[t], y'[t] == v[t], 
   u'[t] == -(1 - Alpha) (x[t] - Alpha)/r01[x[t], y[t]]^3 - 
     Alpha (x[t] + 1 - Alpha)/r02[x[t], y[t]]^3 + x[t] + 2 v[t], 
   v'[t] == -(1 - Alpha) y[t]/r01[x[t], y[t]]^3 - 
     Alpha y[t]/r02[x[t], y[t]]^3 + y[t] - 2 u[t], x[0] == x00, 
   y[0] == y00, u[0] == u00, v[0] == v00}, {x, y, u, v}, {t, 0, tmax}];

    ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, tmax}]

fig1

Alex Trounev
  • 44,369
  • 3
  • 48
  • 106