Carl Love

Carl Love

28015 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Like this:

a__01 #Two underscores

 

To return all the values of w, replace your for loop (all 3 lines) with this:

w:= [seq](gamma__1*alpha/(4*k__1*qq[i]^2/d^2-alpha__3*xi/eta__1), i= 1..m);

That makes w a list. What you had makes w a table. There's nothing wrong with using a table, but they're slightly more difficult to return.

As promised, here's a general procedure for all such questions involving an equivalence relation between the rows of two matrices.
 

restart
:

A:= <
    1, 3, 3, 2, 3, 2, 2, 3, 3, 2, 0;
    1, 3, 3, 2, 3, 1, 1, 2, 3, 3, 2;
    1, 3, 2, 2, 2, 3, 1, 2, 3, 3, 2;
    1, 3, 5, 3, 2, 2, 3, 3, 2, 0, 0;
    1, 3, 5, 3, 1, 1, 2, 3, 3, 2, 0;
    1, 3, 4, 2, 3, 1, 2, 3, 3, 2, 0;
    1, 3, 6, 4, 2, 3, 3, 2, 0, 0, 0;
    1, 3, 6, 3, 1, 2, 3, 3, 2, 0, 0;
    1, 3, 5, 5, 5, 3, 2, 0, 0, 0, 0;
    1, 3, 3, 3, 5, 4, 3, 2, 0, 0, 0;
    1, 3, 4, 4, 4, 3, 3, 2, 0, 0, 0;
    1, 3, 3, 4, 6, 5, 2, 0, 0, 0, 0;
    1, 3, 5, 5, 6, 4, 0, 0, 0, 0, 0;
    1, 3, 5, 6, 4, 3, 2, 0, 0, 0, 0;
    1, 3, 3, 5, 5, 2, 3, 2, 0, 0, 0;
    1, 3, 5, 5, 3, 2, 3, 2, 0, 0, 0;
    1, 3, 3, 4, 3, 3, 2, 3, 2, 0, 0;
    1, 3, 4, 4, 2, 3, 2, 3, 2, 0, 0;
    1, 3, 5, 2, 1, 2, 3, 2, 3, 2, 0;
    1, 3, 5, 3, 2, 3, 2, 3, 2, 0, 0;
    1, 3, 4, 3, 1, 2, 3, 2, 3, 2, 0;
    1, 3, 3, 3, 2, 2, 3, 2, 3, 2, 0;
    1, 3, 3, 3, 1, 1, 2, 3, 2, 3, 2;
    1, 3, 2, 2, 3, 1, 2, 3, 2, 3, 2
>:

For testing, I construct matrix B by permuting (at random) a subset of the rows of A and then doing a random cyclic permutation on the interior columns.

(r,c):= op(1,A);

24, 11

C:= combinat:

cc:= rand(2..c-1)();

8

 

B:= A[C:-randperm(r)[..rand(1..r)()], [1, cc..-2, 2..cc-1, c]];

_rtable[36893491101098178908]

CycPermRep:= proc(r::posint, M::Matrix)
description "
This procedure returns (as a list) the lexicographically least cyclic permutation of
M[r, 2..-2]. The time complexity is O(c) where c is the number of columns of M.
";
local A:= [seq](M[r, 2..-2]), p;
    {seq}(A[[p..-1, 1..p-1]], p= ListTools:-SearchAll({A[]}[1], A))[1]
end proc
:

MatrixRowMatch:= proc(A::Matrix, B::Matrix, ClRep)
description "
Author: Carl Love <carl.j.love@gmail.com> 2022-Aug-28
.
For matrices A and B, this procedure produces a bipartite graph showing a relation between
the rows of A and those of B. The relation is determined by the 3rd argument, procedure or
operator ClRep.
.
The matrices can be any sizes; if one has fewer columns than the other, it'll be padded
on the right with 0s. Then the matrices are stacked into a single matrix AB. ClRep's
arguments will be a row number i of AB, AB itself, and any extra arguments passed to this
procedure. It should return a canonical identifier (of any immutable type) of the
relation's equivalence class that contains row AB[i]. (The return value should be
immutable, such as a list; thus, it shouldn't be a vector.)
.
The equivalence classes are used to form a bipartite graph by removing connections from A
to itself and B to itself. The graph's vertices are
[cat(\"A\", 1..ra), cat(\"B\", 1..rb)] where ra and rb are the numbers of rows of A and
B.
.
The time complexity of this algorithm is O(r*C) where r is the number of rows of AB and C
is the time complexity of C1Rep.
";
local AB, Cl, ra, ca, rb, cb, r, RepRem, rest:= _rest;
    (ra, ca):= op(1, A); (rb, cb):= op(1, B); r:= ra+rb;
    AB:= <<A | Matrix((ra, max(0, cb-ca)))>, <B | Matrix((rb, max(0, ca-cb)))>>;
    RepRem:= proc(i::posint) option remember; ClRep(i, AB, rest) end proc;
    Cl:= ListTools:-Classify(RepRem, [$1..r]);
    GraphTheory:-Graph(
        [cat("A", 1..ra), cat("B", 1..rb)],
        Array(1..r, i-> remove(`if`(i > ra, `>`, `<=`), Cl[RepRem(i)], ra))
    )
end proc
:

BG:= MatrixRowMatch(A, B, CycPermRep);

GRAPHLN(undirected, unweighted, ["A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23", "A24", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14"], Array(1..38, {(1) = {34}, (2) = {28}, (3) = {}, (4) = {30}, (5) = {}, (6) = {}, (7) = {27}, (8) = {}, (9) = {32}, (10) = {35}, (11) = {}, (12) = {33}, (13) = {31}, (14) = {29}, (15) = {25}, (16) = {}, (17) = {26}, (18) = {}, (19) = {38}, (20) = {}, (21) = {}, (22) = {36}, (23) = {}, (24) = {37}, (25) = {15}, (26) = {17}, (27) = {7}, (28) = {2}, (29) = {14}, (30) = {4}, (31) = {13}, (32) = {9}, (33) = {12}, (34) = {1}, (35) = {10}, (36) = {22}, (37) = {24}, (38) = {19}}), `GRAPHLN/table/1`, 0)

GT:= GraphTheory:

E:= GT:-Edges(BG);

{{"A1", "B10"}, {"A10", "B11"}, {"A12", "B9"}, {"A13", "B7"}, {"A14", "B5"}, {"A15", "B1"}, {"A17", "B2"}, {"A19", "B14"}, {"A2", "B4"}, {"A22", "B12"}, {"A24", "B13"}, {"A4", "B6"}, {"A7", "B3"}, {"A9", "B8"}}

for e in E do
    print(A[parse(e[1][2..])], B[parse(e[2][2..])])
od;

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 2, (5) = 3, (6) = 2, (7) = 2, (8) = 3, (9) = 3, (10) = 2, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 2, (5) = 3, (6) = 3, (7) = 2, (8) = 3, (9) = 2, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 3, (5) = 5, (6) = 4, (7) = 3, (8) = 2, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 0, (4) = 0, (5) = 3, (6) = 3, (7) = 3, (8) = 5, (9) = 4, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 4, (5) = 6, (6) = 5, (7) = 2, (8) = 0, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 3, (6) = 3, (7) = 4, (8) = 6, (9) = 5, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 5, (5) = 6, (6) = 4, (7) = 0, (8) = 0, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 3, (6) = 5, (7) = 5, (8) = 6, (9) = 4, (10) = 0, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 6, (5) = 4, (6) = 3, (7) = 2, (8) = 0, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 3, (6) = 5, (7) = 6, (8) = 4, (9) = 3, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 5, (5) = 5, (6) = 2, (7) = 3, (8) = 2, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 0, (4) = 0, (5) = 3, (6) = 3, (7) = 5, (8) = 5, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 4, (5) = 3, (6) = 3, (7) = 2, (8) = 3, (9) = 2, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 0, (5) = 3, (6) = 3, (7) = 4, (8) = 3, (9) = 3, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 2, (5) = 1, (6) = 2, (7) = 3, (8) = 2, (9) = 3, (10) = 2, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 3, (4) = 2, (5) = 3, (6) = 5, (7) = 2, (8) = 1, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 2, (5) = 3, (6) = 1, (7) = 1, (8) = 2, (9) = 3, (10) = 3, (11) = 2}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 3, (4) = 3, (5) = 3, (6) = 3, (7) = 2, (8) = 3, (9) = 1, (10) = 1, (11) = 2})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 3, (5) = 2, (6) = 2, (7) = 3, (8) = 2, (9) = 3, (10) = 2, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 3, (4) = 2, (5) = 3, (6) = 3, (7) = 3, (8) = 2, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 2, (5) = 3, (6) = 1, (7) = 2, (8) = 3, (9) = 2, (10) = 3, (11) = 2}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 3, (5) = 3, (6) = 2, (7) = 2, (8) = 3, (9) = 1, (10) = 2, (11) = 2})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 3, (5) = 2, (6) = 2, (7) = 3, (8) = 3, (9) = 2, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 0, (5) = 3, (6) = 5, (7) = 3, (8) = 2, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 6, (4) = 4, (5) = 2, (6) = 3, (7) = 3, (8) = 2, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 0, (4) = 0, (5) = 3, (6) = 6, (7) = 4, (8) = 2, (9) = 3, (10) = 3, (11) = 0})

Vector[row](%id = 36893491101175625596), Vector[row](%id = 36893491101175625716)

GT:-DrawGraph(BG, layout= bipartite);

 

Download MatrixRowMatch.mw

Here is a procedure for it (based on my limited understanding from a very quick lookup of the definition of the co-normal product of graphs). Let me know if I got it right. The definition that I used is that conormal(G,H) contains the edge {u1:v1, u2:v2} iff (G contains {u1, u2} or H contains {v1, v2}). 

restart
:
RelationGraph:= (f, V::list({integer, symbol, string}))->
local n:= {$nops(V)}, i, F:= i-> j-> f(V[i],V[j]);
    GraphTheory:-Graph(V, [seq](select(F(i), n, _rest), i= n))
:
ConormalProduct:= proc(
    G::Graph, H::Graph, {vertex_format::{string, symbol}:= "%a:%a"}
)
local Vg, Vh, ng, nh, Ng, Nh, P, i, j, Vgh, K;
    (Vg,Vh):= op(GraphTheory:-Vertices~([G,H]));
    (ng,nh):= op(`..`~(1, nops~([Vg,Vh])));
    (Ng,Nh):= op(op~(4, [G,H]));
    P:= [seq](seq([i,j], j= nh), i= ng);
    Vgh:= (curry(sprintf, vertex_format)@((i,j)-> (Vg[i],Vh[j]))@op)~(P);
    K:= op~(table(Vgh=~ P));
    RelationGraph(
        proc(a, b, $)
        local u, v, x, y; 
            (u,v):= K[a]; (x,y):= K[b]; 
            x in Ng[u] or y in Nh[v]
        end proc,
        Vgh
    )
end proc
:

 

I've had many problems using coerce over the years, although it seems much better in Maple 2022 than previously. That's why for a previous Question from you, I recommended using coercion procedures whose names begin rather than using the coerce parameter modifier.

I have no experience using Maple's debugger (or any other debugger for that matter), but as far as I can tell, the following works with the debugger and correctly does the coercion. Let me know if it works for you.

restart;
~list:= (e, T::type)->
    if e::{set, thistype}(T) then [`if`](e::set, e[], e)
    else error "%1 not cercible to type list(%2)", A, T
    fi
:
A:= module()
option object;
export 
    ode, ic,

    ModuleCopy::static:= proc(_self, proto::A, ode::`=`, {ic::~list(`=`):= []}, $)
        print("ode=",ode);
        print("ic=",ic)
    end proc
;
end module;

foo:= proc(ode::`=`, {ic::~list(`=`):= []}, $)
local o;
    #DEBUG();
    o:= Object(A, ode, ':-ic'= ic)
end proc:

foo(diff(y(x),x)=1); 

 

The last word of your description is `vectors"`. It should be `vectors`".

It can be done by

I *~ soln

If I use your n:= 434160 and create a random x n tridiagonal matrix with options shape= band[1, 1], datatype= hfloat and a random n-vector with datatype= hfloat and then simply call X:= LinearSolve(A, B), it takes 0.047 seconds, the memory usage is trivial, and the infinity norm of the residual vector A.X - B is 2e-9.

restart:
Digits:= 15:
n:= 434160:
LA:= LinearAlgebra:

A:= LA:-RandomMatrix(
    (n,n), generator= -99. .. 99., shape= band[1,1], datatype= hfloat
):
B:= LA:-RandomVector(n, generator= -99. .. 99., datatype= hfloat):
X:= CodeTools:-Usage(
    LA:-LinearSolve(A, B)
):
memory used=20.08MiB, alloc change=19.88MiB, cpu time=47.00ms, real time=52.00ms, gc time=0ns

abserr:= LA:-Norm(A.X - B);
                                               -9
               abserr := 2.06871675345610129 10  

(The RandomMatrix command above takes several minutes to complete.)

I couldn't find a stock method for this, so I wrote a procedure. The procedure will work for any 2D PLOT structure containing two or more CURVES substructures.

ShadeBetween:= proc(
    P::specfunc(PLOT), 
    {pairs::list(patlist(posint, posint, {name, name= anything})):= [[1,2]]}
)
uses PT= plottools, LT= ListTools;
local 
    C:= subsindets(
        op~(1, select(type, [op](P), specfunc(CURVES))), rtable, convert, 'lislist'
    ),
    p
;
    plots:-display(
        P,
        seq(PT:-polygon([C[p[1]][], LT:-Reverse(C[p[2]])[]], p[3..][]), p= pairs),
        _rest
    )
end proc
:
#Example usage:
A := <1, 2, 3, 4, 2, 3, 1>:
B := <1, 5, 1, 0, 2, 1, 1>:
C := <1, 2, 1, 3, 1, 4, 2>:
ShadeBetween(
    Statistics:-LineChart([A, B, C], format= stacked), 
    pairs= [[1, 2, color= pink], [2, 3, color= orange, transparency= 0.3]]
);

You can't just substitute vectors for scalars in arithmetic expressions; however, Maple's elementwise operators (indicated by the ~ character) make it almost that simple. You can handle this very similarly to your previous Question:

restart:
N := 2.7:
Hb := <0.076, 0.083>: k := <0.00003400566801, 0.00003424620533>:
P50a := <20.78938475, 21.39546041>:
P50v := <21.20711722, 22.06793197>:
nu := <0.02042461957, 0.02120393111>:
Df := <0.00001617321837, 0.00001607066092>:
P__baro := <759.062, 759.062>:
PaCor := <94.82734101, 90.40928915>:
PvCor := <35.32630403, 35.55779803>:

MyProc:= proc(N, Hb, k, P50a, P50v, nu, Df, P__baro, PaCor, PvCor)
local p, P:= (2*p/(P50a+P50v))^N;
     Por*phi/4/(1-Por)/BP__length*(nu/Df)^(2/3)
     * int((1+1.34*Hb*N*P/k/p/(1+P)^2)^(2/3)/(P__baro - p), p= PvCor..PaCor)
end proc
:
MyProc~(N, Hb, k, P50a, P50v, nu, Df, P__baro, PaCor, PvCor);

Let E be the original set of edges. Then do

subsindets(E, symbol, String);

However, why not use GraphTheory:-RelabelVertices instead?

Making your corrected code into a procedure and getting matrix output can be done like this:

restart:
MyProc:= proc(pH, pO2, Tart, n)
local 
    P50p37:= 26.6*(10.^0.48)^(7.4-pH),
    S0:= (pO2/P50p37)^n
;
    [S0/(1+S0), (P50p37, pO2)*~(10.^0.024)^(Tart-37)]
end proc
:   
pH:= [7.398, 7.392]; pO2:= [121.6, 113.4]; Tart:= [32.5, 32.9];
n:= 2.7; 
Matrix(MyProc~(pH, pO2, Tart, n));
         [0.9836583446 20.78938475 94.82734141]
         [                                    ]
         [0.9799869417 21.39546041 90.40928912]

 

The multiplication that you want can be done by 

evalDG(5 * g5);

The Multiply command that you were trying to use comes from the LinearAlgebra package, and it has no connection to tensors. 

It took me less than 5 minutes to figure this out once I saw your worksheet. In the future, please be more forthcoming with any requested additional information.

You can't use square brackets [ ] or curly braces { } instead of parentheses (a.k.a. round brackets) for grouping and disamibiguation in ordinary algebraic expressions. Using [ ] or { } adds extra layers of meaning that you did not intend. It often takes several steps before an early use leads to an error, which is the case here. So, you need to start at the top and change all algebraic uses of [ ] and { }

You can handle products, quotients, powers, and incrementing the second argument like this:

evalindets[3](
    evalindets(
        evalindets(p, specfunc(T)^anything, `*`@op), 
        `*`, t-> ((A,B)-> add(A)*mul(B))(selectremove(type, [op](t), specfunc(T)))
    ),               
    specfunc(T), `+`, 2, applyop, 1 #This 1 is the increment.
);
  8 T(x, 8) + 8 T(x, 3) + 4 T(x, 6) + 11 T(x, 2) + 12 T(x, 4) + 7 T(x, 5)

The increment could be made -1 or anything else.

First 40 41 42 43 44 45 46 Last Page 42 of 394