Using the Example Maplet Applications
This worksheet provides examples that demonstrate how each example Maplet application found in the Maplets[Examples] subpackage can be used within code.
Alert
This example provides a scenario in which the Alert Maplet application is useful.
restart:
if Maplets[Examples][Alert]( "Do you really want to delete the file?" ) = true then fremove( "whateverfile.mpl" ); end if;
See Also
Help Page, Example Worksheet
Confirm
This Maplet application queries the user to determine if Cauchy principal value integration should be used. If the user cancels, no integration is performed.
cpv := Maplets[Examples][Confirm]( "Should Cauchy principal value integration be used?" ): if cpv = true then int( 1/x^3, x = -3..5, CauchyPrincipalValue ); elif cpv = false then int( 1/x^3, x = -3..5 ); else NULL; end if;
GetColor
This procedure calls plot by using all the arguments specified. It also queries the user for the color of the plot by using the GetColor example Maplet application.
MyPlot := proc() plot( args, color = Maplets[Examples][GetColor]() ); end proc:
MyPlot( sin(x), x = 0..2*Pi );
GetEquation
This procedure calls solve with respect to x with the user input received from the GetEquation Maplet application.
MySolve := proc() solve( Maplets[Examples][GetEquation]( 'caption' = "Enter an equation in `x`:" ), x ); end proc:
MySolve();
GetExpression
This procedure calls diff with respect to x with the user input received from the GetExpression Maplet application.
MyDiffx := proc() diff( Maplets[Examples][GetExpression]( 'caption' = "Enter an expression in `x`:" ), x ); end proc:
MyDiffx();
GetFile
This example, once uncommented, deletes the file the user selects.
# fremove( Maplets[Examples][GetFile]() );
GetInput
This example requests an integer from the user. The user input is then returned to the Maple session.
parse( Maplets[Examples][GetInput]( "Enter an integer:", 'type' = plain ) );
Integration
This example of the Integration Maplet application prompts the user to select a type of integration, enter an integrand, variables of integration, limits of integration, and other options.
Maplets[Examples][Integration]( 1/x^3 );
KernelOpts
This example Maplet application is an interface to the kernelopts routine.
Maplets[Examples][KernelOpts]();
Help Page
LinearAlgebra
The LinearAlgebra subpackage of the Maplets[Examples] package provides an interface to a number of LinearAlgebra routines.
M := <<1,5>|<3,7>>;
V := <1,5,3>;
Maplets[Examples][LinearAlgebra][BezoutMatrix]();
Maplets[Examples][LinearAlgebra][ConditionNumber](M);
Maplets[Examples][LinearAlgebra][HilbertMatrix]();
Maplets[Examples][LinearAlgebra][MatrixNorm](M);
Maplets[Examples][LinearAlgebra][QRDecomposition](M);
Maplets[Examples][LinearAlgebra][SingularValues](M);
Maplets[Examples][LinearAlgebra][VectorNorm](V);
Message
This example runs the following Maple routine and displays the result in a message box.
MySolve := proc() local solns; solns := solve( args ); if solns = NULL then if _SolutionsMayBeLost then Maplets[Examples][Message]( "No solutions, but some solutions may have been lost" ); else Maplets[Examples][Message]( "No solutions" ); end if; else Maplets[Examples][Message]( sprintf( "%q", solns ) ); end if; solns; end proc:
MySolve(x^3 - 6.3 * x);
Question
In this example, if the sign of a variable cannot by determined, the user is queried about the variable's sign.
MySignum := proc(x) local sgnm; sgnm := signum( 0, x, 0 ); if type( sgnm, 'specfunc'('anything', 'signum') ) then if Maplets[Examples][Question]( sprintf( "Is %a positive?", x ) ) then 1; else sgnm; end if; else sgnm; end if; end proc:
assume( s1 > 0 );
MySignum( s1 );
MySignum( s2 );
Selection
The following procedure calls LinearAlgebra[QRDecomposition] with arguments. It also queries the user for the desired output form by using the Selection example Maplet application.
MyQRDecomposition := proc(M::Matrix) LinearAlgebra[QRDecomposition]( args, output = [seq( [Q, R, rank][i], i = [Maplets[Examples][Selection]( ["Q", "R", "rank"], default = 1 )] )] ); end proc:
MyQRDecomposition( <<1,2,5>|<5,3,6>|<2,5,3>> );
ShowTable
This procedure creates a conversion table by using the Units package and displays it by using the ShowTable example Maplet application. It uses the fact that convert/conversion_table with output = grid returns a MATRIX data structure (the first argument of which is a list of lists).
MyConversionTable := proc(L::list(name)) Maplets[Examples][ShowTable]( map2( map, convert, op(1, convert( L, conversion_table, output = columns, filter = evalf[5] )), string ), width = 500 ); end proc:
MyConversionTable( [kg, g, lb, stone] );
SignQuery
This integral checks all indeterminates to determine if they are positive. All indeterminates that are positive are assumed to be positive inside the integration by using the assuming command.
MyInt := proc(integrand::algebraic, var::{name, name = range}) local indts, i, positives, varT; if type( var, name ) then varT := var; else varT := lhs( var ); end if; indts := select( 'type', indets( integrand ), 'name' ) minus {varT}; positives := NULL; for i in indts do if Maplets[Examples][SignQuery]( i ) then positives := positives, i::positive; end if; end do; int( integrand, var ) assuming positives; end proc:
MyInt( exp(-n*x), x=0..infinity );
Return to Index for Example Worksheets
Download Help Document