-3
$\begingroup$

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?

$\endgroup$
  • 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
2
$\begingroup$
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

| improve this answer | |
$\endgroup$

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