Carl Love

Carl Love

27291 Reputation

25 Badges

11 years, 360 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

This works: I explicitly construct the relevant polygon from the data provided by arc:

M:= op(1, plottools:-arc([0,0], 1, Pi/6..3*Pi/4)):
plots:-polygonplot(< < M[1,1] | 0 >, M, < M[-1,1] | 0 > >);

Let me know how that goes for you.

Regarding the help: Some of the options listed on the page ?plot,options apply only to the plot command itself. I think that those options are adaptive, discont, filled, resolution, sample, and smartview. And option filledregions applies only to the three plots commands contourplot, implicitplot, and listcontplot.

Assuming that the B's are nonnegative (if the B's can be negative, you'll need to explain the significance of that):

A:= [3,5,7,2,11,2,1,10,6,15]:
B:= [0.23, 0.11, 0.05, 0.05, 0.04, 0.06, 0.10, 0.20, 0.06, 0.10]:
Statistics:-Histogram(zip(`$`, A, round~(1000./`+`(B[]) *~ B)), discrete);

How about this?

restart:
with(GraphTheory):
G1:= Graph(
     [A, AT, T, CA, TC, GT, TG, C, CG, G, GC],
     {
          [C,CG], [CG,G], [G,GC],
          [GC,C], [G,GT], [GT,T],
          [T,TG], [TG,G], [A,AT], [AT,T],
          [C,CA], [CA,A], [T,TC], [TC,C]
     }
):

SetVertexPositions(
     G1,
     [
          [0,2], [1.5,2], [3,2],
          [0,1], [1.5,1], [3,1], [3.5,1],
          [0,0], [1.5,0], [3,0],
                 [1.5,-.5]
     ]
);
HighlightVertex(G1, [A,T,C,G], red);
HighlightVertex(G1, [AT,CA,TC,GT,TG,CG,GC], grey);

DrawGraph(G1);

I am guessing that by "labelled" you mean that you want the contours themselves labelled. That would perhaps be possible with some carefully placed textplots. But perhaps the following is good enough: I've placed the labels on the z-axis and some eye-tracking lines from the labels to the contours.

Contours:= [10*k $ k =-3..2]:
P1:= plots:-contourplot3d(
     x^3-y^2, x= -3..3, y= -3..2,
     axes= box, shading= zhue, filled,
     contours= Contours,
     tickmarks= [default$2, Contours],
     transparency= 0.5, thickness= 3
):
P2:= seq(
     plots:-pointplot3d(
          [[-3,2,c], [3,2,c]],
          style= line, color= gray
     ),
     c= Contours
):
plots:-display([P2,P1]);

The following command will create the graph. Having Maple draw the graph exactly the same way as you did is another matter. But Maple's graph is isomorphic to yours.
restart:
with(GraphTheory):
G1:= Graph( {[C,G], [G,C], [T,G], [G,T], [A,T], [C,A], [T,C]});
   
DrawGraph(G1);

graph.mw

The trick is to introduce a new independent variable for the derivative and to link it to the other independent variables. But pdsolve(..., numeric) is very fussy about how you introduce it. I tried three ways that didn't work before I got the working way below.

(**)

restart:

Abbreviations:

(**)

U:= u(y,t):  T:= theta(y,t):  UY:= Uy(y,t):

I've substituted Uy(y,t) for diff(u(y,t), y) in the first PDE.

(**)

pde1:= diff(Uy(y,t),y) = S*Uy(y,t) + diff(U,t) + M*U + U/K - T;

diff(Uy(y, t), y) = S*Uy(y, t)+diff(u(y, t), t)+M*u(y, t)+u(y, t)/K-theta(y, t)

No change in PDE 2.

(**)

pde2:= diff(T,y$2) = Pr*(diff(T,t) + S*diff(T,y));

diff(diff(theta(y, t), y), y) = Pr*(diff(theta(y, t), t)+S*(diff(theta(y, t), y)))

I added a PDE to link the new dependent variable to the others.

(**)

pde3:= diff(U,y) = Uy(y,t);

diff(u(y, t), y) = Uy(y, t)

(**)

IBC:= {
     u(y,0)=0, theta(y,0)=0, u(0,t)=0,
     theta(0,t)=t0, u(1,t)=0, theta(1,t)=0
};

{theta(0, t) = t0, theta(1, t) = 0, theta(y, 0) = 0, u(0, t) = 0, u(1, t) = 0, u(y, 0) = 0}

Parameters (I changed your parameter t to t0 because t is already used as an independent variable):

(**)

Pr:= 7:  S:= 0.6:  M:= 1:  K:= 0.5:  t0:= 0.2:

(**)

Sol:= pdsolve({pde1,pde2,pde3}, IBC, numeric);

module () local INFO; export plot, plot3d, animate, value, settings; option `Copyright (c) 2001 by Waterloo Maple Inc. All rights reserved.`; end module

(**)

dudy:= Sol:-value(Uy(y,t)):

(**)

dudy(0,3);

[y = 0., t = 3., Uy(y, t) = 0.682213955850606429e-1]

(**)

Sol:-plot(Uy(y,t), y= 0, t= 0..5);

(**)

dudy0:= tau-> eval(Uy(y,t), dudy(0,tau));

proc (tau) options operator, arrow; eval(Uy(y, t), dudy(0, tau)) end proc

(**)

plot(dudy0, 0..5);

(**)

dudy0(3.);

0.682213955850606429e-1

(**)

 

 

 

Download dudy0.mw

For your first question, enter the command

Digits:= 15;

or whatever number of digits you want.

 

For your second question, make the loop like this:

for i from 1 to 5 do
     A := i;
     B := 2*i;
     C := A+B;
     print('C' = C)
end do:

Whether you use colons or semicolons inside the loop makes no difference; what matters is what you use on the end do.

Here's how to do simplify with side relations (modulo what Markiyan said), plus a few other techniques to simplify both the input and the output of this expression.

 

(**)

mul((1+x[k]+y[k])*(1-x[k])*(1-y[k]), k= 1..4);

(1+x[1]+y[1])*(1-x[1])*(1-y[1])*(1+x[2]+y[2])*(1-x[2])*(1-y[2])*(1+x[3]+y[3])*(1-x[3])*(1-y[3])*(1+x[4]+y[4])*(1-x[4])*(1-y[4])

(**)

simplify(%, {seq}([x[k]^2, y[k]^2][], k= 1..4));

x[1]*x[2]*x[3]*x[4]*y[1]*y[2]*y[3]*y[4]-x[1]*x[2]*x[3]*y[1]*y[2]*y[3]-x[1]*x[2]*x[4]*y[1]*y[2]*y[4]-x[1]*x[3]*x[4]*y[1]*y[3]*y[4]-x[2]*x[3]*x[4]*y[2]*y[3]*y[4]+x[1]*x[2]*y[1]*y[2]+x[1]*x[3]*y[1]*y[3]+x[1]*x[4]*y[1]*y[4]+x[2]*x[3]*y[2]*y[3]+x[2]*x[4]*y[2]*y[4]+x[3]*x[4]*y[3]*y[4]-x[1]*y[1]-x[2]*y[2]-x[3]*y[3]-x[4]*y[4]+1

(**)

factor(%);

(x[4]*y[4]-1)*(x[3]*y[3]-1)*(x[2]*y[2]-1)*(x[1]*y[1]-1)

(**)

 

 

Download siderels.mw

When solving for the real part of y, the y2 cancels miraculously, leaving something that can be plotted with plot3d.

 

(**)

E:= y^2+x^2=1;

x^2+y^2 = 1

(**)

E1:= eval(E, [y= y1+I*y2, x= x1+I*x2]);

(x1+I*x2)^2+(y1+I*y2)^2 = 1

(**)

E2:= solve(E1, y1);

-I*y2+(-(2*I)*x1*x2-x1^2+x2^2+1)^(1/2), -I*y2-(-(2*I)*x1*x2-x1^2+x2^2+1)^(1/2)

(**)

E3a:= evalc(Re(E2[1])); E3b:= evalc(Re(E2[2]));

(1/2)*(2*((-x1^2+x2^2+1)^2+4*x1^2*x2^2)^(1/2)-2*x1^2+2*x2^2+2)^(1/2)

-(1/2)*(2*((-x1^2+x2^2+1)^2+4*x1^2*x2^2)^(1/2)-2*x1^2+2*x2^2+2)^(1/2)

(**)

P1:= plot3d(E3a, x1= -1.5..1.5, x2= -1.5..1.5):

(**)

P2:= plot3d(E3b, x1= -1.5..1.5, x2= -1.5..1.5):

(**)

plots[display]([P1,P2], scaling= constrained, title= "Real part");

(**)

 

 

Download real_part.mw

By default, Maple does not check for discontinuities in a plot. So it picks x-values too close to the vertical asymptotes, which produces very large y-values. You can get Maple to check for discontinuities by including the discont option to plot.

plot([(2*x+3)/(x-4), (4*x+3)/(x-2)], discont);

It took me awhile to finish this. It ended up being about 300 lines. This is the first multi-threaded application I've written, other than just using Threads:-Map or Threads:-Seq. But it's done: A fully functional multi-threaded combinations filter. Suggestions for improvement are most welcome.  In particular, it would be great if the processor utilization could be increased.


ComboFilter:= module()
(*________________________________________________________________________
This is a multi-threaded combinations filter.  It generates all k-subsets
of an n-set, applies a user-specified filter to them, and writes the
remaining combinations to a file using a user-specified format.  It is
intended to be used in situations where it is not feasible to represent all
combinations in memory at once (the same situations where one would use
combinat:-nextcomb).  The generation, filtering, and writing are handled
in separate threads.  The memory usage is about 7 times (very rough
estimate) the memory needed for a list of combinations of length 'blocksize'
(see the Parameters).

Parameters: See comment at the ModuleApply.
Returns: NULL: The output goes to a file.
````````````````````````````````````````````````````````````````````````````*)
uses  
    M= Threads:-Mutex,
    LOCK= Threads:-Mutex:-Lock,
    UNLOCK= Threads:-Mutex:-Unlock,
    CV= Threads:-ConditionVariable,
    WAIT= Threads:-ConditionVariable:-Wait,
    SIGNAL= Threads:-ConditionVariable:-Signal
;
local
    GenerateSignal,
    FilterBuffer, FilterBufferLock, FilterSignal,
    WriteBuffer, WriteBufferLock, WriteSignal,
    Combo,

    # Some macros to shorten the ubiquitous userinfo statements
    _:= userinfo,
    C:= (5, ComboFilter),
    q:= (C, "Acquired."),
    w:= s-> (C, sprintf("Waiting for %s.", s)),
    u:= s-> (C, sprintf("Unlocked %s lock.", s)),
    s:= s-> (C, sprintf("%s signalled.", s)),
    longbuffer:= B-> `if`(nops(B) > 9, [B[1..9][], `...`], B),    
(*_________________________________________________________________________
Generate is the first of the three main threads. It uses combinat:-nextcomb
to generate combinations and then places them in FilterBuffer, a
list shared with thread Filter and access-controlled by
FilterBufferLock. It sends FilterSignal to Filter and waits on
GenerateSignal from Filter.

Parameters: n::posint, blocksize::posint, preciseorder::truefalse (see
comment at ModuleApply).
Returns: NULL
```````````````````````````````````````````````````````````````````````````*)
(*
#**************************************************************************#
In each of the three main procedures, code in a comment box (like this)    #
is the main algorithm; everything else is for thread synchronization.        #
#**************************************************************************#*)
Generate:= proc(n::posint, blocksize::posint, preciseorder::truefalse)
    local buffer, more:= true, i, j;
        while more do
            #******************************************************#
            buffer:= table();                                #
            if preciseorder then                            #
                for j to blocksize do                        #
                    buffer[j]:= Combo;                        #
                    Combo:= combinat:-nextcomb(Combo, n);        #
                    if Combo = FAIL then  #End                #
                        more:= false;                         #
                        break                            #
                    end if                                #
                end do;                                       #
                buffer:= [seq](buffer[i], i= 1..min(j, blocksize))#                
            else                                             #
                to blocksize do                                 #
                    buffer[Combo]:= ();                        #
                    Combo:= combinat:-nextcomb(Combo, n);        #
                    if Combo = FAIL then  #End                  #
                        more:= false;                         #
                        break                                 #
                    end if                                     #
                end do;                                    #
                buffer:= [indices](buffer, ':-nolist')            #
            end if;                                        #
            #******************************************************#
            _(w("FB lock"));  
            LOCK (FilterBufferLock);_(q);
                # Wait for Filter to empty the buffer.
                while FilterBuffer <> () do
                    SIGNAL (FilterSignal);_(s("Filter"));
                    _(w("GenerateSignal"));  
                    WAIT (GenerateSignal, FilterBufferLock);_(q)
                end do;
                #************************#
                FilterBuffer:= buffer;    #
                #************************#
                _(C, longbuffer(FilterBuffer));
                SIGNAL (FilterSignal);_(s("Filter"));
            UNLOCK (FilterBufferLock);_(u("FB"))
        end do;
        
        #Send final signal to Filter thread, so that it can end.
        _(w("final lock"));  
        LOCK (FilterBufferLock);_(q);
            # Wait for Filter to empty the buffer.
            while FilterBuffer <> () do
                SIGNAL (FilterSignal);_(s("Filter"));
                _(w("GenerateSignal."));
                WAIT (GenerateSignal, FilterBufferLock);_(q)
            end do;        
            FilterBuffer:= [];
            SIGNAL (FilterSignal);_(s("Filter"));
        UNLOCK (FilterBufferLock);_(u("FB"));    
        [][]    
    end proc,
(*_____________________________________________________________________
Filter is the second of the three main threads. It uses Threads:-Map
to apply a user-specified filter to the combinations in FilterBuffer
and then places the remaining combinations in WriteBuffer, a list
shared with Write and accessed-controlled by WriteBufferLock. It sends
GenerateSignal to Generate and waits on FilterSignal from Generate; it
sends WriteSignal to Write and waits on FilterSignal from Write.

Parameter: filter::procedure (see comment at ModuleApply)
Returns: NULL
```````````````````````````````````````````````````````````````````````*)
    Filter:= proc(filter::procedure)
    local buffer, more:= true;
        while more do
            _(w("FB lock"));  
            LOCK (FilterBufferLock);_(q);
                while FilterBuffer = () do
                    SIGNAL (GenerateSignal);_(s("Generate"));
                    _(w("FilterSignal"));  
                    WAIT (FilterSignal, FilterBufferLock);_(q)
                end do;
                #******************************************************#
                if FilterBuffer = [] then                         #
                    more:= false;                                 #
                    buffer:= "empty"  #Signal Write process to end.     #
                else                                          #
                    buffer:= FilterBuffer                         #
                end if;                                        #
                #******************************************************#
                FilterBuffer:= (); #Signal to Generate
            UNLOCK (FilterBufferLock);_(u("FB"));
               #******************************************#
            if buffer <> "empty" then                  #
                buffer:= Threads:-Map(filter, buffer) #
            end if;                                     #
            #******************************************#
            _(w("WB lock"));  
            LOCK (WriteBufferLock);_(q);
                # Wait for WriteBuffer to empty.
                while WriteBuffer <> () do
                    SIGNAL (WriteSignal);_(s("Write"));
                    _(w("FilterSignal"));  
                    WAIT (FilterSignal, WriteBufferLock);_(q);
                end do;
                _(C, longbuffer(buffer));
                #************************#
                WriteBuffer:= buffer;    #
                #************************#
                SIGNAL (WriteSignal);_(s("Write"));
            UNLOCK (WriteBufferLock);_(u("WB"))
        end do;
        [][]
    end proc,
(*__________________________________________________________________________
Write is the third of the three main threads.  It writes the contents of
WriteBuffer to a file using a user-specified formatting procedure.  It waits
on WriteSignal from Filter and sends FilterSignal to Filter.

Parameters: filename::string, format::procedure (see comment at
ModuleApply).
Returns: NULL: Output goes to a file.
`````````````````````````````````````````````````````````````````````````````*)
    Write:= proc(format::procedure)
    local
        buffer,
        OutFile:= FileTools:-Text:-Open(Filename)
    ;
        do
            _(w("WB lock"));
            LOCK (WriteBufferLock);_(q);
                while WriteBuffer = () do
                    SIGNAL (FilterSignal);_(s("Filter"));
                    _(w("WriteSignal"));  
                    WAIT (WriteSignal, WriteBufferLock);_(q);
                end do;

                if WriteBuffer = "empty" then  #End
                    UNLOCK (WriteBufferLock);
                    break  
                end if;
                #************************#            
                buffer:= WriteBuffer;    #
                #************************#
                WriteBuffer:= (); #Signal to Filter to fill it.
            UNLOCK (WriteBufferLock);_(u("WB"));
               #***********************#
            format(OutFile, buffer) #
            #***********************#
        end do;
        [][]
    end proc,
(*________________________________________________________________________
ModuleApply: Generates first combination, initiates all the Threads, and
waits.

Parameters:
n::posint: The set that the combinations are drawn from
k::posint: The size of a combination.

Keyword parameters (default values are specified with :=):

blocksize::posint:= 1:
The number of combinations to be treated as one "block". It does not need to
be a divisor of binomial(n,k); if necessary, a shorter final block will be
used.

filter::procedure:= C-> C:
The procedure used to filter the combinations.  It should be a procedure
such that if L is a list of combinations, then map(filter, L) yields the
combinations that are to be kept.  This is achieved by the procedure
returning either its input or NULL.  The default filter keeps everything.

filename::string:= cat(currentdir(), kernelopts(diresep), "Combos.m"):
The name of the output file.

format::procedure:= (F,B)-> fprintf(F, "%m", B):
The procedure used to write one block of output to the file. The procedure
takes two arguments: F, the file pointer, and B, a list (possibly empty!)
of combinations. The default uses Maple's ".m" format, which is very
quick to read and write but is not human readable while it's in the file.

preciseorder::truefalse:= false:
Boolean option that specifies that the combinations be placed in the file
in their canonical order. This is slightly less efficient, so the default
is false.
`````````````````````````````````````````````````````````````````````````*)                
    ModuleApply:= proc(
        n::posint, k::posint,
        {
            blocksize::posint:= 1,
             filter::procedure:= (C-> C),
             format::procedure:= ((F,B)-> fprintf(F, "%m", B)),
             preciseorder::truefalse:= false
         }
    )    
         GenerateSignal:= CV:-Create();
         FilterBuffer:= [][];  
         FilterBufferLock:= M:-Create();  FilterSignal:= CV:-Create();
        WriteBuffer:= [][];  
        WriteBufferLock:= M:-Create();  WriteSignal:= CV:-Create();
        
        Combo:= combinat:-firstcomb(n, k);
        try        
            Threads:-Wait(
                map(
                    Threads:-Create,
                    [
                        'Generate(n, blocksize, preciseorder)',
                        'Filter(filter)',
                        'Write(format)'
                    ]
                )[]
            )
        catch: error
        finally
            FileTools:-Text:-Close(Filename);
            CV:-Destroy(GenerateSignal, WriteSignal, FilterSignal);
            M:-Destroy(WriteBufferLock, FilterBufferLock);
        end try;        
        [][]
    end proc
;
export
    # The default name of the output file. Change it by assigning to
    # the module export: ComboFilter:-Filename:= ...;
    Filename:= cat(currentdir(), kernelopts(':-dirsep'), "Combos.m"),
(*__________________________________________________________________________
Reader is a little submodule for reading the output files assuming that the
default format was used.
````````````````````````````````````````````````````````````````````````````*)
    Reader:= module()
    local
        File,
        (*____________________________________
          The ModuleApply just opens the file.
        ```````````````````````````````````````*)
        ModuleApply:= proc()
            File:= FileTools:-Text:-Open(Filename);
            [][]
        end proc
    ;
    export
        (*____________________________________________________________________
          Read() returns the contents of one block, or NULL if at end-of-file.
        ``````````````````````````````````````````````````````````````````````*)
        Read:= proc()
            if FileTools:-AtEndOfFile(File) then
                _(1, ComboFilter, "At end of file.");
                FileTools:-Text:-Close(File);
                [][]
            else
                fscanf(File, "%m")[]
            end if
        end proc
    ;
    end module
;
end module;

   
   

module () local GenerateSignal, FilterBuffer, FilterBufferLock, FilterSignal, WriteBuffer, WriteBufferLock, WriteSignal, Combo, _, C, q, w, u, s, longbuffer, Generate, Filter, Write, ModuleApply; export Filename, Reader; end module

To load the module, place cursor in the Code Edit Region above, right-click, and select Execute Code.

(**)

infolevel[ComboFilter]:= 5:

Set name of the output file.

(**)

ComboFilter:-Filename:= "C:/Users/Carl/Combos.m":

(**)

binomial(99, 4);

3764376

(**)

CodeTools:-Usage(ComboFilter(99, 4, blocksize= 2^20, filter= (C-> C)));

Filter: Waiting for FB lock.

Filter: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.
Write: Waiting for WB lock.
Write: Acquired.
Filter: Acquired.
Write: Filter signalled.
Write: Waiting for WriteSignal.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.

Generate: Waiting for FB lock.
Generate: Acquired.

Generate: [{3 73 90 95} {3 29 43 88} {3 24 68 82} {2 68 71 96} {2 63 89 90} {1 13 74 89} {1 69 75 88} {1 13 49 92} {1 35 37 84} ...]
Generate: Filter signalled.
Generate: Unlocked FB lock.
Filter: Acquired.
Filter: Unlocked FB lock.

Filter: Waiting for WB lock.
Filter: Acquired.
Filter: [{3 73 90 95} {3 29 43 88} {3 24 68 82} {2 68 71 96} {2 63 89 90} {1 13 74 89} {1 69 75 88} {1 13 49 92} {1 35 37 84} ...]
Filter: Write signalled.
Filter: Unlocked WB lock.
Filter: Waiting for FB lock.
Filter: Acquired.
Write: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.
Write: Unlocked WB lock.

Write: Waiting for WB lock.
Write: Acquired.
Write: Filter signalled.
Write: Waiting for WriteSignal.
Filter: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.

Generate: Waiting for FB lock.
Generate: Acquired.
Generate: [{9 14 90 97} {13 26 51 72} {13 25 75 83} {13 25 31 81} {10 21 23 68} {12 27 81 89} {12 17 59 74} {10 15 31 43} {11 61 91 95} ...]
Generate: Filter signalled.
Generate: Unlocked FB lock.
Filter: Acquired.
Filter: Unlocked FB lock.

Filter: Waiting for WB lock.
Filter: Acquired.
Filter: [{9 14 90 97} {13 26 51 72} {13 25 75 83} {13 25 31 81} {10 21 23 68} {12 27 81 89} {12 17 59 74} {10 15 31 43} {11 61 91 95} ...]
Filter: Write signalled.
Filter: Unlocked WB lock.
Filter: Waiting for FB lock.
Filter: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.
Write: Acquired.
Write: Unlocked WB lock.

Write: Waiting for WB lock.
Write: Acquired.
Write: Filter signalled.
Write: Waiting for WriteSignal.
Filter: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.

Generate: Waiting for FB lock.
Generate: Acquired.
Generate: [{24 39 47 53} {21 47 62 91} {23 62 70 95} {30 33 35 56} {29 52 63 87} {20 40 41 71} {23 51 81 89} {29 52 57 74} {23 37 55 94} ...]
Generate: Filter signalled.
Generate: Unlocked FB lock.
Filter: Acquired.
Filter: Unlocked FB lock.

Filter: Waiting for WB lock.
Filter: Acquired.
Filter: [{24 39 47 53} {21 47 62 91} {23 62 70 95} {30 33 35 56} {29 52 63 87} {20 40 41 71} {23 51 81 89} {29 52 57 74} {23 37 55 94} ...]
Filter: Write signalled.
Filter: Unlocked WB lock.
Filter: Waiting for FB lock.
Filter: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.
Write: Acquired.
Write: Unlocked WB lock.

Write: Waiting for WB lock.
Write: Acquired.
Write: Filter signalled.
Write: Waiting for WriteSignal.
Filter: Acquired.
Filter: Generate signalled.
Filter: Waiting for FilterSignal.

Generate: Waiting for FB lock.
Generate: Acquired.
Generate: [{62 67 78 80} {39 64 85 98} {44 50 53 75} {39 48 65 68} {37 38 52 56} {57 69 70 74} {57 65 68 92} {56 64 79 92} {55 67 78 91} ...]
Generate: Filter signalled.
Generate: Unlocked FB lock.
Generate: Waiting for final lock.
Filter: Acquired.
Generate: Acquired.
Generate: Filter signalled.
Generate: Unlocked FB lock.
Filter: Unlocked FB lock.

Filter: Waiting for WB lock.
Filter: Acquired.
Filter: [{62 67 78 80} {39 64 85 98} {44 50 53 75} {39 48 65 68} {37 38 52 56} {57 69 70 74} {57 65 68 92} {56 64 79 92} {55 67 78 91} ...]
Filter: Write signalled.
Filter: Unlocked WB lock.
Write: Acquired.
Filter: Waiting for FB lock.
Filter: Acquired.
Filter: Unlocked FB lock.
Filter: Waiting for WB lock.
Filter: Acquired.
Filter: empty
Filter: Write signalled.
Filter: Unlocked WB lock.
Write: Unlocked WB lock.

Write: Waiting for WB lock.
Write: Acquired.
memory used=7.27GiB, alloc change=368.00MiB, cpu time=2.59m, real time=2.02m

Read the output file back in (just as an example):

(**)

ComboFilter:-Reader():

(**)

L:= []:

(**)

while L <> () do
     L:= ComboFilter:-Reader:-Read():
     if L <> () then
          print(nops(L));
          print(L[1..8])
     end if
od:

1048576

[{3, 73, 90, 95}, {3, 29, 43, 88}, {3, 24, 68, 82}, {2, 68, 71, 96}, {2, 63, 89, 90}, {1, 13, 74, 89}, {1, 69, 75, 88}, {1, 13, 49, 92}]

1048576

[{9, 14, 90, 97}, {13, 26, 51, 72}, {13, 25, 75, 83}, {13, 25, 31, 81}, {10, 21, 23, 68}, {12, 27, 81, 89}, {12, 17, 59, 74}, {10, 15, 31, 43}]

1048576

[{24, 39, 47, 53}, {21, 47, 62, 91}, {23, 62, 70, 95}, {30, 33, 35, 56}, {29, 52, 63, 87}, {20, 40, 41, 71}, {23, 51, 81, 89}, {29, 52, 57, 74}]

618648

[{62, 67, 78, 80}, {39, 64, 85, 98}, {44, 50, 53, 75}, {39, 48, 65, 68}, {37, 38, 52, 56}, {57, 69, 70, 74}, {57, 65, 68, 92}, {56, 64, 79, 92}]

Read: At end of file.

(**)

 


Download Para_Combos.mw

(I've only looked at the Gauss-Seidel; I assume that the Jacobi has the same problem.)

The problem is that x, which has the value Vector([0,0,0]), is passed in as an argument to parameter x. The first line of the procedure is x:= Vector(n). Since x has a value, this becomes Vector([0,0,0]):= Vector(3). You have something that cannot be assigned to on the left side of :=, hence the error message. 

There were a few other errors in your procedure, which I cleaned up. Here it is:

 

Método de Gauss-Seidel

gauss_seidel:= proc(A::Matrix, b::Vector, x_init::Vector, e::float)
local
     i, j, soma,
     n:= LinearAlgebra:-Dimension(b),
     x:= copy(x_init),
     x0:= Vector(n, fill= infinity),
     g:= Vector(n),
     C:= Matrix(n)
;
     for i to n do
          g[i]:= b[i]/A[i,i];
          for j to n do
               if i=j then
                    C[i,j]:= 0
               else
                    C[i,j]:= -A[i,j]/A[i,i]
               end if
          end do
     end do;
     while LinearAlgebra:-Norm(x - x0) > e do
          x0:= copy(x);
          for i to n do
               soma:=0;
               for j to n do
                    soma:= soma + C[i,j]*x[j]
               end do;
               x[i]:= soma + g[i]
          end do
     end do;
     x
end proc:

A:= Matrix([[4,1,1],[-2,5,1],[3,1,6]]);

A := Matrix(3, 3, {(1, 1) = 4, (1, 2) = 1, (1, 3) = 1, (2, 1) = -2, (2, 2) = 5, (2, 3) = 1, (3, 1) = 3, (3, 2) = 1, (3, 3) = 6})

b:= Vector([5,0,-6.5]);

b := Vector(3, {(1) = 5, (2) = 0, (3) = -6.5})

(**)

x:= Vector([0,0,0]);

x := Vector(3, {(1) = 0, (2) = 0, (3) = 0})

gauss_seidel(A, b, x, 0.001);

Vector(3, {(1) = 1.49999631754557, (2) = .999955463867186, (3) = -1.99999073608398})

Compare with known solution:

LinearAlgebra:-LinearSolve(A,b);

Vector(3, {(1) = 1.50000000000000, (2) = 1., (3) = -2.})

(**)

 

NULL

 

Download Método_de_Gauss-Sei.mw

There is still the possibility of an infinite loop if the errors are never less than e.

Hopefully you can now fix the Jacobi on your own.

I assume this work is for educational value. If instead it is for production use, there are much more efficient ways to do it.

You need to use different loop index variables for your inner and outer loops. You have i for both.

Bonus: Here's your procedure in a more-standard style. Note that the outer loop doesn't even need an index variable.

randomDeck:= proc(n::posint)
local
     deck:= [seq](1..52),
     randomDeck:= [],
     i,
     succes:= 0
;
     to n do
          randomDeck:= Statistics:-Shuffle(deck);
          for i to nops(deck) do
               if deck[i] = randomDeck[i] then
                    succes:= succes + 1;
                    break
               end if
          end do
     end do;
     succes
end proc:

In both plots, change g[k] to rhs(g[k]). In the first plot, change plot(F(x), x= 1..2) to plot(F, 1..2).

You can extend the power of the expand command by adding a simple procedure:

`expand/.`:= proc()
local p,a;
     if membertype(`+`, [args], 'p') then
          add(thisproc(args[1..p-1], a, args[p+1..-1]), a= args[p])
     else
          `.`(args)
     end if
end proc:

ex:= {[1]}.{[2]}.({[2, 3]}-{[3, 2]}).({[1, 3]}-{[3, 1]}):
expand(ex);

First 352 353 354 355 356 357 358 Last Page 354 of 390