Joe Riel

9530 Reputation

23 Badges

20 years, 27 days

MaplePrimes Activity


These are answers submitted by Joe Riel

I'm not sure what you want, but the following code might do just that:

A:=[[a,b],[b,c],[b,c,c],[d,c,c]]:
f := proc(a,b) evalb(a[2..]=b[2..]) end proc:
ListTools:-MakeUnique(A,f);
                                  [[a, b], [b, c], [b, c, c]]

Note that `equal' is not a Maple procedure. also RETURN is deprecated (use return).

Why not just enclose the section in a do loop, terminated with a colon (so the lines do not automatically generate printed output)  and add a print statement to the line that generates the output?  For example:

to 10 do
  < your code here >
  print(%); # print the last value
end do:

One approach is

T := combinat:-cartprod([[a,b],[c,d]]):
while not T[finished] do combinat:-permute(T[nextvalue]()); end do;

To instantiate a cartesian produce at once, you might look at http://www.mapleprimes.com/book/cartesian-products-of-lists.

Here's a brute force solution.  To reduce the solution space, I solved for a pan-magic square; in addition to the usual constraints, the sums of all the broken diagonals must also equal the magic number.

PanMagic := proc(L,n::posint)
local i,j,M,rng;
    rng := 0..n-1;
    M := (n^3+n)/2;
    [seq(s=M, s in [NULL
                    , seq(add(L[i,j], j=rng), i=rng)
                    , seq(add(L[i,j], i=rng), j=rng)
                    , seq(add(L[i,modp(i+j,n)],i=rng), j=rng)
                    , seq(add(L[i,modp(j-i-1,n)],i=rng), j=rng)
                   ])];
end proc:

to 1 do
    n := 4:
    eqs := PanMagic(L,n);
    sol := solve(eqs);
    vals := map(rhs,sol);
    vars := convert(indets(vals),'list');
end do:

all := {seq(1..n^2)}:

P := combinat:-permute(convert(all,'list'),nops(vars)):

found := false:
for p in P do
    eqs := Equate(vars,p);
    if subs(eqs, vals) = all then
        found := true;
        break;
    end if;
end do:

if found=true then
    M := subs(sol,eqs, Matrix(n,n,(i,j) -> L[i-1,j-1]));
end if;

                               [ 1     8    10    15]
                               [                    ]
                               [12    13     3     6]
                          M := [                    ]
                               [ 7     2    16     9]
                               [                    ]
                               [14    11     5     4]

You should add some context to that question. 

Do you want to tally the occurrences of each distinct n-tuple?  Here is a simple way to do so.  First, I'll create the data (I'm using pairs, the extension to any n-tuple is clear).

L := [[a,b],[a,b],[b,a],[a,a]]:

We cannot do

Statistics:-Tally(L);
                                [a = 5, b = 3]

However, if we wrap each sublist in an unevaluated function call, Tally then tallys the functions and not the elements of the sublists. A neat way to do that is with the empty function, ``, followed by a call to expand, which expands ``(x) into x:

expand(Statistics:-Tally(map(``,L))); 
                      [[a, a] = 1, [b, a] = 1, [a, b] = 2]

Is that what you want?
 


 

 

It is not clear what you want.

xbar indicates the complex-conjugate of x.  Add the option conjugate=false in the call to MatrixNorm to prevent taking conjugates.

e is not assigned the Euler number in Maple.  Long ago, E was used for that purpose.  Now nothing is preassigned.  You could do e := exp(1), but the better solution is to convert your e^x to exp(x), because e^x, with e = exp(1), is not the same as exp(x).

The usual solution is with map:

L := [a=2,b=3,c=4]:
map(rhs, L);
                            [2,3,4]

To swap the lhs and rhs of the equations, do

map(rhs=lhs, L);
                   [2=a, 3=b, 4=c]

You will probably want to save your module to a custom Maple archive so that you can use it from any Maple session, provided it can access that archive.  Saving the module is easy enough, assuming you have a writable directory with path /home/si37/maple:

LibraryTools:-Save('foo', "/home/si37/maple/myarchive.mla"):

The next step to modify the global variable libname so that Maple can find this archive.  I do that by creating a Maple initialization file and inserting the line

libname := "/home/si37/maple", libname:

See the Maple help page worksheet,reference,initialization for details on the location of the initialization file. Maple reads this file every time it starts and executes the Maple commands contained within.  The above assignment to libname prepends your custom archive directory to the existing libname sequence.

 

There are two related problems, both somewhat subtle, with this routine.  First, the Maple procedure convert/symbol returns a global symbol.  As such, it will not match the local symbols (variables) in the procedure.  A better way to handle this translation is via a table, however, for now let's just use what you have.  The simplest change is to redeclare the symbols M, M2, ..., M10, and X to be global.  That, alas, does not suffice.  The reason is that inside a procedure Maple only evaluates expressions one level.  When you do map(convert, s, symbol) the result is a list of symbols, not a list of their values.  It is those values which foldl gets and chokes.  A work-around for that is to fully evaluate the list, that is add the statement s := eval(s) [before the call to op(s)).  With those changes the procedure operates.

As mentioned, a better way to do this is with a table.  Create the table

MIX := table(["X" = [[1,12], ...], "M" = [...], ..., "M10" = [...]):

then instead of converting s to symbols, look up the strings in the table

s := [seq([MIX[char], char in s)];

Actually, I'd probably do that inside the loop that parses the individual characters.

Are you just trying to draw a nice graph, or are you attempting to fit a particular parameterized curve to the data?  If so, what equation do you expect?

The equation is not symmetric, look at the denominators.

 map(denom,lhs(eq)); 
                                              2
                                          A(r)  + A(r) B(r) + B(r)

You might consider the following:

angles1_dif := map(L -> L[..-2]-L[2..], angles1_s);

Note that angles1_dif here is a list, not a sequence.  It is usually better to use a list when you will be later selecting from it, otherwise you get unexpected results if there is only 1 item.

Rather than sorting and picking the first element, use min

for i to nops(angles1_s) do
   member(min(angles1_dif[i][]), angles1_dif[i], 'k');
   print(angles1_s[i][k], angles_s[i][k+1]);
end do:
First 90 91 92 93 94 95 96 Last Page 92 of 114