Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Suggestions for more compact code

  • To: mathgroup at
  • Subject: [mg48783] Suggestions for more compact code
  • From: mathma18 at (Narasimham G.L.)
  • Date: Wed, 16 Jun 2004 04:54:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

I wish to avoid writing independent variable repetitively, reducing
the bulk and appearance of written programs in Mathematica; :).. May I
avail the liberty,even with my relatively new acquaintance to Mathematica, to
make a small suggestion for the code? Of course, I do understand the
code is written keeping generalities/versatality  in mind, but as is
well known in NDSolve and other so many Function usages that Mathematica is so
well known for, a single independent variable like x or time t is most
often used.   For plotting Cornu's Spiral from its differential
equation, one writes in the normal way:
NDSolve[{ph'[s] == s,ph[0] == 0},
Plot[ph2[s],{s, -8,8}] ;
NDSolve[{x'[s] == Simplify[Cos[ph2[s]]],x[0] == 0},
x,{s, -8,8}];
NDSolve[{y'[s] == Simplify[Sin[ph2[s]]],y[0] == 0},
y,{s, -8,8}];
" Suggested declaration for Functions of single argument:
  Variables[{ph,ph2,x,x2,y,y2},[s]] "
" Suggested command for single Dummy independent
 variable/argument: x2[]=x[]/.First[%]"
By above shorter notation, it might be possible to write:
NDSolve[{ph' == s,ph[0] == 0},ph,{s,-8,8}];
ph2[]=ph[]/.First[%]; Plot[ph2,{s, -8,8}] ;
NDSolve[{x' == Simplify[Cos[ph2]],x[0] == 0},x,{s, -8,8}];
x2[]=x[]/.First[%]; Plot[x2,{s,-8,8}];
NDSolve[{y' == Simplify[Sin[ph2]],y[0] == 0},y,{s, -8,8}];
y2[]=y[]/.First[%]; Plot[y2,{s,-8,8}];
Best Regards, Narasimham.

  • Prev by Date: Re: How to modify Convex Hull program to give output as Cartesian Coordinates?
  • Next by Date: Clear cell labels palette
  • Previous by thread: Re: Iterate initial conditions
  • Next by thread: Re: Suggestions for more compact code