Re: Suggestions for more compact code

• To: mathgroup at smc.vnet.net
• Subject: [mg48998] Re: Suggestions for more compact code
• From: mathma18 at hotmail.com (Narasimham G.L.)
• Date: Mon, 28 Jun 2004 04:13:41 -0400 (EDT)
• References: <cap3tt\$cbm\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```A single independent variable for functions is often useful. A
notation where paranthesis [t] or [t_] is omitted (as understood) is
Continuous Simulation Language (ACSL of MGA software, excellent for
non-linear differential equations,transfer functions, automatic
statement sorting etc. among others) is compared here with Mathematica
in four corrosponding code lines:
--
yi=2 ;
equn = 0 == y'[t] - t / y[t] +Sin[t];
NDSolve[{equn,y[0] == yi},y,{t,-5,5}];
y2[u_]=y[u]/.First[%]; Plot[y2[t],{t,0,5}];
--
constant yi=2.
yd=t/y - sin(t)
y=integ(yd,yi) \$ termt(t.ge.5) \$  end
prepar t , y   \$   plot y
--
One can see how "lean" the latter is when adopting a single time
independent variable.Or is there an artifice/statement available
already, without having to repeat [t]?

mathma18 at hotmail.com (Narasimham G.L.) wrote in message news:<cap3tt\$cbm\$1 at smc.vnet.net>...
> 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},
> ph,{s,-8,8}];
> ph2[u_]=ph[u]/.First[%];
> Plot[ph2[s],{s, -8,8}] ;
> NDSolve[{x'[s] == Simplify[Cos[ph2[s]]],x[0] == 0},
> x,{s, -8,8}];
> x2[v_]=x[v]/.First[%];
> Plot[x2[s],{s,-8,8}];
> NDSolve[{y'[s] == Simplify[Sin[ph2[s]]],y[0] == 0},
> y,{s, -8,8}];
> y2[w_]=y[w]/.First[%];
> Plot[y2[s],{s,-8,8}];
> ParametricPlot[{x2[s],y2[s]},{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}];
> ParametricPlot[{x2,y2},{s,-8,8}];
> --------
> Best Regards, Narasimham.

```

• Prev by Date: Re: Simplifying with assumptions
• Next by Date: Re: PlotLabel with assigned variables *and* on several lines
• Previous by thread: Suggestions for more compact code
• Next by thread: Clear cell labels palette