Programming Guide



It could look like this, by ELIMINATING ALL DECLARATIONS..



step(lam,alpha):=
block([h 1/(2*n)],

  a0[0]:alpha, a1[0]:0, a2[0]:-lam/2*sin(a0[0]), a3[0]:0,
  ap0[0]:0, ap1[0]:0, ap2[0]:-0.5*sin(alpha), ap[3][0]:0,

    a0[i]:=a0[i-1]+a1[i-1]*h+a2[i-1]*h^2,
    a1[i]:=a1[i-1]+2*a2[i-1]*h+3*a3[i-1]*h^2,
    a2[i]:=-lam/2*sin(a0[i]),
    a3[i]:=-lam/6*cos(a0[i])*a1[i],
    ap0[i]:=ap0[i-1]+ap1[i-1]*h+ap2[i-1]*h^2,
    ap1[i]:=ap1[i-1]+2*ap2[i-1]*h+3*ap[3][i-1]*h^2,
    ap2[i]:=-0.5*sin(a0[i])-lam/2*cos(a0[i])*ap0[i],
    ap3[i]:=-1/6*cos(a0[i])*a1[i]+lam/6*sin(a0[i])*ap0[i]*a1[i]
                   -lam/6*cos(a0[i])*ap1[i],
   these[i]:=[op(these),[i*h,a0[i]]],  /* these is not used here*/
[a0[n],ap0[n]])

 

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Zoho Vignochi
> Sent: Friday, March 30, 2007 10:03 AM
> To: maxima at math.utexas.edu
> Subject: Programming Guide
> 
> Hello,
> 
> I am looking for a good tutorial on the Maxima programming 
> language. As
> well as some sample code. I am currently in the process of porting a
> simple Maple program to Maxima and I could use some help regarding
> arrays.
> 
> Here is the maple code snipit in question:
> 
> step:=proc(lambda,alpha)
> #
> #    Given lambda and alpha, solve the differential
> #    equation subject to the first boundary condition
> #    returning psi(0.5) and d/d lambda psi(0.5). 
> # 
> local i,h;
> global a,ap,n,these;
> h:=1/(2*n); # The step size. 
> a:=array(0..3); ap:=array(0..3); # The coefficients and their
>   for i from 0 to 3 do             # derivatives.
>     a[i]:=array(0..n); ap[i]:=array(0..n);
>   end do;
>   a[0][0]:=alpha; a[1][0]:=0; a[2][0]:=-lambda/2*sin(a[0][0]);
> a[3][0]:=0;
> ap[0][0]:=0; ap[1][0]:=0; ap[2][0]:=-0.5*sin(alpha); ap[3][0]:=0;
>   for i from 1 to n do
>     a[0][i]:=a[0][i-1]+a[1][i-1]*h+a[2][i-1]*h^2;
>     a[1][i]:=a[1][i-1]+2*a[2][i-1]*h+3*a[3][i-1]*h^2;
>     a[2][i]:=-lambda/2*sin(a[0][i]);
>     a[3][i]:=-lambda/6*cos(a[0][i])*a[1][i];
>     ap[0][i]:=ap[0][i-1]+ap[1][i-1]*h+ap[2][i-1]*h^2;
>     ap[1][i]:=ap[1][i-1]+2*ap[2][i-1]*h+3*ap[3][i-1]*h^2;
>     ap[2][i]:=-0.5*sin(a[0][i])-lambda/2*cos(a[0][i])*ap[0][i];
> ap[3][i]:=-1/6*cos(a[0][i])*a[1][i]+lambda/6*sin(a[0][i])*ap[0
][i]*a[1][i]
>                    -lambda/6*cos(a[0][i])*ap[1][i];
>   end do;
> these:=[]; # Points on psi for plotting. 
> for i from 0 to n do
>    these:=[op(these),[i*h,a[0][i]]];
> end do;
> [a[0][n],ap[0][n]];
> end proc; 
> 
> I have not including the other proc's. It is the declaration of the
> array's which is giving me trouble. I believe that Maxima can have an
> array of arrays but I have been unable to locate an example 
> of how to do
> this.
> 
> Any help appreciated and thank you for your time.
> 
> Zoho
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>