where is the number of elements of the list
and
is the
average of the numbers in list
.
Your routine should print an error if the list is empty.
Write a Maple procedure that computes the Frobenius norm of an by
matrix
.
The Frobenius norm is
.
Write a Maple procedure which sorts an array of numbers
faster than the bubblesort algorithm in the section on arrays,
e.g. by using shell sort, quick sort, merge sort, or heap sort or
some other sorting algorithm.
Modify your Maple procedure to accept an optional 2nd argument ,
a boolean function to be used for comparing two
elements of the array.
Write a Maple procedure which computes the Fibonacci polynomials .
These polynomials satisfy the linear recurrence
,
, and
.
Compute and factor the first 10 Fibonacci polynomials.
Can your program compute
?
For example: structure(x^3*sin(x)/cos(x)); should return
[*, [^, x, 3], [function, sin, x], [^, [function, cos, x], -1]]
Your routine should handle the Maple types integer, fraction, float, `+`, `*`, `^`, string, indexed, function, range, equation, set, list, series and table. Test your function on the following input
Int( exp(-t)*sqrt(t)*ln(t), t=0..infinity ) = int( exp(-t)*sqrt(t)*ln(t), t=0..infinity );
Write a routine comb that when given a set of values and a non-negative integer
returns a list of all combinations of the values of size
.
For example
=-1.00.5plus##1`##1=12=^^M=12 > comb( a,b,c,d, 3 );
a,b,c, a,b,d, a,c,d, b,c,d
plusplus -100 plus Modify your routine to work for lists which may contain duplicates, e.g.
=-1.00.5plus##1`##1=12=^^M=12 > comb( [a,b,b,c], 2 );
[[a,b], [a,c], [b,b], [b,c]]
plusplus -100 plus
=-1.00.5plus##1`##1=12=^^M=12 > p := x^3*y^3 + x^4 + y^5: > degree(p,x); # degree in x
4
> degree(p,x,y); # total degree in x and y
6
plusplus -100 plus We showed how one could code the degree function in Maple with our DEGREE function. However, the degree function and our DEGREE function only work for integer exponents. Extend the DEGREE so that it computes the degree of a general expression, which may have rational or even symbolic exponents, e.g.
=-1.00.5plus##1`##1=12=^^M=12 > f := x^(3/2) + x + x^(1/2); 3/2 1/2 f := x + x + x
> DEGREE(f,x); 3/2
> h := (x^n + x^(n-1) + x^2) * y^m;
n (n - 1) 2 m h := (x + x + x ) y
> DEGREE(h,x); max(n, 2)
> DEGREE(h,x,y); max(n, 2) + m
plusplus -100 plus
[10,0,0,0,0,0,0,0,1,1]
and as a linked list it is
[10,[0,[0,[0,[0,[0,[0,[0,[0,[1,[1,NIL]]]]]]]]]]].
A more efficient representation for sparse polynomials is to store
just the non-zero terms. Let us store the 'th non-zero
term
as
where
.
Now write procedures to add and multiply sparse univariate polynomials
which are represented as
Write a Maple n-ary procedure GCD that does integer and
symbolic simplification of GCD calculations in .
E.g. on input of GCD(b,GCD(b,a),-a),
your procedure should return GCD(a,b).
For integer inputs, your routine should compute the GCD directly.
For symbolic inputs, your GCD procedure should know the following
Write a Maple procedure monomial(v,n) which
computes a list of the monomials of total degree in the
list of variables
.
For example, monomial([u,v],3) would
return the list
.
Hint: consider the Taylor series expansion of the product
in to order
- see Maple's taylor command.
Given a sequence of points
where the
's are distinct, the Maple library function interp
computes a polynomial of degree
which interpolates the points
using the Newton interpolation algorithm. Write a Maple procedure which
computes a natural cubic spline for the points. A natural cubic spline is a
piecewise cubic polynomial where each interval
is
defined by the cubic polynomial
where the unknown coefficients are uniquely determined by the
following
conditions
These conditions mean that the resulting piecewise polynomial is
continuous.
Write a Maple procedure which on input of the points as a list of
's in the form [x0, y0, x1, y1, ..., xn, yn],
and a variable, outputs a list of the segment
polynomials [f1, f2, ..., fn].
This requires that you create the segment polynomials with unknown
coefficients, use Maple to compute the derivatives and solve the
resulting equations.
For example
=-1.00.5plus##1`##1=12=^^M=12 > spline([0,1,2,3],[0,1,1,2],x);
3 3 2 3 2 [- 1/3 x + 4/3 x, 2/3 x - 3 x + 13/3 x - 1, - 1/3 x + 3 x - 23/3 x + 7]
plusplus -100 plus
Design a data structure for representing a piecewise function. The representation for the piecewise cubic spline above does not interface with other facilities in Maple. Let us represent a piecewise function as an unevaluated function instead as follows. Let
mean

E.g. your procedures should result in the following behaviour.
=-1.00.5plus##1`##1=12=^^M=12 > IF( x<0, sin(x), cos(x) );
IF(x < 0, sin(x), cos(x)) > diff(",x); IF(x < 0, cos(x), - sin(x))
> IF( Pi/3<0, sin(Pi/3), cos(Pi/3) ); 1/2 IF(1/3 Pi < 0, 1/2 3 , 1/2) > evalf("); .5000000000
plusplus -100 plus Modify your IF procedure to simplify nested IF expressions, and to handle constant conditions like the example above. E.g. your IF procedure should result in the following behaviour.
=-1.00.5plus##1`##1=12=^^M=12 > IF( x<0, 0, IF( x<1, x^2, IF(x>2, 0, 1-x^2) ) );
2 2 IF(x < 0, 0, x < 1, x , 2 < x, 0, 1 - x )
> IF( Pi/3<0, sin(Pi/3), cos(Pi/3) );
1/2
plusplus -100 plus
Program this iteration in Maple and check that it converges cubically. Prove that the convergence is cubic.
The command dsolve solves ordinary differential equations analytically, although not all ODE's can be solved in closed form. But it is always possible to obtain a series solution which may be useful. We are given the ODE
and the initial condition and we want to find the first
few terms in the series
Write a Maple procedure which on input of and the initial
condition
constructs a linear system of equations to solve.
I.e. let
substitute this finite sum into the ODE, equate coefficients and solve
for the unknowns . Note, you will want to use the taylor command
to truncate the result to order
. Test your Maple procedure on
the following ODE
You should get the following series
Compute the solution analytically using Maple's dsolve command and check that your series solution agrees with Maple's analytic solution.
Develop a Newton iteration to solve for the series which
converges quadratically. I.e. the
'th approximation
is accurate to . Thus the iteration starts with
and computes
then
and so on. Write a Maple procedure to compute the series.