RE : string to identifier



On 22.01.2012 10:14, Adam Majewski wrote:
> On 22.01.2012 01:39, laurent couraud wrote:
>> You can also use eval_string from the package stringproc.
>>
>> Laurent.
>
>
> Thx. It :
> * removes upper/lower case switching
> * removes one language from code ( older code have used 3 languages :
> Maxima, Lisp and gnuplot. New code uses 2 languages : Maxima and gnuplot. )
> Below is new code.
>
> I think about making scene ( scene1, scene2 ....) in similar way to make
> code shorter ( I hope not obfuscated) and then use :
> draw(scene1, scene2)
>
> Old code and image is here :
> http://commons.wikimedia.org/wiki/File:Parabolic_critical_orbits.png
> more description :
> http://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/parabolic
>
>
> Please look also at :
>
> Category:Images with Maxima CAS source code
> http://commons.wikimedia.org/wiki/Category:Images_with_Maxima_CAS_source_code
>
>
> Category:Created with Maxima (software)
> http://commons.wikimedia.org/wiki/Category:Created_with_Maxima_%28software%29
>
>
> Thx
>
> Adam
>
>
>
>
> ============== newest code ==============
>
> kill(all);
>
>
>
> /* ---------- functions ---------------------- */
>
> /* conformal map from circle to cardioid ( boundary
> of period 1 component of Mandelbrot set */
> F(w):=w/2-w*w/4;
>
>
> /*
> circle D={w:abs(w)=1 } where w=ToCircle(t,r)
> t is angle in turns ; 1 turn = 360 degree = 2*Pi radians
> r is a radius
> */
> ToCircle(t,r):=r*%e^(%i*t*2*%pi);
>
>
>
>
> /*
>
> http://en.wikipedia.org/wiki/Complex_quadratic_polynomial
> */
> f(z,c):=z*z+c $
>
> GiveCriticalOrbit(c,iMax):=
> /*
> computes (without escape test)
> critical orbit (forward orbit of critical point )
> and saves it to the list for draw package */
> block(
> [z,orbit,temp],
> z:0, /* first point = critical point z:0+0*%i */
> orbit:[[realpart(z),imagpart(z)]],
> for i:1 thru iMax step 1 do
> ( z:expand(f(z,c)),
> orbit:endcons([realpart(z),imagpart(z)],orbit)),
>
> return(orbit)
> )$
>
>
> /* find fixed point alfa , returns a list */
> GiveFixed(c):=
> (
> [z],
> z:float(rectform((1-sqrt(1-4*c))/2)),
> [[realpart(z),imagpart(z)]]
> )$
>
>
>
> GiveC(angle,radius):=
> (
> [w],
> /* point of unit circle w:l(internalAngle,internalRadius); */
> w:ToCircle(angle,radius), /* point of circle */
> float(rectform(F(w))) /* point on boundary of period 1 component of
> Mandelbrot set */
> )$
>
>
>
> compile(all)$
>
>
>
> /* ---------- constant ---------------------------*/
> Numerator :1;
> DenominatorMax :10;
> InternalRadius:1;
> iMax:500;
>
>
> /* -------------- main ----------------- */
>
>
>
> for Denominator:1 thru DenominatorMax step 1 do
> (
> InternalAngle: Numerator/Denominator,
> c: GiveC(InternalAngle,InternalRadius),
> /* */
> eval_string(concat("z",string(Denominator)))::GiveFixed(c),
> /* */
>
> eval_string(concat("orbit",string(Denominator)))::GiveCriticalOrbit(c,iMax)
> );
>
>
>
>
> /*-----------------------------------------------------------------------*/
> load(draw); /* ( interface to gnuplot ) by Mario Rodriguez Riotorto
> http://www.telefonica.net/web2/biomates */
>
> draw(
>
> terminal = screen,
> columns =5,
> file_name = "b",
> pic_width = 1000, /* Since Maxima 5.23, pic_width and pic_height are
> deprecated. */
> pic_height = 500, /* See option dimensions. To get the same effect,
> write dimensions=[800,600] */
>
> gr2d(
> title= "1/1 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
>
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit1),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z1),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= " 1/2 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
>
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* criitical orbit */
> color =red,
> points(orbit2),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z2),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= " 1/3 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit3),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z3),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= " 1/4 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit4),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z4),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
> gr2d(
> title= " 1/5 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit5),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z5),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= "1/6 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
>
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit6),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z6),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= " 1/7 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
>
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* criitical orbit */
> color =red,
> points(orbit7),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z7),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= " 1/8 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit8),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z8),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
>
> gr2d(
> title= " 1/9 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit9),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z9),
> /* criitical point */
> color =blue,
> points([0],[0])
> ),
> gr2d(
> title= " 1/10 ",
> user_preamble = "set border 0;set nokey;set size square;set noxtics ;set
> noytics;",
> point_type = filled_circle,
> points_joined = false,
> point_size = 0.7,
> /* critical orbit */
> color =red,
> points(orbit10),
> /* parabolic fixed point */
> color =black,
> point_size = 1.4,
> points(z10),
> /* criitical point */
> color =blue,
> points([0],[0])
> )
>
>
>
> );
With help of Mario Rodriguez Riotorto
I have change the program. It does not uses strings but lists of scenes 
  and is much shorter.

Thx

Adam


===========code==========

kill(all);



/* ---------- functions ---------------------- */

/* conformal map  from circle to cardioid ( boundary
  of period 1 component of Mandelbrot set */
F(w):=w/2-w*w/4;


/*
circle D={w:abs(w)=1 } where w=l(t,r)
t is angle in turns ; 1 turn = 360 degree = 2*Pi radians
r is a radius
*/
ToCircle(t,r):=r*%e^(%i*t*2*%pi);




/*

http://en.wikipedia.org/wiki/Complex_quadratic_polynomial
*/
f(z,c):=z*z+c $

GiveCriticalOrbit(c,iMax):=
    /*
    computes (without escape test)
    critical orbit (forward orbit of critical point )
    and saves it to the list for draw package */
block(
  [z,orbit,temp],
  z:0, /* first point = critical point z:0+0*%i */
  orbit:[[realpart(z),imagpart(z)]],
  for i:1 thru iMax step 1 do
         ( z:expand(f(z,c)),
           orbit:endcons([realpart(z),imagpart(z)],orbit)),

  return(orbit)
)$


/* find fixed point alfa , returns a list */
GiveFixed(c):=
(
  [z],
z:float(rectform((1-sqrt(1-4*c))/2)),
[[realpart(z),imagpart(z)]]
)$



GiveC(angle,radius):=
(
  [w],
  /* point of  unit circle   w:l(internalAngle,internalRadius); */
  w:ToCircle(angle,radius),  /* point of circle */
  float(rectform(F(w)))    /* point on boundary of period 1 component of 
Mandelbrot set */
)$




GiveScene(sTitle, zn, orbitn):=
gr2d(title= sTitle,
	user_preamble = "set border 0;set nokey;set size square;set noxtics 
;set noytics;",
	
         point_type    = filled_circle,
	points_joined = false,
         point_size    = 0.7,
         /* critical orbit */
	color		  =red,
	points(orbitn),
         /* parabolic fixed point */
	color		  =black,
	point_size    = 1.4,
	points(zn),
         /* criitical point */
	color		  =blue,
	points([0],[0])
         )$

compile(all)$



/* ---------- constant ---------------------------*/
Numerator :1;
DenominatorMax :10;
InternalRadius:1;
iMax:500;


/* -------------- main ----------------- */


scenes:[];
for Denominator:1 thru DenominatorMax step 1 do
(
  InternalAngle: Numerator/Denominator,
  c: GiveC(InternalAngle,InternalRadius),
  scene:GiveScene(string(InternalAngle), GiveFixed(c), 
GiveCriticalOrbit(c,iMax)),
  scenes:cons(scene,scenes))$



/*-----------------------------------------------------------------------*/
load(draw); /* ( interface to gnuplot ) by Mario Rodriguez Riotorto 
http://www.telefonica.net/web2/biomates */

draw(

     terminal  = screen,
     columns =5,
     file_name = "b",
     pic_width  = 1000,    /* Since Maxima 5.23, pic_width and 
pic_height are deprecated. */
     pic_height = 500,    /* See option dimensions. To get the same 
effect, write dimensions=[800,600] */

     scenes


  );