Question: Subprocedures in a main procedure

How to add any/many subprocedure in a mainprocedure?
Somehow the mainprocedure must deliver the input for the mainprocedure

Here is a example 

Note: probably can this old procedure be rewritten in modern Maple programming language ?  



Code to Find the Max and Min Values in a List A



   local i;

   maxv:=A[1]; minv:=A[1];

   for i from 2 to nops(A) do

     if eval(maxv) < A[i] then maxv:=A[i] end if;

     if eval(minv) > A[i] then minv:=A[i] end if;

   end do;


end proc:


Now we can call the maxmin procedure from a procedure named optimize, which is designed to create the polygonal approximation, use maxmin to find the largest and smallest y-values from among the vertices, and produce some graphic output.

See the documentation in the book.


Code to Approximate the Max and Min Values of a Function  f :



  local X,Y,L,i,A,xmax,xmin;



  for i from 0 to N do




  end do;


  maxmin(A,maxv,minv); # USE OF SECOND PROCEDURE --------------


  for i from 0 to N do

    if Y[i]=maxv then xmax:=xmax union {X[i]} end if;

    if Y[i]=minv then xmin:=xmin union {X[i]} end if;

  end do; #----------------------------------------------------


  print(`maximum y value is`,maxv,`and occurs at these x values`,xmax);

  print(`minimum y value is`,minv,`and occurs at these x values`,xmin);

  end proc:


Note that you must execute the code that defines maxmin before the procedure optimize will work. This only make sense.


We test the optimize procedure with the following function



proc (x) options operator, arrow; 3+10*(-x^2+x^4)*exp(-x^2) end proc


on the interval [-1, 4].



`maximum y value is`, 6.088066652, `and occurs at these x values`, {1.633333333}


`minimum y value is`, 1.391538737, `and occurs at these x values`, {-.6333333333, .6333333333}






Please Wait...