plummie

2 years, 111 days


These are questions asked by plummie

if and for loops (nested)

February 27 2010 by plummie 130 Maple

At the moment I'm trying to find the smallest difference between two things (of form E[i] i goes from 1 to n)  and input them in a list. To do this I need to use nested loops but I'm not sure of the best kind/way to do this. I have been experimenting with for and if loops so far

for instance, this is my most recent effort.
 

for i from 2 to n do;

a := abs(E[i]-E[1]);

for j from 2 to n do;

if i <> j then ;

b := abs(E[i]-E[j]);

end if;

if b < a then a := b end if;

end do;

I have been trying to do this for some while now but am not having much luck.

Basically what I need is a hermitian matrix, with real values on the diagonals X~N(0,1) and complex values on the off diagonals X~N(0,1/2)+i*N(0,1/2)

Obviously as its hermitian I need Xij = Xji*
 

I have tried a few things but can't get anything to work correctly, in my latest attempt I decided to try and construct the 2x2 case from scratch using if and for loops;

for i to n do

for j to n do

if i <> j then

loop within a loop i not equal to j

February 20 2010 by plummie 130 Maple

0

1

I need to write a loop within a loop for something like this;

for i from 1 to n for j from i to n do;
A[i,j]:= rand();
A[j,i]:= A[i,j]

end do; end do;

(just random sample code, not what I need to do)

But I don't want the loop to carry this out for when i=j ie. A[i,i] for i = 1 to n. How can I do this?

I want to generate values which have a N(0,1) distribution (and also some which have a N(0,1/2)+I*N(0,1/2))

I have found the RandomVariable(Normal(0,1)) command but this just tells me things like _R44 and I need the numerical value.

Please can you help? (with both distribution cases)

I have only found rand() which gives me integer values and I need to generate (a lot of)  random rational numbers.

The boundary (0,2) doesn't really matter but I do need the numbers to at least go up to 2. Else any rational will do.

Thankyou.

For instance at the moment I need to write a for loop, with an 'if element' (I assume this can be done with maple)

if the elements satisfy it then I want to add the answer into an array X:=[a1,a2,a3.....] without changing or having to rewrite the data already in X.

Is there any way to do this, or would I have to write the array myself and put all of the elements in at one time?

Currently I have 500 values, I put them in an array x:= [a,b,c,d,.....] then using with(Statistics) plotted my histogram with Histogram(x) but this doesn't give me a very accurate histogram and there are only 10 or so bars. How can I make this better?

I have found eigenvalues of a  2x2 matrix A, these are displayed in a vector. eg.

a + sqrt(b)

a - sqrt(b)

Is there any way I can write code which will find the difference between them? At the moment I'm doing it manually and it is taking a lot of time as I have many matrices.

When i input something like sqrt(30) I just get back 30 with a square root symbol over it. How can I make maple evaluate it?

Gaussian Random Matrices

February 04 2010 by plummie 130 Maple

How do I generate a gaussian random matrix (2x2).

Is this the default setting already in maple or is there code I need to use?

Page 1 of 1