Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

A Complete Guide for Tensors computations using Physics


This is an old request, a complete guide for using Physics  to perform tensor computations. This is it. Feedback on how to improve this presentation is welcome. The Guide, shown below with Setions closed, is linked at the end of this post as a Maple worksheet that allows for reproducing its contents, including all the hyperlinks. Most of the illustrative computations shown are reproducible in Maple 2018.2.1, and a significant part also in previous releases, but to reproduce everything shown below you need to have the Maplesoft Physics Updates version 283 or higher installed. 


Physics  is a package developed by Maplesoft, an integral part of the Maple system. In addition to its commands for Quantum Mechanics, Classical Field Theory and General Relativity, Physics  includes 5 other subpackages, three of them also related to General Relativity: Tetrads , ThreePlusOne  and NumericalRelativity , (work in progress, currently named Cactus) plus one to compute with Vectors , and another related to the Standard Model (also work in progress)..


This material is organized as follows. Section I is complete regarding the functionality for computing with tensors provided with the Physics package, in Classical and Quantum Mechanics (so including Euclidean spaces), Electrodynamics and Special Relativity. The material of section I is also relevant for working with tensors in General Relativity, for which section II is all devoted to curved spacetimes. )(The sub-section on the Newman-Penrose formalism needs to be filled with more material and a new section devoted to the EnergyMomentum tensor is appropriate. I will complete these two things as time permits.) Section III is about transformations of coordinates, relevant in general.


For a alphabetical list of the Physics commands with a brief one-line description and a link to the corresponding help page see Physics: Brief description of each command .


I. Spacetime and tensors in Physics



This section contains all what is necessary for working with tensors in Classical and Quantum Mechanics, Electrodynamics and Special Relativity. This material is also relevant for computing with tensors in General Relativity, for which there is a dedicated Section II. Curved spacetimes .


Default metric and signature, coordinate systems


Tensors, their definition, symmetries and operations



Physics comes with a set of predefined tensors, mainly the spacetime metric  g[mu, nu], the space metric  gamma[j, k], and all the standard tensors of  General Relativity. In addition, one of the strengths of Physics is that you can define tensors, in natural ways, by indicating a matrix or array with its components, or indicating any generic tensorial expression involving other tensors.


In Maple, tensor indices are letters, as when computing with paper and pencil, lowercase or upper case, latin or greek, entered using indexation, as in A[mu], and are displayed as subscripts as in A[mu]. Contravariant indices are entered preceding the letter with ~, as in A[`~μ`], and are displayed as superscripts as in A[`~mu`]. You can work with two or more kinds of indices at the same time, e.g., spacetime and space indices.


To input greek letters, you can spell them, as in mu for mu, or simpler: use the shortcuts for entering Greek characters . Right-click your input and choose Convert To → 2-D Math input to give to your input spelled tensorial expression a textbook high quality typesetting.


Not every indexed object or function is, however, automatically a tensor. You first need to define it as such using the Define  command. You can do that in two ways:



Passing the tensor being defined, say F[mu, nu], possibly indicating symmetries and/or antisymmetries for its indices.


Passing a tensorial equation where the left-hand side is the tensor being defined as in 1. and the right-hand side is a tensorial expression - or an Array or Matrix - such that the components of the tensor being defined are equal to the components of the tensorial expression.


After defining a tensor - say A[mu] or F[mu, nu]- you can perform the following operations on algebraic expressions involving them


Simplify  products using Einstein's sum rule for repeated indices.


SumOverRepeatedIndices  of the tensorial expression.


Use TensorArray  to compute the expression's components


TransformCoordinates .


If you define a tensor using a tensorial equation, in addition to the items above you can:



Get each tensor component by indexing, say as in A[1] or A[`~1`]


Get all the covariant and contravariant components by respectively using the shortcut notation A[] and "A[~]".


Use any of the special indexing keywords valid for the pre-defined tensors of Physics; they are: definition, nonzero, and in the case of tensors of 2 indices also trace, and determinant.


No need to specify the tensor dependency for differentiation purposes - it is inferred automatically from its definition.


Redefine any particular tensor component using Library:-RedefineTensorComponent


Minimizing the number of independent tensor components using Library:-MinimizeTensorComponent


Compute the number of independent tensor components - relevant for tensors with several indices and different symmetries - using Library:-NumberOfTensorComponents .


The first two sections illustrate these two ways of defining a tensor and the features described. The next sections present the existing functionality of the Physics package to compute with tensors.


Defining a tensor passing the tensor itself


Defining a tensor passing a tensorial equation


Tensor symmetries


Substituting tensors and tensor indices


Simplifying tensorial expressions




Visualizing tensor components - Library:-TensorComponents and TensorArray


Modifying tensor components - Library:-RedefineTensorComponent


Enhancing the display of tensorial expressions involving tensor functions and derivatives using CompactDisplay


The LeviCivita tensor and KroneckerDelta


The 3D space metric and decomposing 4D tensors into their 3D space part and the rest


Total differentials, the d_[mu] and dAlembertian operators


Tensorial differential operators in algebraic expressions


Inert tensors


Functional differentiation of tensorial expressions with respect to tensor functions


The Pauli matrices and the spacetime Psigma[mu] 4-vector


The Dirac matrices and the spacetime Dgamma[mu] 4-vector


Quantum not-commutative operators using tensor notation


II. Curved spacetimes



Physics comes with a set of predefined tensors, mainly the spacetime metric  g[mu, nu], the space metric  gamma[j, k], and all the standard tensors of general relativity, respectively entered and displayed as: Einstein[mu,nu] = G[mu, nu],    Ricci[mu,nu]  = R[mu, nu], Riemann[alpha, beta, mu, nu]  = R[alpha, beta, mu, nu], Weyl[alpha, beta, mu, nu],  = C[alpha, beta, mu, nu], and the Christoffel symbols   Christoffel[alpha, mu, nu]  = GAMMA[alpha, mu, nu] and Christoffel[~alpha, mu, nu]  = "GAMMA[mu,nu]^(alpha)" respectively of first and second kinds mentioned in the previous section. The Tetrads  and ThreePlusOne  subpackages have other predefined related tensors. This section is thus all about computing with tensors in General Relativity.


Loading metrics from the database of solutions to Einstein's equations


Setting the spacetime metric indicating the line element or a Matrix


Covariant differentiation: the D_[mu] operator and the Christoffel symbols


The Einstein, Ricci, Riemann and Weyl tensors of General Relativity


A conversion network for the tensors of General Relativity


Tetrads and the local system of references - the Newman-Penrose formalism


The ThreePlusOne package and the 3+1 splitting of Einstein's equations


III. Transformations of coordinates


See Also


Physics , Conventions used in the Physics package , Physics examples , Physics Updates





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


Does maple have the ability to create probability trees / branch plots? (representing a sample space).  I would like to represent a problem more elegantly while learning how to use the software.  For example, a sample space that can be represented could be a coin toss.

Recently, my research team at the University of Waterloo was approached by Mark Ideson, the skip for the Canadian Paralympic men’s curling team, about developing a curling end-effector, a device to give wheelchair curlers greater control over their shots. A gold medalist and multi-medal winner at the Paralympics, Mark has a passion to see wheelchair curling performance improve and entrusted us to assist him in this objective. We previously worked with Mark and his team on a research project to model the wheelchair curling shot and help optimize their performance on the ice. The end-effector project was the next step in our partnership.

The use of technology in the sports world is increasing rapidly, allowing us to better understand athletic performance. We are able to gather new types of data that, when coupled with advanced engineering tools, allow us to perform more in-depth analysis of the human body as it pertains to specific movements and tasks. As a result, we can refine motions and improve equipment to help athletes maximize their abilities and performance. As a professor of Systems Design Engineering at the University of Waterloo, I have overseen several studies on the motor function of Paralympic athletes. My team focuses on modelling the interactions between athletes and their equipment to maximize athletic performance, and we rely heavily on Maple and MapleSim in our research and project development.

The end-effector project was led by my UW students Borna Ghannadi and Conor Jansen. The objective was to design a device that attaches to the end of the curler’s stick and provides greater command over the stone by pulling it back prior to release.  Our team modeled the end effector in Maple and built an initial prototype, which has undergone several trials and adjustments since then. The device is now on its 7th iteration, which we felt appropriate to name the Mark 7, in recognition of Mark’s inspiration for the project. The device has been a challenge, but we have steadily made improvements with Mark’s input and it is close to being a finished product.

Currently, wheelchair curlers use a device that keeps the stone static before it’s thrown. Having the ability to pull back on the stone and break the friction prior to release will provide great benefit to the curlers. As a curler, if you can only push forward and the ice conditions aren’t perfect, you’re throwing at a different speed every time. If you can pull the stone back and then go forward, you’ve broken that friction and your shot is far more repeatable. This should make the game much more interesting.

For our team, the objective was to design a mechanism that not only allowed curlers to pull back on the stone, but also had a release option with no triggers on the curler’s hand. The device we developed screws on to the end of the curler’s stick, and is designed to rest firmly on the curling handle. Once the curler selects their shot, they can position the stone accordingly, slide the stone backward and then forward, and watch the device gently separate from the stone.

For our research, the increased speed and accuracy of MapleSim’s multibody dynamic simulations, made possible by the underlying symbolic modelling engine, Maple, allowed us to spend more time on system design and optimization. MapleSim combines principles of mechanics with linear graph theory to produce unified representations of the system topology and modelling coordinates. The system equations are automatically generated symbolically, which enables us to view and share the equations prior to a numerical solution of the highly-optimized simulation code.

The Mark 7 is an invention that could have significant ramifications in the curling world. Shooting accuracy across wheelchair curling is currently around 60-62%, and if new technology like the Mark 7 is adopted, that number could grow to 70 or 75%. Improved accuracy will make the game more enjoyable and competitive. Having the ability to pull back on the stone prior to release will eliminate some instability for the curlers, which can help level the playing field for everyone involved. Given the work we have been doing with Mark’s team on performance improvements, it was extremely satisfying for us to see them win the bronze medal in South Korea. We hope that our research and partnership with the team can produce gold medals in the years to come.


Hi guys,

I have got serious problem with solving this system of ODE, where psi is equal to 10*sqrt(da) and uB,E,kL,uc are constants:

firstly I have to find missing initial condition using shooting method and calculate cA(z=2) using Runge-Kutta 4th order then. And plot following concentration profile for cA and dA. So far, I have dealt with first diff eq 2nd order dividing by two diff eq of 1st order using mentioned constants so I got these ones:


I understand I need a condition da(z=0) that I should obtain using shooting method, but I do not know how to do it in spite of I understand it in theoretical way. And same problem I have with RK4th order. Anybody here with a hint, please? 

There is my maple file (unfinished version of mine):

Why Maple doesn't calculate this and only rewrites it??



invlaplace(exp((0.2500000000e-1-2.500000000*sqrt(0.116e-3+.8*p-3.2*10^(-10)/(p+0.2e-4)))*x)/p, p, t);

`&x` := proc (x, y) options operator, arrow; 2*x+3*y end proc;

`&x`(a, b);

[x[1], y[1]]+[x[2], y[2]];
                   [x[2] + x[1], y[2] + y[1]]
'&.':=proc(u,v)  eval([u[1]*v[1]-u[2]*v[2]],[u[1]*v[2]+u[2]*v[1]]  end proc:
Error, unable to match delimiters

  primeAssignproc(ucommav)  evallpar(u(1)sdotv(1) - u(2)sdotv(2))

  comma(u(1)sdotv(2) + u(2)sdotv(1))  end proccolon,

  Typesetting:-merror("unable to match delimiters")))
&. ([x[1],y[1]],[x[2],y]]);
Error, unable to match delimiters

     ampperiod lpar(x(1)y(1))comma(x(2)commay)rsqbrparsemi,

     Typesetting:-merror("unable to match delimiters")))
f := proc (x1, y1, x2, y2) options operator, arrow; x1*x2-y1y2 end proc;
(x1, y1, x2, y2) -> x1 x2 - y1y2
f := proc (x1, y1, x2, y2) options operator, arrow; x1*x2-y1y2, x1*y2+y1*x2 end proc;
(x1, y1, x2, y2) -> x1 x2 - y1y2, x1 y2 + y1 x2


I am on a Mac and unable to login to MapleCloud. I can log in perfectly fine via the website in all browsers. Any solutions for this?


How to simplify


to b=c ?


I try to simulate the sum of two dice, and display the frequencies of the apparitions (in order 2,3,..12). Is my approach good? can generalize the approch to several dices?

Thanks for your help


Hi every body:

How can I solve this equation with Trapezoidal Rule in Maple? 

u(x) = 1+int(x*t*u(t), t = 0 .. 1)


I have a procedure that changes the value of an input variable quite unexpectdly. Can anyone explain why? I have a very simplified example of this below.

switch := proc (V::Vector)
description "This procedure is supposed to take a Vector V and switch entries 1 and 2";
local W,a,b;
W:= V;
a:= W[1];
b:= W[2];
W[1 ] := b;  
W[2] :=a;
end proc;

I have omitted the output for brevity's sake but all works well as expected.

returns V2 not V1. Why is the procedure changing V1?

The problem occurs with matrices but not with lists.




Hello there,

for academic purposes I need to solve a pretty complex and substantial non-linear equation system. Here you can have a look at the equations:

The MAPLE Statement "fsolve" is not working here, though there is no error message. I know, that I can provide a framework for each variable to help fsolve find a solution. But for my usage this is not an appropriate task, since I'd like to do some simulations and variations with the input parameters.

Is there a way, so I can find a solution to my equation system?


It would be possible to make some adjustments to my equations, e.g. reducing the complexity of the equations and increasing the number of equations at the same time, if needed.

I would appreciate any advice!

Thanks in advance!

if V=(u(x,y,t),v(x,y,t),0) is vector field ( x,y space, t is time), how can find gradient of V in maple ?

iqt + aqxy + ibq (qq*x − q*qx) = 0. write this equation in maple

In the worksheet below I produce a sequence of frames for an animation by distributing the task into several threads.  The result has strange artifacts as we see in the sample.  The artifacts vary randomly from run to run.  Am I doing something wrong?



`Maple 2018.2, X86 64 LINUX, Oct 23 2018, Build ID 1356656`



Draw a simple picture:

frame := proc(t)
  plot(x^2 + t, x=-1..1, title=typeset("t = %1", t));
end proc:

Generate a sequence of pictures:

frames := Threads:-Seq(frame(t), t=0..1, 0.05):

Animate the sequence:

plots:-display([frames], insequence);


1 2 3 4 5 6 7 Last Page 1 of 1501