MuPAD Pro Computing Essentials, 2nd Edition

Example 5.7 User defined library of MuPAD procedures

In order to understand what is going on in this example you should read the appropriate fragment of the book. The idea is to write a number of constants, functions and procedures and save them as a MuPAD "library" that can be later used through the read command.

// declarations of constants and functions
MyPI := 3.14;
MyE := 2.72;
MyExp := x -> MyE^x;
    
// declarations of procedures 
average := proc()
local n, i, result;
begin
   n := args(0);
   result := 0;
   for i from 1 to n do
      result := result + args(i)
   end;
   result := result/n;
 return(result)
end: 
  
squares := proc()
local n, i, result;
begin
   n:=args(0);
   result := 0;
   for i from 1 to n do
      result := result + args(i)^2
   end;
   return(result)
end:
 
// first make the folder "userlib" in MuPAD main folder 
 
WRITEPATH := "userlib"; 
write(Text,"myfunctions.mu")
 
// library can now be read and used
 
READPATH := "userlib";
read("myfunctions.mu")

 

© Miroslaw Majewski, Abu Dhabi,  Update  26-10-2004