Carl Love

Carl Love

28095 Reputation

25 Badges

13 years, 99 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

I find the ColorTools package exceedingly clunky to work with. The design is poor; the APIs are inconsistent. So here is a better version of ColorTools:-RGB24ToName:

RGB24toName:=
     (RGB::And(list(nonnegint), satisfies(L-> nops(L)=3 and max(L) < 256)))->
          ColorTools:-NearestNamedColor(
               RGB, 'metric'= "RGB", 'number'= 1, 'palette'= "all", 'threshold'= 1/255
          )[1][1]
:

Example:

RGB24toName([179, 193, 16]);

     "Resene LaRioja"

I believe that there are some cases where the same triplet of numbers corresponds to two or more different named colors in different palettes. In those cases, my RGB24toName may not return the name that you are expecting.

NearestNamedColor seems exceedingly slow. If that's an issue, I think that I can rewrite it to be faster.

By the way, the mathematical term in English for what you call "reciprocal functions" is inverse functions.

I don't know what exactly has changed regarding writebytes since Maple 12, but it seems like using writebytes to open a file is crude and potentially dangerous. I'd use FileTools:-Text:-Open with its options create, overwrite, and append. It doesn't say at ?writebytes whether or not the I/O is buffered. If it's not buffered, then there's no point in using the command except for the lowest-level programming.

Before you try to use a file in another program, it should be closed by the program that's creating it. This is true in any computer language or system. That filepos happens to work in this case is a quirk and unreliable. Use FileTools:-Text:-Close or simply fclose.

You have at least eight small problems:

1. In the equation assigned to H, you need a multiplication operator immediately after Jx^2.

2. The syntax for the dsolve call should be

nsol:= dsolve({eqs[], ic[]}, numeric);

not

nsol:= dsolve(eqs, ic, numerical);

3. You have seven unknown functions and only six equations. The unknown functions are R, p1, p2, psi, r, theta, and varphi. I guess that r should be R. If I make this correction in equation V:=, it corrects the problem.

4. You have two initial conditions for theta(0). I guess that thetaini should be theta0.

5. You have no initial conditions for psi. I guess that should be psi(0) = psi0.

6. You should use the exp function rather than e. The latter is just considered an unknown variable name.

7. You used a lowercase j rather than an uppercase J in the second subs clause of statement Hyy:=.

8. There is still an unsubstituted Jx somewhere in the system. My guess is that that should be J*sin(psi(t))*cos(varphi(t)).

If I correct all these problems, then the dsolve command runs without error.

Add option complex to the fsolve command. Then the solution is returned almost instantly. By default, fsolve only looks for real solutions.

Suppose that we have a procedure

P:= proc(x) 2*x end proc:

Then, naturally, proc() 2*x end proc() means the same thing as P(). It's natural syntax that's often used to create and invoke an anonymous procedure in one step. The same thing works for procedures defined with the arrow:

(x-> 2*x)(y^2);

map(Limit, f(a+h) - f(a), h= 0);

The change that you noticed must be a bug. The documented changes to the package are listed at ?updates,Maple2016,Logic.

If you construct the matrix correctly, then Maple will know that it's symmetric, and it will make the eigenvalues real. Otherwise, you'll get very small imaginary parts that can be ignored or removed with Re. But it's better to avoid those in the first place.

Example:

restart:
G:= GraphTheory:-RandomGraphs:-RandomGraph(99, .1):
L:= GraphTheory:-LaplacianMatrix(G, datatype= float[8]):
E:= fnormal(LinearAlgebra:-Eigenvalues(L)):
(min,max)(E);

     -0., 20.0828010137594

 

Assuming that you have no interest in the generated file being human readable, then the easiest thing to do is to write and read the matrices in ".m" format. This is Maple's internal format. Essentially the only difference from what you have above is that the format code is %m rather than %a. This format can be used for any Maple data structure, not just matrices.

restart:

file:= FileTools:-Text:-Open(
     "c:/users/owner/desktop/TestMatrices.txt",
     create, overwrite, append
):

n:= 9:   #number  of matrices

for k to n do
     M:= LinearAlgebra:-RandomMatrix(3);
     fprintf(file, "%m\n", M)
end do:

FileTools:-Text:-Close(file);

 

Start a new session, which could be in a different worksheet or even via command-line Maple.

restart:

file:= FileTools:-Text:-Open(
     "c:/users/owner/desktop/TestMatrices.txt"
):

for k while not FileTools:-AtEndOfFile(file) do
     M:= fscanf(file, "%m\n")[];
     printf("%a=%d: %d\n", 'k', k, LinearAlgebra:-Determinant(M))
end do:

k=1: -327244

k=2: -307260
k=3: -570297
k=4: -74874
k=5: 627941
k=6: -821055
k=7: -32964
k=8: 83178
k=9: 441574

FileTools:-Text:-Close(file);

 

Download percent-m_format.mw

 

This is like Kitonum's procedure, but it only displays non-isomorphic graphs, except for n=4. For that n, there is a bug in GraphTheory:-IsIsomorphic. So, for n=4, the procedure displays all 64 "raw" graphs. This procedure takes about 4 minutes for n=6. I wouldn't recommend running it for n=7 or greater. Note that there are over 2 million raw graphs for n=7.

AllGraphs:= proc(n::posint)
uses C= combinat, GT= GraphTheory, LT= ListTools, P= plots;
local  
     Gs:= map2(GT:-Graph, n, [C:-powerset(C:-choose({$1..n},2))[]]),
     NP:= plot(()-> 0, -1..1, color= white, axes= none),
     ng, ns
;    
     if n <> 4 then
          Gs:= map(`?[]`, [LT:-Categorize(GT:-IsIsomorphic, Gs)], [1])
     end if;
     ng:= nops(Gs);
     ns:= ceil(evalf(sqrt(ng)));
     P:-display(Matrix(ns, [GT:-DrawGraph~(Gs, style= circle)[], NP $ ns^2-ng]))     
end proc;

Is your goal to re-import the Matrix into Maple? If so, then use the save command. For example:

A:= LinearAlgebra:-RandomMatrix(31);
save A, "C:/users/owner/desktop/MyMatrix.txt";

To get the Matrix back into Maple, perhaps in another session, do

read "C:/users/owner/desktop/MyMatrix.txt";

This process can be applied to any data structure, not just Matrices.

If your goal is to create a text file that can be read by another program, use the command ExportMatrix. For example,

ExportMatrix("C:/users/owner/desktop/MyMatrix.csv", A, target= csv);

will export your Matrix as comma-separated values (csv). See ?ExportMatrix for the other formats supported.

If you can get the data in a Matrix, it's then trivial to extract the columns from that Matrix. Let's say that the Matrix is named M. If you want the third column of M, you could do

X:= M[.., 3];

 

See ?printlevel. In particular, setting

printlevel:= 2:

will let you see the results of statements within two nested loops or within a loop and a conditional statement.

Edit: I changed to value from 3 to 2.

The command is evalf[2], for example, evalf[2](2.5999).

You need multiplication operators for xyxz, and yz. They should be x*y, etc.

First 217 218 219 220 221 222 223 Last Page 219 of 395