Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

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.

It's better to use subscripted variables x[k] rather than concatenated variables xk when there are an indefinite number of them.

fx:= x-> theta*exp(-theta*x);
prod:= product(fx(x[k]), k= 1..n);

In the command I show below, the part Typesetting:-ms(...is undocumented, and thus it could change in a future Maple release.

plot(
     x^2, x= -2..2,
     title= Typesetting:-ms("My favorite plot", color= green),
     titlefont= [TIMES,ROMAN,24]
);

(FC,Fr):= selectremove(has, F, C):
(FL,Fx1):= selectremove(has, Fr, L):
for v in [C, L, x1] do k||v:= collect(F||v/v, v) end do;

Verify correctness:

expand(kC*C + kL*L + kx1*x1 - F);

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