Product Tips & Techniques

Tips and Tricks on how to get the most about Maple and MapleSim

This is the first of three blog posts about working with data sets in Maple.

In 2013, I wrote a library for Maple that used the HTTP package to access the Quandl data API and import data sets into Maple. I was motivated by the fact that, when I was downloading data, I often used multiple data sources, manually updated data when updates were available, and cleaned or manipulated the data into a standardized form (which left me spending too much time on the data acquisition step).

Simply put, I needed a source for data that would provide me with a searchable, stable data API, which would also return data in a form that did not require too much post-processing.

My initial library had really just scratched the surface of what was possible.

Maple 2015 introduced the new DataSets package, which fully integrated a data set search into core library routines and made its functionality more discoverable through availability in Maple’s search bar.

Accessing online data suddenly became much easier. From within Maple, I could now search through over 12 million time series data sets provided by Quandl, and then automatically import the data into a format that I could readily work with.

If you’re not already aware of this online service, Quandl is an online data aggregator that delivers a wide variety of high quality financial and economic data. This includes the latest data on stocks and commodities, exchange rates, and macroeconomic indicators such as population, inflation, unemployment, and so on. Quandl collects both open and proprietary data sets from many sources, such as the US Federal Reserve System, OECD, Eurostat, The World Bank, and Open Data for Africa. Best of all, Quandl's powerful API is free to use.

One of the first examples for the DataSets package that I constructed was in part based on the inspirational work of Hans Rosling. I was drawn in by his ability to use statistical visualizations to break down complex multidimensional data sets and provide insight into underlying patterns; a key example investigating the correlation between rising incomes and life expectancy.

As well as online data, the DataSets package had a database for country data. Hence it seemed fitting to add an example that explored macroeconomic indicators for several countries. Accordingly, I set out to create an example that visualized variables such as Gross Domestic Product, Life Expectancy, and Population for a collection of countries.

I’ll now describe how I constructed this application.

The three key variables are Gross Domestic Product at Power Purchasing Parity, Life Expectancy, and Population. Having browsed through Quandl’s website for available data sets, the World Bank and Open Data for Africa projects seemingly had the most available relevant data; therefore I chose these as my data sources.

Pulling data for a single country from one of these sources was pretty straight forward. For example, the DataSets Reference for the Open Data for Africa data set on GDP at PPP for Canada is:

DataSets:-Reference("quandl", "ODA/CAN_PPPPC"));

In this command, the second argument is the Quandl data set code. If you are on Quandl’s website, this is listed near the top of the data set page as well as in the last few characters of the web address itself: https://www.quandl.com/data/ODA/CAN_PPPPC . Deconstructing the code, “ODA” stands for Open Data for Africa and the rest of the string is constructed from the three letter country code for Canada, “CAN”, and the code for the GDP and PPP. Looking at a small sample of other data set codes, I theorized that both of the data sources used a standardized data set name that included the ISO-3166 3-letter country code for available data sets. Based on this theory, I created a simple script to query for available data and discovered that there was data available for many countries using this standardized code. However, not every country had available data, so I needed to filter my list somewhat in order to pick only those countries for which information was available.

The script that I had constructed required three letter country codes. In order to test all available countries, I created a table to house the country names and three-letter country codes using data from the built-in database for countries:

ccdata := DataSets:-Builtin:-Reference("country")[.., "3 Letter Country Code"];
cctable := table([seq(op(GetElementNames(ccdata[i])) = ccdata[i, "3 Letter Country Code"], 
i = 1 .. CountRows(ccdata))]):

My script filtered this table, returning a subset of the original table, something like:

Countries := table( [“Canada” = “CAN”, “Sweden” = “SWE”, … ] );

You can see the filtered country list in the code edit region of the application below.

With this shorter list of countries, I was now ready to download some data. I created three vectors to hold the data sets by mapping in the DataSets Reference onto the “standardized” data set names that I pulled from Quandl. Here’s the first vector for the data on GDP at PPP.

V1 := Vector( [ (x) -> Reference("quandl", cat("ODA/", x, "_PPPPC"))
                   ~([entries(Countries, nolist, indexorder)])]):
#Open Data for Africa GDP at PPP

Having created three data vectors consisting of 180 x 3 = 540 data sets, I was finally ready to visualize the large set of data that I had amassed.

In Maple’s Statistics package, BubblePlots can use the horizontal axis, vertical axis and the relative bubble size to illustrate multidimensional information. Moreover, if incoming data is stored as a TimeSeries object, BubblePlots can generate animations over a common period of time.

Putting all of this together generated the following animation for 180 available countries.

This example will be included with the next version of Maple, but for now, you can download a copy here:DataSetsBubblePlot.mw

*Note: if you try this application at home, it will download 540 data sets. This operation plus the additional BubblePlot construction can take some time, so if you just want to see the finished product, you can simply interact with the animation in the Maple worksheet using the animation toolbar.

A more advanced example that uses multiple threads for data download can be seen at the bottom of the following page: https://www.maplesoft.com/products/maple/new_features/maple19/datasets_maple2015.pdf You can also interact with this example in Maple by searching for: ?updates,Maple2015,DataSets

In my next post, I’ll discuss how I used programmatic content generation to construct an interactive application for data retrieval.

Below is the worksheet with the whole material presented yesterday in the webinar, “Applying the power of computer algebra to theoretical physics”, broadcasted by the “Institute of Physics” (IOP, England). The material was very well received, rated 4.5 out of 5 (around 30 voters among the more than 300 attendants), and generated a lot of feedback. The webinar was recorded so that it is possible to watch it (for free, of course, click the link above, it will ask you for registration, though, that’s how IOP works).

Anyway, you can reproduce the presentation with the worksheet below (mw file linked at the end, or the corresponding pdf also linked with all the input lines executed). As usual, to reproduce the input/output you need to have installed the latest version of Physics, available in the Maplesoft R&D Physics webpage.

Why computer algebra?

 

 

 

... and why computer algebra?


We can concentrate more on the ideas instead of on the algebraic manipulations

 

We can extend results with ease

 

We can explore the mathematics surrounding a problem

 

We can share results in a reproducible way

 

Representation issues that were preventing the use of computer algebra in Physics

 

 


Notation and related mathematical methods that were missing:


coordinate free representations for vectors and vectorial differential operators,

covariant tensors distinguished from contravariant tensors,

functional differentiation, relativity differential operators and sum rule for tensor contracted (repeated) indices

Bras, Kets, projectors and all related to Dirac's notation in Quantum Mechanics

 

Inert representations of operations, mathematical functions, and related typesetting were missing:

 

inert versus active representations for mathematical operations

ability to move from inert to active representations of computations and viceversa as necessary

hand-like style for entering computations and textbook-like notation for displaying results

 

Key elements of the computational domain of theoretical physics were missing:

 

ability to handle products and derivatives involving commutative, anticommutative and noncommutative variables and functions

ability to perform computations taking into account custom-defined algebra rules of different kinds

(commutator, anticommutator and bracket rules, etc.)

 

 

Examples

 

The Maple computer algebra environment

   

Classical Mechanics

 

Inertia tensor for a triatomic molecule

   

Classical Field Theory

 

*The field equations for the lambda*Phi^4 model

   

*Maxwell equations departing from the 4-dimensional Action for Electrodynamics

   

*The Gross-Pitaevskii field equations for a quantum system of identical particles

   

Quantum mechanics

 

*The quantum operator components of  `#mover(mi("L",mathcolor = "olive"),mo("→",fontstyle = "italic"))` satisfy "[L[j],L[k]][-]=i `ε`[j,k,m] L[m]"

   

Quantization of the energy of a particle in a magnetic field

   

Unitary Operators in Quantum Mechanics

 

*Eigenvalues of an unitary operator and exponential of Hermitian operators

   

Properties of unitary operators

 

 

Consider two set of kets " | a[n] >" and "| b[n] >", each of them constituting a complete orthonormal basis of the same space.


One can always build an unitary operator U that maps one basis to the other, i.e.: "| b[n] >=U | a[n] >"

*Verify that "U=(&sum;) | b[k] >< a[k] |" implies on  "| b[n] >=U | a[n] >"

   

*Show that "U=(&sum;) | b[k] > < a[k] | "is unitary

   

*Show that the matrix elements of U in the "| a[n] >" and  "| b[n] >" basis are equal

   

Show that A and `&Ascr;` = U*A*`#msup(mi("U"),mo("&dagger;"))`have the same spectrum

   

````

Schrödinger equation and unitary transform

 

 

Consider a ket "| psi[t] > " that solves the time-dependant Schrödinger equation:

 

"i `&hbar;` (&PartialD;)/(&PartialD;t) | psi[t] >=H(t) | psi[t] >"

and consider

"| phi[t] > =U(t) | psi[t] >",

 

where U(t) is a unitary operator.

 

Does "| phi[t] >" evolves according a Schrödinger equation

 "i*`&hbar;` (&PartialD;)/(&PartialD;t) | phi[t] >=`&Hscr;`(t) | phi[t] >"

and if yes, which is the expression of `&Hscr;`(t)?

 

Solution

   

Translation operators using Dirac notation

 

In this section, we focus on the operator T[a] = exp((-I*a*P)*(1/`&hbar;`))

Settings

   

The Action (translation) of the operator T[a]"=(e)^(-i (a P)/(`&hbar;`))" on a ket

   

Action of T[a] on an operatorV(X)

   

General Relativity

 

*Exact Solutions to Einstein's Equations  Lambda*g[mu, nu]+G[mu, nu] = 8*Pi*T[mu, nu]

   

*"Physical Review D" 87, 044053 (2013)

 

Given the spacetime metric,

g[mu, nu] = (Matrix(4, 4, {(1, 1) = -exp(lambda(r)), (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = -r^2, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = -r^2*sin(theta)^2, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = exp(nu(r))}))

a) Compute the Ricci and Weyl scalars

 

b) Compute the trace of

 

"Z[alpha]^(beta)=Phi R[alpha]^(beta)+`&Dscr;`[alpha]`&Dscr;`[]^(beta) Phi+T[alpha]^(beta)"

 

where `&equiv;`(Phi, Phi(r)) is some function of the radial coordinate, R[alpha, `~beta`] is the Ricci tensor, `&Dscr;`[alpha] is the covariant derivative operator and T[alpha, `~beta`] is the stress-energy tensor

 

T[alpha, beta] = (Matrix(4, 4, {(1, 1) = 8*exp(lambda(r))*Pi, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 8*r^2*Pi, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 8*r^2*sin(theta)^2*Pi, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 8*exp(nu(r))*Pi*epsilon}))

c) Compute the components of "W[alpha]^(beta)"" &equiv;"the traceless part of  "Z[alpha]^(beta)" of item b)

 

d) Compute an exact solution to the nonlinear system of differential equations conformed by the components of  "W[alpha]^(beta)" obtained in c)

 

Background: paper from February/2013, "Withholding Potentials, Absence of Ghosts and Relationship between Minimal Dilatonic Gravity and f(R) Theories", by P. Fiziev.

 

a) The Ricci and Weyl scalars

   

b) The trace of "  Z[alpha]^(beta)=Phi R[alpha]^(beta)+`&Dscr;`[alpha]`&Dscr;`[]^(beta) Phi+T[alpha]^(beta)"

   

b) The components of "W[alpha]^(beta)"" &equiv;"the traceless part of " Z[alpha]^(beta)"

   

c) An exact solution for the nonlinear system of differential equations conformed by the components of  "W[alpha]^(beta)"

   

*The Equivalence problem between two metrics

 

 

From the "What is new in Physics in Maple 2016" page:

  

In the Maple PDEtools package, you have the mathematical tools - including a complete symmetry approach - to work with the underlying [Einstein’s] partial differential equations. [By combining that functionality with the one in the Physics and Physics:-Tetrads package] you can also formulate and, depending on the metrics also resolve, the equivalence problem; that is: to answer whether or not, given two metrics, they can be obtained from each other by a transformation of coordinates, as well as compute the transformation.

Example from: A. Karlhede, "A Review of the Geometrical Equivalence of Metrics in General Relativity", General Relativity and Gravitation, Vol. 12, No. 9, 1980

   

*Equivalence for Schwarzschild metric (spherical and Krustal coordinates)

   

Tetrads and Weyl scalars in canonical form

 

 

Generally speaking a canonical form is obtained using transformations that leave invariant the tetrad metric in a tetrad system of references, so that theWeyl scalars are fixed as much as possible (conventionally, either equal to 0 or to 1).

 

Bringing a tetrad in canonical form is a relevant step in the tackling of the equivalence problem between two spacetime metrics.

The implementation is as in "General Relativity, an Einstein century survey", edited by S.W. Hawking (Cambridge) and W. Israel (U. Alberta, Canada), specifically Chapter 7 written by S. Chandrasekhar, page 388:

 

 

`&Psi;__0`

`&Psi;__1`

`&Psi;__2`

`&Psi;__3`

`&Psi;__4`

Residual invariance

Petrov type I

0

"<>0"

"<>0"

1

0

none

Petrov type II

0

0

"<>0"

1

0

none

Petrov type III

0

0

0

1

0

none

Petrov type D

0

0

"<>0"

0

0

`&Psi;__2`  remains invariant under rotations of Class III

Petrov type N

0

0

0

0

1

`&Psi;__4` remains invariant under rotations of Class II

 

 

The transformations (rotations of the tetrad system of references) used are of Class I, II and III as defined in Chandrasekar's chapter - equations (7.79) in page 384, (7.83) and (7.84) in page 385. Transformations of Class I can be performed with the command Physics:-Tetrads:-TransformTetrad using the optional argument nullrotationwithfixedl_, of Class II using nullrotationwithfixedn_ and of Class III by calling TransformTetrad(spatialrotationsm_mb_plan, boostsn_l_plane), so with the two optional arguments simultaneously.

 

The determination of appropriate transformation parameters to be used in these rotations, as well as the sequence of transformations happens all automatically by using the optional argument, canonicalform of TransformTetrad .

 

restart; with(Physics); with(Tetrads)

`Setting lowercaselatin letters to represent tetrad indices `

 

0, "%1 is not a command in the %2 package", Tetrads, Physics

 

0, "%1 is not a command in the %2 package", Tetrads, Physics

 

[IsTetrad, NullTetrad, OrthonormalTetrad, PetrovType, SimplifyTetrad, TransformTetrad, e_, eta_, gamma_, l_, lambda_, m_, mb_, n_]

(7.4.1)

Petrov type I

   

Petrov type II

   

Petrov type III

   

Petrov type N

   

Petrov type D

   

 

 

Physics_2016_IOP_webinar.mw     Physics_2016_IOP_webinar.pdf


Edgardo S. Cheb-Terrab
Physics, Differential Equations and Mathematical Functions, Maplesoft

Maple 2016.1a now available, fixes issues reported here http://www.mapleprimes.com/questions/211561-Why-Does-Maple-20161-Improperly-Treat-X2

Thank you Maplesoft for your quick response to this issue.

An update to Maple 2016 is now available. Maple 2016.1 provides:

  • Updated translations for Simplified and Traditional Chinese,  French, Greek, Japanese, Brazilian Portuguese, and Spanish
  • Updates to the new Maple Workbook
  • Enhancements to Maple’s context-sensitive menus
  • A variety of improvements to the math engine and interface

 

To get this update, use Tools>Check for Updates from within Maple, or visit the Maple 2016.1 downloads page.

 

eithne

 

MapleSim 2016 is here!

MapleSim 2016 provides variety of improvements to streamline the user experience, expand modeling scope, and enhance connectivity with other tools. Here are some highlights:

  • Collapsible task panes provide a larger model workspace, so you can see more of your model at once.
  • Improved layout ensures the tools you need for your current task are available at your fingertips.
  • The expanded Multibody component library now supports contact modeling.
  • A new add-on library, the MapleSim Pneumatics Library from Modelon, supports the modeling and simulation of pneumatic systems.
  • The MapleSim CAD Toolbox has been extended to support the latest versions of Inventor®, NX®, SOLIDWORKS®, CATIA® V5, Solid Edge®, PTC® Creo Parametric™, and more.
  • The MapleSim Connector, which provides connectivity to Simulink®, now supports single precision export of S-functions so you can run your MapleSim models on hardware that only supports single precision.

See What’s New in MapleSim 2016 for more information about these and other improvements.

 

eithne

 

MapleSim 2016 is here!

MapleSim 2016 provides variety of improvements to streamline the user experience, expand modeling scope, and enhance connectivity with other tools. Here are some highlights:

  • Collapsible task panes provide a larger model workspace, so you can see more of your model at once.
  • Improved layout ensures the tools you need for your current task are available at your fingertips.
  • The expanded Multibody component library now supports contact modeling.
  • A new add-on library, the MapleSim Pneumatics Library from Modelon, supports the modeling and simulation of pneumatic systems.
  • The MapleSim CAD Toolbox has been extended to support the latest versions of Inventor®, NX®, SOLIDWORKS®, CATIA® V5, Solid Edge®, PTC® Creo Parametric™, and more.
  • The MapleSim Connector, which provides connectivity to Simulink®, now supports single precision export of S-functions so you can run your MapleSim models on hardware that only supports single precision.

See What’s New in MapleSim 2016 for more information about these and other improvements.

 

eithne

New color schemes for plotting have been added to Maple 2016. They are summarized here. You can also see more details on the plot/colorscheme help pages, which have been reworked (hopefully in a way that makes them more useful to you).

We released a new video a few weeks ago describing one of these features: coloring by value. The worksheet I used for the video is available here: ColorByValueWebinar.mw

 

The mechanism of transport of the material of the sewing machine M 1022 class: mathematical animation.   BELORUS.mw 




I thought I would share some code for computing sparse matrix products in Maple.  For floating point matrices this is done quickly, but for algebraic datatypes there is a performance problem with the builtin routines, as noted in http://www.mapleprimes.com/questions/205739-How-Do-I-Improve-The-Performance-Of

Download spm.txt

The code is fairly straightforward in that it uses op(1,A) to extract the dimensions and op(2,A) to extract the non-zero elements of a Matrix or Vector, and then loops over those elements.  I included a sparse map function for cases where you want to map a function (like expand) over non-zero elements only.

# sparse matrix vector product
spmv := proc(A::Matrix,V::Vector)
local m,n,Ae,Ve,Vi,R,e;
n, m := op(1,A);
if op(1,V) <> m then error "incompatible dimensions"; end if;
Ae := op(2,A);
Ve := op(2,V);
Vi := map2(op,1,Ve);
R := Vector(n, storage=sparse);
for e in Ae do
n, m := op(1,e);
if member(m, Vi) then R[n] := R[n] + A[n,m]*V[m]; end if;
end do;
return R;
end proc:
# sparse matrix product
spmm := proc(A::Matrix, B::Matrix)
local m,n,Ae,Be,Bi,R,l,e,i;
n, m := op(1,A);
i, l := op(1,B);
if i <> m then error "incompatible dimensions"; end if;
Ae := op(2,A);
Be := op(2,B);
R := Matrix(n,l,storage=sparse);
for i from 1 to l do
Bi, Be := selectremove(type, Be, (anything,i)=anything);
Bi := map2(op,[1,1],Bi);
for e in Ae do
n, m := op(1,e);
if member(m, Bi) then R[n,i] := R[n,i] + A[n,m]*B[m,i]; end if;
end do;
end do;
return R;
end proc:
# sparse map
smap := proc(f, A::{Matrix,Vector})
local B, Ae, e;
if A::Vector then
B := Vector(op(1,A),storage=sparse):
else
B := Matrix(op(1,A),storage=sparse):
end if;
Ae := op(2,A);
for e in Ae do
B[op(1,e)] := f(op(2,e),args[3..nargs]);
end do;
return B;
end proc:


As for how it performs, here is a demo inspired by the original post.

n := 674;
k := 6;
A := Matrix(n,n,storage=sparse):
for i to n do
  for j to k do
    A[i,irem(rand(),n)+1] := randpoly(x):
  end do:
end do:
V := Vector(n):
for i to k do
  V[irem(rand(),n)+1] := randpoly(x):
end do:
C := CodeTools:-Usage( spmv(A,V) ):  # 7ms, 25x faster
CodeTools:-Usage( A.V ):  # 174 ms
B := Matrix(n,n,storage=sparse):
for i to n do
  for j to k do
    B[i,irem(rand(),n)+1] := randpoly(x):
  end do:
end do:
C := CodeTools:-Usage( spmm(A,B) ):  # 2.74 sec, 50x faster
CodeTools:-Usage( A.B ):  # 2.44 min
# expand and collect like terms
C := CodeTools:-Usage( smap(expand, C) ):

eulermac(1/(n*ln(n)^2),n=2..N,1);  #Error
Error, (in SumTools:-DefiniteSum:-ClosedForm) summand is singular in the interval of summation


eulermac(1/(n*ln(n)^2+1),n=2..N,1);  #nonsense

 

 

polygon_2_color.mw

Imitation coloring both sides of the polygon in 3d.  We  build a new polygon in parallel with our polygon on a very short distance t. (We need any three points on the polygon plane, do not lie on a straight line.) This place in the program is highlighted in blue.

Paint the polygons are in different colors.

The method of solving underdetermined systems of equations, and universal method for calculating link mechanisms. It is based on the Draghilev’s method for solving systems of nonlinear equations. 
When calculating link mechanisms we can use geometrical relationships to produce their mathematical models without specifying the “input link”. The new method allows us to specify the “input link”, any link of mechanism.

Example.
Three-bar mechanism.  The system of equations linkages in this mechanism is as follows:

f1 := x1^2+(x2+1)^2+(x3-.5)^2-R^2;
f2 := x1-.5*x2+.5*x3;
f3 := (x1-x4)^2+(x2-x5)^2+(x3-x6)^2-19;
f4 := sin(x4)-x5;
f5 := sin(2*x4)-x6;

Coordinates green point x'i', i = 1..3, the coordinates of red point x'i', i = 4..6.
Set of x0'i', i = 1..6 searched arbitrarily, is the solution of the system of equations and is the initial point for the solution of the ODE system. The solution of ODE system is the solution of system of equations linkages for concrete assembly linkage.
Two texts of the program for one mechanism. In one case, the “input link” is the red-green, other case the “input link” is the green-blue.
After the calculation trajectories of points, we can always find the values of other variables, for example, the angles.
Animation displays the kinematics of the mechanism.
MECAN_3_GR_P_bar.mw 
MECAN_3_Red_P_bar.mw

(if to use another color instead of color = "Niagara Dark Orchid", the version of Maple <17)

Method_Mechan_PDF.pdf






The method of solving underdetermined systems of equations, and universal method for calculating link mechanisms. It is based on the Draghilev’s method for solving systems of nonlinear equations. 
When calculating link mechanisms we can use geometrical relationships to produce their mathematical models without specifying the “input link”. The new method allows us to specify the “input link”, any link of mechanism.

Example.
Three-bar mechanism.  The system of equations linkages in this mechanism is as follows:

f1 := x1^2+(x2+1)^2+(x3-.5)^2-R^2;
f2 := x1-.5*x2+.5*x3;
f3 := (x1-x4)^2+(x2-x5)^2+(x3-x6)^2-19;
f4 := sin(x4)-x5;
f5 := sin(2*x4)-x6;

Coordinates green point x'i', i = 1..3, the coordinates of red point x'i', i = 4..6.
Set of x0'i', i = 1..6 searched arbitrarily, is the solution of the system of equations and is the initial point for the solution of the ODE system. The solution of ODE system is the solution of system of equations linkages for concrete assembly linkage.
Two texts of the program for one mechanism. In one case, the “input link” is the red-green, other case the “input link” is the green-blue.
After the calculation trajectories of points, we can always find the values of other variables, for example, the angles.
Animation displays the kinematics of the mechanism.
MECAN_3_GR_P_bar.mw 
MECAN_3_Red_P_bar.mw

(if to use another color instead of color = "Niagara Dark Orchid", the version of Maple <17)

Method_Mechan_PDF.pdf






Disclaimer: This blog post has been contributed by Dr. Nicola Wilkin, Head of Teaching Innovation (Science), College of Engineering and Physical Sciences and Jonathan Watkins from the University of Birmingham Maple T.A. user group*. 

We all know the problem. During the course of a degree, students become experts at solving problems when they are given the sets of equations that they need to solve. As anyone will tell you, the skill they often lack is the ability to produce these sets of equations in the first place. With Maple T.A. it is a fairly trivial task to ask a student to enter the solution to a system of equations and have the system check if they have entered it correctly. I speak with many lecturers who tell me they want to be able to challenge their students, to think further about the concepts. They want them to be able to test if they can provide the governing equations and boundary conditions to a specific problem.

With Maple T.A. we now have access to a math engine that enables us to test whether a student is able to form this system of equations for themselves as well as solve it.

In this post we are going to explore how we can use Maple T.A. to set up this type of question. The example I have chosen is 2D Couette flow. For those of you unfamiliar with this, have a look at this wikipedia page explaining the important details.

In most cases I prefer to use the question designer to create questions. This gives a uniform interface for question design and the most flexibility over layout of the question text presented to the student.

  1. On the Questions tab, click New question link and then choose the question designer.
  2. For the question title enter "System of equations for Couette Flow".
  3. For the question text enter the text

    The image below shows laminar flow of a viscous incompressible liquid between two parallel plates.



    What is the system of equations that specifies this system. You can enter them as a comma separated list.

    e.g. diff(u(y),y,y)+diff(u(y),y)=0,u(-1)=U,u(h)=0

    You then want to insert a Maple graded answer box but we'll do that in a minute after we have discussed the algorithm.

    When using the questions designer, you often find answers are longer than width of the answer box. One work around is to change the width of all input boxes in a question using a style tag. Click the source button on the editor and enter the following at the start of the question

    <style id="previewTextHidden" type="text/css">
    input[type="text"] {width:300px !important}
    </style>


    Pressing source again will show the result of this change. The input box should now be significantly wider. You may find it useful to know the default width is 186px.
  4. Next, we need to add the algorithm for this question. The teacher's answer for this question is the system of equations for the flow in the picture.

    $TA="diff(u(y),y,y) = 0, u(0) = 0, u(h) = U";
    $sol=maple("dsolve({$TA})");


    I always set this to $TA for consitency across my questions. To check there is a solution to this I use a maple call to the dsolve function in Maple, this returns the solution to the provided system of equations. Pressing refresh on next to the algorithm performs these operations and checks the teacher's answer.

    The key part of this question is the grading code in the Maple graded answer box. Let's go ahead and add the answer box to the question text. I add it at the end of the text we added in step 3. Click Insert Response area and choose the Maple-graded answer box in the left hand menu. For the answer enter the $TA variable that we defined in the algorithm. For the grading code enter

    a:=dsolve({$RESPONSE}):
    evalb({$sol}={a}) 


    This code checks that the students system of equations produces the same solution as the teachers. Asking the question in this way allows a more open ended response for the student.

    To finish off make sure the expression type is Maple syntax and Text entry only is selected.
  5. Press OK and then Finish on the Question designer screen.

That is the question completed. To preview a working copy of the question, have a look here at the live preview of this question. Enter the system of equations and click How did I do?

  

I have included a downloadable version of the question that contains the .xml file and image for this question. Click this link to download the file. The question can also be found on the Maple T.A. cloud under "System of equations for Couette Flow".

* Any views or opinions presented are solely those of the author(s) and do not necessarily represent those of the University of Birmingham unless explicitly stated otherwise.

There has been a spate of Questions posted in the past week about computing eigenvalues. Invariably, the Questioners have computed some eigenvalues by applying fsolve to a characteristic polynomial obtained from a floating-point matrix via LinearAlgebra:-Determinant. They are then surprised when various tests show that these eigenvalues are not correct. In the following worksheet, I show that the eigenvalues computed by the fsolve@Determinant method (when applied to a floating-point matrix) are 100% garbage for dense matrices larger than about Digits x Digits. The reason for this is that computing the determinant introduces too much round-off error into the coefficients of the characteristic polynomial. The best way to compute the eigenvalues is to use LinearAlgebra:-Eigenvalues or LinearAlgebra:-Eigenvectors. Furthermore, very accurate results can be obtained without increasing Digits.

 

The correct and incorrect ways to compute floating-point eigenvalues

Carl Love 2016-Jan-18

restart:

Digits:= 15:

macro(LA= LinearAlgebra):

n:= 2^5:  #Try also 2^3 and 2^4.

A:= LA:-RandomMatrix(n):

A is an exact matrix of integers; Af is its floating-point counterpart.

Af:= Matrix(A, datatype= float[8]):

P:= LA:-CharacteristicPolynomial(A, x):

P is the exact characteristic polynomial with integer coefficients; Pf is the floating-point characteristic polynomial computed by the determinant method.

Pf:= LA:-Determinant(Af - LA:-DiagonalMatrix([x$n])):

RP:= [fsolve(P, complex)]:

RP is the list of floating-point eigenvalues computed from the exact polynomial; RPf is the list of eigenvalues computed from Pf.

RPf:= [fsolve(Pf, complex)]:

RootPlot:= (R::list(complexcons))->
     plot(
          [Re,Im]~(R), style= point, symbol= cross, symbolsize= 24,
          axes= box, color= red, labels= [Re,Im], args[2..]
     )
:

RootPlot(RP);

RootPlot(RPf);

We see that the eigenvalues computed from the determinant are completely garbage. The characteristic polynomial might as well have been x^n - a^n for some positive real number a > 1.

 

Ef is the eigenvalues computed from the floating-point matrix Af using the Eigenvalues command.

Ef:= convert(LA:-Eigenvalues(Af), list):

RootPlot(Ef, color= blue);

We see that this eigenvalue plot is visually indistinguishable from that produced from the exact polynomial. This is even more obvious if I plot them together:

plots:-display([RootPlot(Ef, color= blue), RootPlot(RP)]);

Indeed, we can compare the two lists of  eigenvalues and show that the maximum difference is exceedingly small.

 

The following procedure is a novel way of sorting a list of complex numbers so that it can be compared to another list of almost-equal complex numbers.

RootSort:= (R::list(complexcons))-> sort(R, key= abs*map2(`@`, signum+2, Re+Im)):


max(abs~(RootSort(RP) -~ RootSort(Ef)));

HFloat(1.3258049636636544e-12)

 

 

``

 

Download Eigenvalues.mw

First 17 18 19 20 21 22 23 Last Page 19 of 64