Can someone please tell me what I am doing wrong? I am trying to solve a system of odes using NDSolve. The code I have written is as follows:

NDSolve[{x'[t] == cos[t] + 4sin[t] - 4[x] - 2[y], y'[t] == -3sin[t] + 
3[x] + [y], x[0] == 0, y[0] == -1},{x[t],y[t]},t]

However I am getting an error that says

Syntax:"-3sin[t]+3[x]+" cannot be followed by "[y]".

I have tried taking the brackets off [y] which results in

NDSolve: The function y appears with no arguments.

Any help would be greatly appreciated. Also how would I plot a solution curve for this ODE after getting NDSolve to function?


closed as off-topic by bbgodfrey, m_goldberg, Bob Hanlon, Michael E2, MarcoB May 8 '17 at 1:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – bbgodfrey, m_goldberg, Bob Hanlon, Michael E2, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ what do you mean with 4[x] and 2[y]? Are those functions?? Also, the sinus function ist written in Mathematica with capital S, Sin[x] is $\sin(x)$. You should first take a look at basic syntax in Mathematica. $\endgroup$ – Mauricio Fernández May 7 '17 at 15:31
  • 3
    $\begingroup$ You made the Sin sin before! Please show some signs of learning instead of asking people to do your work for you. $\endgroup$ – Michael E2 May 7 '17 at 18:05
eqns = {
   x'[t] == Cos[t] + 4 Sin[t] - 4 x[t] - 2 y[t],
   y'[t] == -3 Sin[t] + 3 x[t] + y[t],
   x[0] == 0, y[0] == -1};

This system can be solved exactly with DSolve without using numeric techniques of NDSolve

soln = DSolve[eqns, {x, y}, t][[1]]

(*  {x -> Function[{t}, E^(-2 t) (-2 + 2 E^t + E^(2 t) Sin[t])], 
 y -> Function[{t}, -E^(-2 t) (-2 + 3 E^t)]}  *)

Verifying that the solution satisfies the equations and initial conditions,

And @@ (eqns /. soln // Simplify)

(*  True  *)

Plot[Evaluate[{x[t], y[t]} /. soln], {t, 0, 3 Pi},
 PlotLegends -> Placed[{x[t], y[t]}, {0.85, 0.2}]]

enter image description here


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