Apologies in advance: this is a really basic question, and I am sure it has been answered, but I don't know enough mathematica to even find the answer.

I have a differential equation I want to solve. Specifically I want to know the solution at some long time T (say T=50). The differential equation involves some parameters, and I want to define a function to be the solution of the differential equation as a function of these parameters.

What I did was

Solu[w1_, w2_, w3_, alph_, T_] := 
 Flatten[Evaluate[{u[T], v[T], w[T], x[T], y[T], z[T]} /.  
    NDSolve[{u'[t] == 
       w1 + x[t] Sin[v[t] - u[t]] + y[t] Sin[w[t] - u[t]], 
      v'[t] == w2 + x[t] Sin[u[t] - v[t]] + z[t] Sin[w[t] - v[t]], 
      w'[t] == w3 + y[t] Sin[u[t] - w[t]] + z[t] Sin[v[t] - w[t]], 
      x'[t] == -alph x[t] + Cos[u[t] - v[t]], 
      y'[t] == -alph y[t] + Cos[u[t] - w[t]], 
      z'[t] == -alph z[t] + Cos[v[t] - w[t]], u[0] == 0, v[0] == 0, 
      w[0] == .0, x[0] == 1, y[0] == 1, z[0] == 1}, {u, v, w, x, y, 
      z}, {t, 0, T}]]]

Which is fine if I want to find the value at a specified point:

In[202]:= Solu[-1.0, -1, 2, .3, 20] 

Out[202] = {-0.107791, -0.107791, 0.215582, 3.32755, 3.14742, 3.14742}

But Mathematica gags if I try to make a table of values, or graph the solutions.

In[203]:= Table[Solu[-x,-1,1+x,.3,50],{x,0,2}]

NDSolve::ndode: Input is not an ordinary differential equation. >>

I understand that this is related to the way mathematica first builds the table and then evaluates, but I don't understand how to fix it.


closed as off-topic by Bob Hanlon, MarcoB, RunnyKine, user9660, LLlAMnYP Apr 12 '16 at 9:30

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." – Bob Hanlon, MarcoB, RunnyKine, Community, LLlAMnYP
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Functions which use numeric techniques should have their arguments restricted to numeric values. Solu[w1_?NumericQ, w2_?NumericQ, w3_?NumericQ, alph_?NumericQ, T_?NumericQ] := ... $\endgroup$ – Bob Hanlon Apr 11 '16 at 19:00
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Apr 11 '16 at 19:29

Do not use x as both a dependent variable in NDSolve and an index in Table. Instead, try,

Table[Solu[-a, -1, 1 + a, .3, 50], {a, 0, 2}]
(* {{7.19845*10^-22, -0.102113, 0.102113, 3.31597, 3.31597, 3.26406}, 
    {-0.10725, -0.10725, 0.214501, 3.33333, 3.16227, 3.16227}, 
    {-67.8836, -67.7287, 135.612, 3.29475, 0.133514, 0.162306}} *)
  • $\begingroup$ Ok, thanks, that was dumb of me. $\endgroup$ – Geardaddy Apr 11 '16 at 19:30

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