6 years, 30 days

## Can you index arrays with a loop?...

Maple

I was wondering if you can index arrays in maple with a loop. In MATLAB, you can index all rows and columns in the Matrix, A, with A(:,:), or a portion of the elements such as A(2:10,5:20) to index, or "loop" through these specific elements. In Maple, I am trying to index the following elements, as done in MATLAB with the command

dIdQ(nmid-(imax-1)/2:nmid+(imax-1)/2,1) = -(omega_t(1:imax,1) - omega_1(nmid-imax*jmax-(imax-1)/2:nmid-imax*jmax+(imax-1)/2,1));

Is there a way to convert this matlab code to maple code?

Any help is very appreciated. Thank you!

## Maple to Fortran...

Maple

From the attached code, you can see that I have a Matrix, A, that I am trying to output into Fortran code so that I can simply copy and paste this long matrix into fortran. The output does not look correct. Doesa anyone have an idea on how to put this matrix A into a form that can be easily copy and pasted into Fortran? You can see that I tried to do each line individually in the attatched code but I am really looking for a way to do the entire Matrix. Thanks for any help or suggestions.

## Replacing sub-expressions inside an expr...

Hello,

Attached is my code where the output of interest is the variable X. What I am trying to do is replace anywhere in this expression that I see "sqrt((nx^2+ny^2+nz^2)c^2) by the variable phi in order to make the expression easier to look at and interpret. This should be a relatively easy thing to accomplish, however I have had problems with doing this. Ive tried using algsubs etc. but nothing seems to work. Could anyone show me how to do this? Is there an easy method that works for doing this for similar problems in the future? I have run across this problem before so I would love to know how to solve it for the future. Thanks in advance.

Also pretty new to maple so thanks for your patience.

## How do I display a large matrix properly...

Maple

Hello all,

I am presenting some results in a small meeting tomorrow and I have a rather large symbollic matrix that I was hoping to be able to view in a more readable form (once you see my code, you will see what I mean). This should be a simple fix. Furthermore, when I use the Latex command to recieve code to import into latex, its not working properly, which makes me think I made some kind of mistake. I am really just trying to get this matrix in its full for so that it is easy for other people to read. Thanks for any help.Turns_Latex.mw

 (1)

 \left[ \begin {array}{ccccc} 0&0&0&0&0\\ \noalign{\medskip}-\mu\,  \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt x"),mn("2"))}}}/3 \right) u-1/3\,\mu\, \zeta_{x}\,\zeta_{y}\,v-1/3\,\mu\,\zeta_{x}\,\zeta_{z}\,w&\mu\,  \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt x"),mn("2"))}}}/3 \right) &1/3\,\mu\, \zeta_{x}\,\zeta_{y}&1/3\,\mu\,\zeta_{x}\,\zeta_{z}&0 \\ \noalign{\medskip}-1/3\,\mu\,\zeta_{x}\,\zeta_{y}\,u-\mu\, \left( { \zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt y"),mn("2"))}}}/3 \right) v-1/3\,\mu\, \zeta_{y}\,\zeta_{z}\,w&1/3\,\mu\,\zeta_{x}\,\zeta_{y}&\mu\, \left( { \zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt y"),mn("2"))}}}/3 \right) &1/3\,\mu\, \zeta_{y}\,\zeta_{z}&0\\ \noalign{\medskip}-1/3\,\mu\,\zeta_{x}\,\zeta _{z}\,u-1/3\,\mu\,\zeta_{y}\,\zeta_{z}\,v-\mu\, \left( {\zeta_{x}}^{2} +{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt z"),mn("2"))}}}/3 \right) w&1/3\,\mu\,\zeta_{x}\,\zeta_{z}&1/3\, \mu\,\zeta_{y}\,\zeta_{z}&\mu\, \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2} +{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt z"),mn("2"))}}}/3 \right) &0\\ \noalign{\medskip}-\mu\, \left( {\zeta_ {x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}} _{\mbox {{\tt x"),mn("2"))}}}/3 \right) {u}^{2}-\mu\, \left( {\zeta_{x }}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{ \mbox {{\tt y"),mn("2"))}}}/3 \right) {v}^{2}-\mu\, \left( {\zeta_{x}} ^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{ \mbox {{\tt z"),mn("2"))}}}/3 \right) {w}^{2}-2/3\,\mu\,\zeta_{x}\, \zeta_{y}\,uv-2/3\,\mu\,\zeta_{x}\,\zeta_{z}\,uw-2/3\,\mu\,\zeta_{y}\, \zeta_{z}\,vw+{\frac { \left( -E+2\,{\it UVW} \right) \mu\,\gamma\,  \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2} \right) }{\Pr} }&-{\frac {\mu\,\gamma\, \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta _{z}}^{2} \right) u}{\Pr}}+\mu\, \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2 }+{\zeta_{z}}^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt x"),mn("2"))}}}/3 \right) u+1/3\,\mu\,\zeta_{x}\,\zeta_{y}\,v+1/3\,\mu \,\zeta_{x}\,\zeta_{z}\,w&-{\frac {\mu\,\gamma\, \left( {\zeta_{x}}^{2 }+{\zeta_{y}}^{2}+{\zeta_{z}}^{2} \right) v}{\Pr}}+1/3\,\mu\,\zeta_{x} \,\zeta_{y}\,u+\mu\, \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z} }^{2}+\mbox {{\tt \#msup(mi("zeta}}_{\mbox {{\tt y"),mn("2"))}}}/3  \right) v+1/3\,\mu\,\zeta_{y}\,\zeta_{z}\,w&-{\frac {\mu\,\gamma\,  \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2} \right) w}{\Pr }}+1/3\,\mu\,\zeta_{x}\,\zeta_{z}\,u+1/3\,\mu\,\zeta_{y}\,\zeta_{z}\,v +\mu\, \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}+\mbox {{ \tt \#msup(mi("zeta}}_{\mbox {{\tt z"),mn("2"))}}}/3 \right) w&{\frac {\mu\,\gamma\, \left( {\zeta_{x}}^{2}+{\zeta_{y}}^{2}+{\zeta_{z}}^{2}  \right) }{\Pr}}\end {array} \right]

## Replacing and expression with a variable...

Hello all,

I am trying to replace an expression with a variable using the algsubs command. Basically I have a vector evecA1 where I want to replace everywhere the expression rho*c^2/(gamma-1)*(1/rho)+(1/2)*u^2 occurs by the variable H.  I will post my code so you can see what i was trying to do. Any help is appreciated.

F := [q2, q2^2/q1+(gamma-1)*(q3-q2^2/(2*q1)), q3*q2/q1+(gamma-1)*(q3-q2^2/(2*q1))*q2/q1];
Q := [q1, q2, q3];

with(VectorCalculus);
A := Jacobian(F, Q);

A := subs(q1 = rho, q2 = rho*u, q3 = rho*e, A);
A := subs(e = P/(rho*(gamma-1))+(1/2)*u^2, A);
A := subs(P = rho*c^2/gamma, A);
A := simplify(A);
with(LinearAlgebra);
evalsA := simplify(Eigenvalues(A));
with(LinearAlgebra);
evecA1 := Eigenvectors(A);

algsubs(rho*c^2/(gamma-1)*(1/rho)+(1/2)*u^2 = H, evecAI);

 1 2 Page 1 of 2
﻿