Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 358 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Here's how to create a random real symmetric float matrix with determinant 2:

macro(LA= LinearAlgebra):
n:= 9:
A:= LA:-RandomMatrix(n, datatype= float[8], shape= symmetric):
det:= LA:-Determinant(A):
A:= signum(det)*(2/abs(det))^(1/n)*A;

The major problem with your procedure is that f isn't defined. You've made f local; it should be a parameter.

A second problem is that a parameter can't be indexed. So change p[0] to p0.

A third problem is that a parameter can't (usually) be assigned to. You attempt to assign to p[0]. If you want to update it, then you need to copy it to a local variable.

omega:= (y::function(name))-> y*diff(y, op(y))/op(y):

omega(y(x));


(In the future, please post small worksheets inline as well as attaching them.)

You had many errors, mostly syntax. I don't have time right now to detail all the syntax errors, but I corrected them all. You should carefully compare what I wrote with what you wrote. Many of the changes I made were simply my personal preference syntax rather than correction of errors.

The glaring logic error that you made is

seq(EnergySpacingGUE(1,1), i= 1..10)

The value of n must be smaller than N, because if there are N values, then there are only N-1 spacings. I changed this to

seq(EnergySpacingGUE(i,1), i= 2..11)

but I'm only guessing your intention!

I guess that you realize that a histogram of only ten data points is ridiculous, and that this was only a proof-of-concept case.

restart:
UseHardwareFloats:= true:
GUE:= proc(N::posint)
uses LA= LinearAlgebra, RT= RandomTools;
local
     R:= RT:-Generate(distribution(Normal(0,1)), makeproc),
     G:= 'Matrix((N,N), R, datatype= float[8])' $ 2,
     C:= G[1] + I*~G[2],
     H:= (C + C^*)/~2
;
     convert(LA:-Eigenvalues(H)/~sqrt(4.*N), list)[]
end proc:

EnergySpacingGUE:= proc(N::posint, n::posint)
local
     Eigenvsorted:= sort(Re~([GUE(N)])),
     Spacing:= abs~(Eigenvsorted[..-2] -~ Eigenvsorted[2..])
;
     Spacing[n]*N/`+`(Spacing[])
end proc:
      
data:= [seq(EnergySpacingGUE(i,1), i= 2..10)];

plots:-display([
     plot(32/Pi^2*x*exp(-Pi/4*x^2), x= 0..2),
     Statistics:-Histogram(data, binwidth= 0.05, range= 0..2)
]);

The linestyle option will accept an integer in 0..7 or a list of such integers.

In the vast majority of cases, when you want to sort a list of complex numbers, you want to sort them by absolute value (aka magnitude). Since Maple 18, option key to sort provides an easier, more-intuitive, and more-efficient way to do this than using a comparison procedure as in Kitonum's Answer. Let C be a list or vector of complex numbers. Then do

sort(C, key= evalf@abs);

If the list C is already in floating-point form, that can be shortened to

sort(C, key= abs);

If you want a lexicographic sort, as in Preben's Answer, this can be done using key by

sort(C, key= evalf);

If C is already floating-point, then that can be simply

sort(C);

That's because lexicographic order is the default order for numeric complex constants.

In the place where you've entered the piecewise expression, in the second row, second column, you've entered two inequalities separated by a comma. This isn't valid, yet the despicable 2-D input doesn't catch the error. Instead, it interprets it as a three-row piecewise with nonsense in the second row, first column. Instead of a comma between conditions, you may use the keyword and.

But, you haven't specifed any value for when |x| >= 10; you might as well let the value be 0. It that case, there's no need to even mention the 10. So, the entire piecewise can be entered as

piecewise(abs(x) < 5, -1, 0)

That's the 1-D input. If you want the 2-D input, I'll leave it to you or someone else to translate it.

 

You have two errors. The first is that you need to call GramSchmidt with option normalized. The second is that the line ord:= Basis(...) simply overwrites the results of GramSchmidt. Here's an example of constructing an orthonormal basis starting with the eigenvectors.

restart:
macro(LA= LinearAlgebra):
n:= 5:
A:= LA:-RandomMatrix(n, datatype= float[8]):

#The 2nd return value of Eigenvectors is a matrix whose columns are the eigenvectors.
E:= LA:-Eigenvectors(A)[2]:

#GramSchmidt expects a list of vectors as input, so you need to split E into columns.
#Option 'normalized' is required if you want normalized vectors as output.
G:= LA:-GramSchmidt(['E[..,k]' $ k= 1..n], 'normalized'):

#Form the orthonormalized vectors into a basis matrix.
B:= `<|>`(seq(G[k], k= 1..n)):

#B^* is the conjugate transpose of B. This line is simply verifying that
#B is orthonormal (upto floating-point rounding error).
simplify(fnormal~(B.B^*), zero);

The following nonsensical subexpression occurs seven times in your formula for G:

[7.6613, 8.0102, 8.1790]*[1]

What is it supposed to mean?

The simplest solution is to simply not use gamma as a variable. The next simplest solution is to begin your code with the line

local gamma;

This latter solution will only work in relatively recent versions of Maple.

If either of these solutions is unacceptable, there are still other alternatives.

Zero-point and negative-point users have never appeared on the Users' list in the three years that I've been here. That's why I give zero-point users a vote up every chance I get (except for spammers, of course). Since only Questions, Posts, and Answers can be voted up---and Mcloone has never made any of those---I never had a chance to give him a vote up. Since only Questions, Posts, and Answers get indexed, you won't find him by searching for words from his Comments and Replies.

The following worksheet shows that there are two solutions for N which produce equally minimal residuals and which both lead to n = 14.


restart:

a:= (.0625*N+.0215)/2:

b:= a - .043:

c:= b/(N/2-1)+.0215:

SolN:= [solve(b/c=n, N)]:

nops(SolN);

2

(1)

N:= SolN[1]:

res:= abs(.0645*0.25*(833-(2*N-1)) + n*.043 - sum(sqrt(a^2 - (.043+i*c)^2), i= 1..n)):

plot([seq([k,eval(res, n= k)], k= 1..30)]);

 

eval(res, n= 14);

0.2320950e-1

(2)

eval(N, n= 14);

39.38892063

(3)

N:= SolN[2]:

plot([seq([k,eval(res, n= k)], k= 1..30)]);

 

eval(res, n= 14);

0.2320950e-1

(4)

eval(SolN, n= 14);

[39.38892063, 1.27507937]

(5)

 


Download SolveForN.mw

Yes, it's trivial. For example,

(a,b,c,d):= 'LinearAlgebra:-RandomVector(3)' $ 4:
m:= LinearAlgebra:-LinearSolve(<b|c|d>, a):
#Verify solution:
a = m[1]*b + m[2]*c + m[3]*d;

You just stumbled upon the real assumption, and you assumed that it had something to do with the simplification of the result to 0. But the real assumption is irrelevant. If you simply use simplify(a-c), you will also get 0. In Maple, the expression a - b (for previously stored algebraic expressions a and b) will return 0 if and only if a and b are stored as exactly the same expression. For example:

a:= (x+1)^2:
b:= x^2 + 2*x + 1:

a-b;

simplify(%);

     0

There are many ways in Maple to prove that two algebraic expressions are mathematically equal. This is an oft-debated topic here. Checking that the difference simplifies to 0 is one way. It has been proven that there is no general algorithm for it.

To avoid this error (which I call invalid indirect reference to a procedure parameter), I prefer to use procedures rather than expressions to as great an extent as is feasible (or reasonable). Specifically, in this case, I'd make W1, W2, and W all procedures.

W1:= (A,omega,k)-> A*cos(omega*t-k*x);
W2:= (A,omega,k)-> W1(A,omega,-k);
W:= W1+W2;

SW:= (A,omega,k)->
     plots:-animate(
          plot,
          [[W1,W2,W](A,omega,k), x= -4..4, y= -4..4,
           color= [red,green,blue], scaling= constrained],
          t= 0..5,
          frames= 10
):

SW(2,2*Pi,5);

Note that the sum of two procedures, W1+W2, can be used as a procedure and that a list of procedures, [W1,W2,W], can also be used as a procedure: In both cases, they can be applied to a sequence of arguments.

First 241 242 243 244 245 246 247 Last Page 243 of 395