ecterrab

14540 Reputation

24 Badges

20 years, 21 days

MaplePrimes Activity


These are replies submitted by ecterrab

"Is there a convert command that converts a matrix to a tensor"

with(Physics)

 

First of all, even working with matrices, you are working in some space and, in general, using some coordinates, and if working with tensors you use certain type of letters as tensor indices. Suppose it is a 3D Euclidean space, your coordinates are Cartesian, and you want to use lowercase letters as indices; set that:

Setup(dimension = 3, metric = euclidean, coordinates = cartesian, spacetimeindices = lowercase)

[coordinatesystems = {X}, dimension = 3, metric = {(1, 1) = 1, (2, 2) = 1, (3, 3) = 1}, spacetimeindices = lowercaselatin]

(1)

Suppose you have the matrix

Matrix(3, symbol = m)

Matrix(%id = 36893488160498076836)

(2)

To transform it into a tensor, just use the Define command

"Define(M[i,j] = ?)"

{Physics:-Dgamma[a], M[i, j], Physics:-Psigma[a], Physics:-d_[a], Physics:-g_[a, b], Physics:-LeviCivita[a, b, c], Physics:-SpaceTimeVector[a](X)}

(3)

That is all. You can perform all tensor computations with such so defined tensor M[i, j]. Start with its definition

M[definition]

M[i, j] = Matrix(%id = 36893488160443859420)

(4)

Then itscomponents (default is the covariant ones)

M[]

M[a, b] = Matrix(%id = 36893488160444031332)

(5)

The contravariant components are the same as the covariant ones because the space is Euclidean

"M[~]"

M[`~a`, `~b`] = Matrix(%id = 36893488160444044340)

(6)

The trace

M[trace]

m[1, 1]+m[2, 2]+m[3, 3]

(7)

Also via

M[j, j]

M[j, j]

(8)

SumOverRepeatedIndices(M[j, j])

m[1, 1]+m[2, 2]+m[3, 3]

(9)

The determinant

M[determinant]

m[1, 1]*m[2, 2]*m[3, 3]-m[1, 1]*m[2, 3]*m[3, 2]-m[1, 2]*m[2, 1]*m[3, 3]+m[1, 2]*m[2, 3]*m[3, 1]+m[1, 3]*m[2, 1]*m[3, 2]-m[1, 3]*m[2, 2]*m[3, 1]

(10)

The inert representation of this determinant

%M[determinant]

%M[determinant]

(11)

value(%M[determinant])

m[1, 1]*m[2, 2]*m[3, 3]-m[1, 1]*m[2, 3]*m[3, 2]-m[1, 2]*m[2, 1]*m[3, 3]+m[1, 2]*m[2, 3]*m[3, 1]+m[1, 3]*m[2, 1]*m[3, 2]-m[1, 3]*m[2, 2]*m[3, 1]

(12)

The non-zero components

M[nonzero]

M[a, b] = {(1, 1) = m[1, 1], (1, 2) = m[1, 2], (1, 3) = m[1, 3], (2, 1) = m[2, 1], (2, 2) = m[2, 2], (2, 3) = m[2, 3], (3, 1) = m[3, 1], (3, 2) = m[3, 2], (3, 3) = m[3, 3]}

(13)

 "for example to perform basic operations like omega*J*omega where J is the inertia tensor and omega the vector of angular velocity?"

OK. Define your vector now. You can do that directly with Define, or also starting with a Maple Vector constructor

Vector(3, symbol = v)

Vector[column](%id = 36893488160334679084)

(14)

"Define(V[j]=?)"

{Physics:-Dgamma[a], M[i, j], Physics:-Psigma[a], V[j], Physics:-d_[a], Physics:-g_[a, b], Physics:-LeviCivita[a, b, c], Physics:-SpaceTimeVector[a](X)}

(15)

For example, the computation you asked for

V[i]*M[i, j]*V[j]

V[i]*M[i, j]*V[j]

(16)

 

SumOverRepeatedIndices(V[i]*M[i, j]*V[j])

m[1, 1]*v[1]^2+m[1, 2]*v[1]*v[2]+m[1, 3]*v[1]*v[3]+m[2, 1]*v[1]*v[2]+m[2, 2]*v[2]^2+m[2, 3]*v[2]*v[3]+m[3, 1]*v[1]*v[3]+m[3, 2]*v[2]*v[3]+m[3, 3]*v[3]^2

(17)

Another example: operations with the metric

V[a]*g_[a, i]*M[i, j]*g_[j, b]*V[b]

V[a]*Physics:-g_[a, i]*M[i, j]*Physics:-g_[b, j]*V[b]

(18)

Simplify(V[a]*Physics[g_][a, i]*M[i, j]*Physics[g_][b, j]*V[b])

V[i]*M[i, j]*V[j]

(19)

Or products of tensor (underlying matrices) that take the symmetry properties into account

LeviCivita[a, b, c]*V[a]*V[b]

Physics:-LeviCivita[a, b, c]*V[a]*V[b]

(20)

Simplify(Physics[LeviCivita][a, b, c]*V[a]*V[b])

0

(21)

Or other tensor commands

Symmetrize(M[a, b])

(1/2)*M[a, b]+(1/2)*M[b, a]

(22)

Antisymmetrize(M[a, b])

(1/2)*M[a, b]-(1/2)*M[b, a]

(23)

Display components using Physics:-TensorArray

V[i]*M[i, j]

V[i]*M[i, j]

(24)

TensorArray(V[i]*M[i, j])

Array(%id = 36893488160308430716)

(25)

V[k]*M[i, j]

V[k]*M[i, j]

(26)

TensorArray(V[k]*M[i, j], explore)

For all these and more check the large help page (sort-of-manual) (Physics:-Tensors

 

A note on the working space: Physics implements working with several different spaces simultaneously (space + spacetime + .....) - just use different kind of indices for each type of space, and there one kind of space that is generic, which means: arbitrary-symbolic dimension (all the other spaces have specific integer dimension). The metric of such a generic space is Euclidean and represented by Physics:-KroneckerDelta

Setup(genericindices = greek)

[genericindices = greek]

(27)

Define(A[mu], B[mu], C[mu, nu], symmetric)

{A[mu], B[mu], C[mu, nu], Physics:-Dgamma[a], M[i, j], Physics:-Psigma[a], U[a, b, c], V[j], Physics:-d_[a], Physics:-g_[a, b], Physics:-LeviCivita[a, b, c], Physics:-SpaceTimeVector[a](X)}

(28)

C[mu, nu]-C[nu, mu]

C[mu, nu]-C[nu, mu]

(29)

Simplify(C[mu, nu]-C[nu, mu])

0

(30)

 

Download Matrices_as_tensors.mw


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

Hi @Scot Gould 
The message "Unable to log into Maplesoft account: Forbidden (403)" ... Wow ... what on earth is that. And thanks, and for sure, it also helps others sharing the info. When clicking the Maplecloud, are you "signed in"? If so, I'd try "sign out" then try to download a package, then "sign in" again, try ... The "Unable to log into ..." is twice unexpected becase you can install these package also when you are signed out (no need to sign in, nor to be signed in at the time). 

@nm , others
Yes, the design is the same in that Version(), Version(n)Version(Iatest) work the same with Physics:-Version and SupportTools:-Version. You know, 'n' is the version number (for SupportTools, ignore the very first ones). In addition, there is a SupporTools:-Update comand that you can use with 'latest' and 'n' as well.

Hi @Scot Gould , others

I don't own the new, very nice initiative, Maple Customer Support Updates, but it is basically an offspring of the Maplesoft Physics Updates, expected to work in exactly the same way. 

But it seems it didn't, so I'd suggest you an experiment:

  1. Close Maple. Use any file manager to delete the Customer Support Updates from the .../toolbox/2025 directory 
  2. Open Maple, click the 'Maplecloud' icon, then click 'packages', then "Maple Customer Updates", and then that icon on the right of the package's name that is for installing the package.

Does it install? It should. If it didn't then something is wrong. Would you mind please take a couple of minutes with this experiment and confirm? (I just did this in my computer, and it installed fine).

Best!

@Christopher2222 I'm sorry, I have no idea. Although the Physics Updates appeared before 2018, on my computer, I, too, only have the Physics Updates back to Maple 2018, which is when the package appeared for the first time with numbered versions and installed automatically in the Maple/toolbox directory. 

Hi @salim-barzani 
Yes, for sure. What is your question?

@MichalKvasnicka , @Christopher2222
Thanks for the explicit and implicit flattering comments. First of all, related to what I wrote in this post, a new Maplecloud package now exists, advertised today as "The Maple Customer Support Updates." This is Maplesoft's package filling the gap I mentioned in this post, and Physics Updates is now back to "only Physics."

Regarding how The Physics Project has evolved, I find it unfortunate that there were no additional resources for developing this Physics environment, so indeed, at Maplesoft, I worked alone. Almost the same with Maple's dsolve (but for collaboration with Austin Roche, formerly a student I supervised in U.Waterloo and S.Fraser, and M. van Hoeij for linear ODEs) and Maple's pdsolve and all of PDEtools, as well as the FunctionAdvisor, conversion network of mathematical functions, and advanced special functions, etc. What you call a "one-man show". Not ideal, but the range of Physics functionality implemented, I think, is a proof of concept of the validity/utility of this project/development, even if, at the company, I've been working alone.

Then there is that The Physics Project also evolved through significant interactions with Maple users (not Maplesoft employees) as Pascal Szriftgiser, Freddy Baudine, Davide Polvara, Kays Haddad, Jürgen Struckmeier, Scot Gould, Anthony Blacket, William Bauldry, Michael Komma, Peter Groszkowski, Denitsa Staicova ... The list is not small.

What I wrote is also true: depending on availability of time, I intend to put some extra work into developing the Maple Physics package further. By the way you also mentioned the documentation: I think that for Physics it is great, including the pages Physics,Examples, Physics,Tensors, Physics,Mini-Course, Physics,Mechanics, Physics,Updates, etc. But I would like to hear from you if you think otherwise; there is ample room for improvements. Ditto for the existing Physics functionality.

Edgardo S. Cheb-Terrab
Physics, Differential Equations, and Mathematical Functions
Maplesoft Emmeritus
Research and Education—passionate about all that.

There are also relevant, Computer Algebra milestone developments in Physics for Maple 2025 - details are in the post "What is new in Physics in Maple 2025".

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

The Physics package is an integral part of Maple since its first day, many years ago, and also part of Maple 2025 (and hence compatible). The Maplesoft Physics Updates is a different thing: an update distributed through the Maplecloud that updates Physics with new developments and fixes, including fixes for other library parts. Since Maple 2025 just got released, there are - generally speaking - no new developments or bug fixes available. Anyway, I will probably produce a first update for Maple 2025 soon, including some developments that didn't arrive in time for the release of Maple 2025.If time permits also include a fix to this problem just reported.

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

@nm

It is important to remember that dsolve is a top level command that, in several intermediate steps, calls the simplifier, the integrator, and many other operation-commands (factor, series, etc.) In my almost 30 years working with Maple, using it to work on mathematical ideas, I don't recall one occurrence where it was dsolve - itself - hanging.

In this example, you present a problem under simplify. Assuming you use Maple from a worksheet, one useful approach to detecting where the computational flow hangs is to click that "bug" icon, which opens a DEBUG window showing the sequence of steps up to the one where the flow is hanging.

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

@acer 
I see no difference, with or without Physics, which is currently at v.1840 after some fixes in the Student ODE package (see other Mapleprimes answers by Austin Roche). This is what I see, including the line with(Physics)
 

restart

with(PDEtools)

with(LinearAlgebra)

with(Physics)

Physics:-Version()

`The "Physics Updates" version in the MapleCloud is 1840 and is the same as the version installed in this computer, created 2024, December 26, 12:58 hours Pacific Time.`

(1)

with(SolveTools)

undeclare(prime)

`There is no more prime differentiation variable; all derivatives will be displayed as indexed functions`

(2)

declare(u(x, t)); declare(U(xi)); declare(G(xi))

u(x, t)*`will now be displayed as`*u

 

U(xi)*`will now be displayed as`*U

 

G(xi)*`will now be displayed as`*G

(3)

T := xi = -V*t+x; T1 := u(x, t) = U(-V*t+x)*exp(I*(-k*x+t*w+theta))

xi = -V*t+x

 

u(x, t) = U(-V*t+x)*exp(I*(-k*x+t*w+theta))

(4)

P3 := diff(u(x, t), x, t)

diff(diff(u(x, t), t), x)

(5)

``

(6)

P33 := diff(u(x, t), x)

diff(u(x, t), x)

(7)

P333 := diff(P33, t)

diff(diff(u(x, t), t), x)

(8)

NULL


 

Download why_including_with(Physics).mw

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

Hi
It is not that "dsolve generates internal error" in that the problem is not related to dsolve. Starting from your tracelast, this looks like a subtle bug in the logic of IntegrationTools:-Indefinite:-Polynomial that results in calls to factor that keep repeating. Maybe we can include a fix for this problem in one of the next Physics Updates.

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

@vv 
The changes you see in the Updates are in the version of Maple that is under development. From that point of view, no, it is not experimental. In fact this is a Typesetting fix that inadvertently introduced a different problem (bug), reproducible also in the version under development. It is good that @nm noticed it. Regarding Maple 2024, the problem started with v.1835 of the Updates, so entering Physics:-Version(1834), works around the issue. I will upload a solution for Maple 2024 later today.

PS update: the problem is fixed in v.1838.
Edgardo S. Cheb-Terrab
Physics, Differential Equations and Mathematical Functions, Maplesoft

Hi
Thanks for the kind comments. It was a difficult decision, but everything has an end, even an apparently "never-ending" career that has already been long, more successful, and more fun than I could have imagined. 

As Andrew's post says, I will continue to work on existing Maple code, including the Physics package - my first computational project at University - and the Maplesoft Physics Updates, though on a 'have time' basis.

In connection, some people were curious about the cherished projects Andrew mentioned, which I intend to continue developing on a 'have time' basis. They are the most important ones I developed at Maplesoft along all these years. Some symbolic packages, some numerical, lots of technical writing, some looking more like courseware. This is a list of these Maplesoft projects, including the names of co-authors and students that worked on them together, cut from the CV

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

@scallopedpancake 
Your attachment has problems. Try downloading it and you see it doesn't work.

What is needed: a Maple worksheet, termination ".mw" illustrating your problem. Important: The description in the mw needs to tell what you expected and what you received that does not match that - or else what you expected and have no idea of how to get it. And yes, a short example is simpler to follow and so understand than a long one. Thanks.

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

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