acer

32490 Reputation

29 Badges

20 years, 8 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

In case the body of the message is once again deleted, here is the original:

Meanwhile, thank you so much for everything.
I know I'm asking a lot but if you have time, you can help me do this?

Building a system of interactive components that, taken a function, two points 'a' and 'b' values ​​and an integer n, the calculations point between a and b in which the function assumes the minimum value by using the following procedure:

• It divides the values ​​between a and b into n equal parts (these will distance the one with the other (b-n)/2);
• calculates the function in each of these points;
• located between these values,  what is the minimum (in case of a tie, take the one closest to a)

I think i have to create a vector for each  part and  prehaps with a fcycle for, calculate the function, finelly i'll use minimize with all function.
Do you think is the correct procedure? If yes, how can I do it?

@abdulganiy 

Here are two ways. (I have opted for simplicity over efficiency.)

Note that they appear the same in the actual Maple 2016 GUI. The first one looks different below because this site's backend engine is old and doesn't render style=pointline properly.
 

restart;

B:=<<150,200,300,600,800,1600,2400,3200>
     |<1.23E-2,5.694E-3,3.134E-4,1.259E-7,1.264E-7,4.947E-10,1.931E-11,1.994E-12>
     |<170,225,381,680,1207,2144,3806,6762>
     |<2.886E-1,7.846E-3,1.399E-3,1.690E-4,1.846E-5,1.938E-6,1.993E-7,2.021E-8>
     |<277,496,884,1573,2796,4970,8833,15706>
     |<2.153E0,1.494E-1,9.359E-3,6.2E-4,4.416E-5,3.412E-6,2.848E-7,2.530E-8>>:

for i from 1 to 8 do
   B[i,2] := log(B[i,2]):
   B[i,4] := log(B[i,4]):
   B[i,6] := log(B[i,6]):
end do:

# One way, motivated because the legend items for style=pointline
# show just a line.

plot([B[.., [1, 2]], B[1..1, [1, 2]],
      B[.., [3, 4]], B[1..1, [3, 4]],
      B[.., [5, 6]], B[1..1, [5, 6]]],
     legend = ["", TSDM,
               "", FESDIRK4,
               "", ESDIRK4],
     colour = [blue, blue, green, green, red, red],
     style = [pointline, point, pointline, point, pointline, point],
     symbol = [solidcircle, solidcircle, diamond, diamond, box, box],
     symbolsize = 10,
     size = [500,500],
     axis = [gridlines = [colour = green, majorlines = 2, linestyle = dot]]);

# Another way is just to do all the points in style=line,
# and all the points in style=point. It's similar.
# This is what you'd have to do in old versions that didn't
# have style=pointline.

plot([B[.., [1, 2]], B[.., [1, 2]],
      B[.., [3, 4]], B[.., [3, 4]],
      B[.., [5, 6]], B[.., [5, 6]]],
     legend = ["", TSDM,
               "", FESDIRK4,
               "", ESDIRK4],
     colour = [blue, blue, green, green, red, red],
     style = [line, point, line, point, line, point],
     symbol = [solidcircle, solidcircle, diamond, diamond, box, box],
     symbolsize = 10,
     size = [500,500],
     axis = [gridlines = [colour = green, majorlines = 2, linestyle = dot]]);

 


 

Download pointlinelegend.mw

People who have seen it are prevented by nondisclosure agreements/clauses from describing its features.

Since this is close to the time of year when Maplesoft traditionally announces new major versions of Maple then I would say it's far too late to make suggestions for significant new features or enhancements to Maple 2017. But it might be a good time to start making suggestions about Maple 2018.

My strong preference on platform is 64bit Linux for modern Maple, followed by 64bit Windows 7. I base that on reasonably extensive performance investigations combined with stability. By far my last choice of platform for modern Maple is now 32bit Windows (of any numbered release).

@mehdibaghaee Upon  arriving home I discovered that I actually possess the book that I mention, by Higham.

For the general nonsymmetric Matrix it suggests two choices for computing the principal square root: one using a Schur decomposition (which Maple should do quickly as its already implemented as a single CLAPACK call), and the other using an iterated Newton approach (which is simple in that it consists mostly of matrix multiplication and powering, but to be efficient the in-place workspace Matrices might need care).

But for the symmetric-definite case the Schur decomposition approach boils down to something much simpler. Namely, do the spectral decomposition A=QDQ* (D being diagonal from lambda[i] and Q unitary) and then just compute sqrt(A) as Q.diag(sqrt(lambda[i])).Q* . Higham details a few other approaches, but this seems enough to start with.

It's the start of March break. I'll let you know when get a bit of time for it. How fast do you expect it to be, roughly, for say cases 200x200 and 1000x1000?

@mehdibaghaee The mathematics behind efficient floating-point computation of various "Matrix Functions" is quite specialized. Maple has a somewhat efficient and specialized routine for computing the "Matrix exponential" for real float Matrices, but that's about it. Nick Higham has written a book on the topic, several papers, and even a Matlab toolbox for it. It's quite complicated in general.

I mentioned earlier that Maple uses the (non-free for commercial use, Tom) highly optimized Intel MKL versions of LAPACK and BLAS in order to get competitively performing real float linear system and eigen system solving. And that's what Matlab and Mathematica use too. But Matrix functions are another thing.

Let me repeat a question, though: for what purpose do you need the "square root" of a Matrix. I'm interested to know, because it doesn't come up that often. Much more common are, say the Cholesky or LDL decompositions (which are covered by LAPACK).

I could also mention, regarding Tom's comments, that another reason people like to access things like LAPACK and BLAS from within the Three M's commerical products is that those products provide interactive, rich, and interpreted environments, with no need for repeatedly compiling drivers, accessing additional plotting facilities, etc. So for some people they are one-stop shops, while for others they make for convenient prototyping environments. That's not news.

@abdulganiy Please don't post the same question more than once.

In the actual Maple GUI those three curves appear with pointline style. The only reason they don't do so below is that this site's backend engine is old and out-of-date.

The key thing is that the colors and symbols in the legend match those on the curves (in Maple).
 

restart;

f1:=sin(x):
f2:=sin(x)/x:
f3:=sin(x)*x:

a,b := -2*Pi,2*Pi:

plots:-display(

  plot(f1, x=a..b, color=red, legend="",
       style=pointline, symbol=cross, symbolsize=10,
       adaptive=false, numpoints=30),
  plot([[a, eval(f1,x=a)]], color=red, legend=f1,
       style=point, symbol=cross, symbolsize=10),

  plot(f2, x=a..b, color=blue, legend="",
       style=pointline, symbol=box, symbolsize=10,
       adaptive=false, numpoints=30),
  plot([[a, eval(f2,x=a)]], color=blue, legend=f2,
       style=point, symbol=box, symbolsize=10),

  plot(f3, x=a..b, color=green, legend="",
       style=pointline, symbol=solidcircle, symbolsize=10,
       adaptive=false, numpoints=30),
  plot([[a, eval(f3,x=a)]], color=green, legend=f3,
       style=point, symbol=solidcircle, symbolsize=10),

  size=[500,500]
);


 

Download pointlegend.mw

@sand15athome I suspect that expanding the result from int, even after preliminary conversion to Heaviside, could be lead to similar double precision overflow and underflow, etc. That is to say, I suspect that the fortune lies in how the terms like exp calls are combined that allows this way to (happen to) work. It may be relatively fragile, then, as a general approach to such problematic examples.

Are you using Matlab on float data? If so then note that Matlab will be doing hardware double precision float computations. To get comparable performance in Maple for linear system solving or eigensolving make sure that you have float data and Digits is not set higher than 15. For example, apply evalf to the data first (or cast Matrices and Vectors to datatype =float [8] ).

Are you sure that you really want the "square root" of a Matrix, as opposed say to the Cholesky decomposition? Or some related decomposition? Is the data symmetric?

@sand15 Well, for redirection to an text file the bold markup will of course depend on what you intend on using to view that "report" later on. You could use ANSI escape sequences, or RTF, or HTML.

As far as left-alignment of what gets printed in the Maple Standard GUI, printf would get that but it would not respect any markup (which would get line-printed, not what you want). Note that left-alignment is a paragraph property. I do not recall that it can be set as a style-sheet preference. So, how might one build upon my previous code, to get left-aligned printed output? The DocumentTools:-Layout commands can produce such. With a little live-surgery the DocumentTools:-Tabulate command can be made to do it too. Here are some ideas. leftaligned.mw

@Jalale You could also call Explore on Kitonum's procedure. Eg,

restart;

# Kitonum's procedure, with minor adjustment for
# cases that h=0.0 or h=2.0 (to avoid Warning)
#
ConeInSphere:=proc(h::numeric,
                   Cone::list:=[style=surface, color="Green"],
                   Sphere::list:=[color=pink, transparency=0.5])
local R, A, B, C;
uses plottools, plots;
R:=sqrt(1-(h-1)^2);
if h>0.0 and h<2.0 then
  # The base of the cone
  A:=plot3d([r*cos(t),r*sin(t),1-h], r=0..R, t=0..2*Pi, op(Cone)):
  # Lateral surface of the cone
  B:=plot3d([r*cos(t),r*sin(t),-h/R*r+1], r=0..R, t=0..2*Pi,op(Cone)):
else
  A:=NULL; B:=NULL;
end if;
C:=plottools:-sphere(op(Sphere)):
plots:-display(A, B, C, axes=normal,
               view=[-1.2..1.2,-1.2..1.2, -1.2..1.4],
               scaling=constrained);
end proc:

Explore(ConeInSphere(h,[style=surface,color="Cyan"],
                     [color="Yellow",transparency=0.7]),
        parameters=[h=0.0 .. 2.0],
        initialvalues=[h=1.0],
        size=[600,600]);

What do you intend the amplitude to represent? Power?

The body of this Question keeps being deleted. Here is the original title and question:

Crypt and decrypt with Vigenère

ConvertToNumbers:=proc(L::list)
local i,M;
M:=[];
for i from 1 to nops(L) do
M:=[op(M),StringTools[Ord](L[i])-96];
if M[i]>26 or M[i]<0 then M[i]:="Errore"; end if;
end do;
return M;
end proc;

ConvertToLetters:=proc(L::list)
local i,M;
M:=[];
for i from 1 to nops(L) do
if L[i]>26 or L[i]<0 then M:=[op(M),"Errore"]; end if;
M:=[op(M),StringTools[Char](L[i]+96)];
end do;
return M;
end proc;

I wrote this proc because i need to create an interactive component that crypt and decrypt with vigenere.
(procedures need lists)

"In a Caesar cipher, each letter of the alphabet is shifted along some number of places; for example, in a Caesar cipher of shift 3, A would become D, B would become E, Y would become B and so on. The Vigenère cipher consists of several Caesar ciphers in sequence with different shift values.

To encrypt, a table of alphabets can be used, termed a tabula recta, Vigenère square, or Vigenère table. It consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar ciphers. At different points in the encryption process, the cipher uses a different alphabet from one of the rows. The alphabet used at each point depends on a repeating keyword.[citation needed]

For example, suppose that the plaintext to be encrypted is:

ATTACKATDAWN
The person sending the message chooses a keyword and repeats it until it matches the length of the plaintext, for example, the keyword "LEMON":

LEMON
Each row starts with a key letter. The remainder of the row holds the letters A to Z (in shifted order). Although there are 26 key rows shown, you will only use as many keys (different alphabets) as there are unique letters in the key string, here just 5 keys, {L, E, M, O, N}. For successive letters of the message, we are going to take successive letters of the key string, and encipher each message letter using its corresponding key row. Choose the next letter of the key, go along that row to find the column heading that matches the message character; the letter at the intersection of [key-row, msg-col] is the enciphered letter.

For example, the first letter of the plaintext, A, is paired with L, the first letter of the key. So use row L and column A of the Vigenère square, namely L. Similarly, for the second letter of the plaintext, the second letter of the key is used; the letter at row E and column T is X. The rest of the plaintext is enciphered in a similar fashion:

Plaintext:	ATTACKATDAWN
Key:	LEMON
Ciphertext:	LXFOPVEFRNHR
Decryption is performed by going to the row in the table corresponding to the key, finding the position of the ciphertext letter in this row, and then using the column's label as the plaintext. For example, in row L (from LEMON), the ciphertext L appears in column A, which is the first plaintext letter. Next we go to row E (from LEMON), locate the ciphertext X which is found in column T, thus T is the second plaintext letter."

I think that it can be done with a for loop but I do not know where to start.

Thanks in advance!

@Djboyko It's not clear what is in the DIMMatrix Matrix at the moment that the eigenvalues are computed. You call fprintf with %f format, but you are also calling `simplify`. Is the Matrix purely floating-point, when the eigenvalues are computed? If not then cannot you make it so, using evalf or evalhf?

Are you calling linalg[eigenvalues], and if so then why not LinearAlgebra:-Eigenvalues?

If the Matrix can be cast to purely floats, then is it symmetric? If so then casting the Matrix to one with shape=symmetric and datatype=float[8] will allow all the result to be purely real floats (and pre-sorted) if compute with LinearAlgebra:-Eigenvalues.

LinearAlgebra:-Eigenvalues wil also use hardware double-precision (by default, if Digits<=15). And linalg[eigenvalues] will only use something similar (an evalhf internal routine), and only if the input is all floats. But the former is faster because it uses a multi-threaded and optimized compiled LAPACK & BLAS. And only the former has a better variant for the symmetric case.

If the Matrix can be cast to purely floats (using evalf at least, say) then you'll also likely get a faster and more accurate and robust result than if you allow it to to an exact symbolic computation (where the exact symbolic results are turned into floats only when you invoke fprintf with the %f format).

I don't understand your 0.2 and 0.005 notation. Is that something related to accuracy, and if so then what does it mean?

Why not upload a worksheet that shows what the Matrix consists of? (Before `kx` and `ky` get realcons values would be OK).

How big is the Matrix?

When you say that you have to make an interactive component do you mean something that simply lets the user enter message and key in text-boxes, and which just displays the result in another text-box? In that scenario you'd mostly just need procedures that do the encryption and decryption.

Or do you mean something more illustrative of how the Vigenere cipher works? For example, something that shows (progressing character-by-character according to some button press, say) the column and row and intersection in a displayed graphical element containing the tabula recta?

@vv Ok, I now believe that the original expression is  -2*a^23*h^40*o*v^2 + 2*a^23*h^40*v^3 .

Sorry for being a doubter. I had to do it myself...   ;)

First 287 288 289 290 291 292 293 Last Page 289 of 595