Carl Love

Carl Love

26518 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

If results is your expression sequence, you can select its 1st and 6th elements by

results[[1,6]]  or  results[[6,1]]

depending on your preferred order. In addition to being less to type, this also avoids the need to assign to a variable results, which is necessary if you use 

results[1], results[6]

 

The Code Edit Region is expecting Maple[*1] code (which would ordinarily include arithmetic operators such as and statement separators such as ;, hence the error message "missing operator or `;`" ), but what you've put in it is simply text data for Syrup. The region can be easily converted to Maple code that assigns the value of a string, that string being exactly the text data that you already have. It just requires a small modification of the first and last lines, like this:

ckt2:= "ckt2
V1 N03 0 vin
C1 N03 N04 Cp
R1 N04 N01 Rp
L1 N01 N02 Lp
L2 N05 N06 Ls
R2 N07 N05 Rs
C2 0   N07 Cs
H1 N02 0 L2 I*w*M
H2 N06 0 L1 I*w*M
.end"

Note that only one pair of double quotes is needed to create a string that contains line breaks.

I named the string ckt2, so change the 1st argument of the Syrup:-Solve command from "ec:ckt2" to simply ckt2 (without quotes).


Footnote: [*1] Code Edit Regions can process Python code in addition to Maple.

Immediately after the DGsetup command, give the command 

interface(prompt= "> "):

Here is one way of many:

interface(rtablesize= [81,24]):
M:= Matrix(
    (81,24), 
    (i,j)-> local k; [seq](indice(C[i][1][k], rorder(orders[j], Sets[k])), k= 1..4)
);

The interface(rtablesize= ...) command only controls how much of any matrix is displayed on screen; it's not specific to matrix M. It isn't needed if you don't need to display the entire matrix simultaneously.

Here's another way, fairly close to what you had:

M:= Matrix(
    [for i to 81 do
        [for j to 24 do
            [for k to 4 do 
                indice(C[i][1][k], rorder(orders[j], Sets[k]))
            end do]
        end do]
    end do]
);

Matrix indexing is best done as M[i,j] rather then M[i][j]. The latter works but is less efficient. 

 

As you likely know, the operation that you're doing is called (in math, not just in Maple) the outer product of two vectors. But there's no need to use the command LinearAlgebra:-OuterProductMatrix or, indeed, any other named command. Indeed, almost all matrix/vector arithmetic in Maple can be done without any named commands.

Acer has shown that making r and Vectors and doing c.r generates an invisible call to OuterProductMatrix. And perhaps you need some transpose operators, which'll generate calls to LinearAlgebra-Transpose. As you may realize by now, it makes more sense to make the row coefficients r a column vector and to make the column coefficients c a row vector. As well as making more sense intuitively, that also eliminates the need for any transposes.

I think that there's an even better way. As far as I can tell,[*1] by making r a 1-column Matrix and c a 1-row Matrix, the entire operation can be done without explicitly invoking any named commands and without generating calls to any library commands for the matrix-multiplyimg operator `.`. Furthermore, the code to do this is quite simple:

r:= <R[1]; R[2]; R[3]; R[4]>:  #4x1 Matrix, not a Vector
c:= <<C[1] | C[2] | C[3]>>:    #1x3 Matrix, not a Vector
r.c;  #4x3 Matrix


[*1] "As far as I can tell": By this I mean as far as I can tell via use of the trace and printlevel ​​​​​​​internal-code-exploration commands.

If x is the expression containing exp that you want to expand, then use

expand(x, indets(x, specfunc(exp))[]);

This is on the help page ?expand.

It's not that Maple prefers the form exp(a)^2; it's that that's what it means to "expand" a function: Make its arguments simpler (2*a becomes a) even at the expense of making the overall expression more complicated.

There's also a way to suppress the expansion of exp (or any other function) that maintains the suppression until you turn it off; so it's suitable for use in an initialization file:

expand(expandoff()): expandoff(exp):

See ?expandoff.

The option axis= [mode= log] is not intended to be a replacement for the plots commands logplotsemilogplotloglogplot, etc. The difference is that mode= log applies the logarithm after the points are computed, but the dedicated log-plotting commands choose the points knowing that they should be spaced logarithmically. The part of your plot that looks linear is the result of too few values of x being used at the left end of the logarithmic domain.

plots:-semilogplot(
   k, x= 10..1e6, view= [10..1e6, 0.92..0.99], 
   color= "Blue", background= "Ivory", filled= [color= "Cyan", transparency= 0.9], 
   axis= [gridlines= [color= "gray"]], size= [600, 300]
)

Use combine(T1).

I think that this (below) is related to why solve isn't working for this problem. To investigate, I solve the corresponding equation, which is what solve does anyway:

solve(log[2](7/10*x) = log[3](3*x-1), x): lprint(%);
        10/7*RootOf(30*_Z-7*_Z^(ln(3)/ln(2))-7)

evalf([allvalues](%));
        [16.60731836, 0.3730125035 + 0. I, 0.3730125035]

That middle root is spurious and has the same real part as the last root. If I increase Digits to 15, a second spurious root appears, the same as above but with "- 0. I". Increasing Digits further does not change anything except the number of digits in the real parts.

Now, obviously, the solution to your original problem is the closed interval between the two real roots shown.

There is a convert command that returns the list of column or row vectors for a Matrix. Let be a Matrix. The list of column vectors is 

convert(M, list, dimension= 2)

and the list of row vectors is 

convert(M, list, dimension= 1)

The command also handles higher-dimensional Arrays; see ?convert,list.

If you don't want to specify the functional dependence a priori, you should use D instead of diff:

lis:= [f||(1..10)];
L:= D~(lis)

The Ds can be converted to diff after specifying the dependence:

convert(L(t), diff)

Here's a way to do it that changes only the view option of the plot; it doesn't add any other structure (point, curve, etc.). It's not limited to plots produced by the plot command; it works for any non-animated 2-D plot, containing any number of any kind of plot components. It works for plots containing vertical asymptotes or any other form of "undefined".

Include0View:= proc(P::specfunc(PLOT), {xview::range(realcons):= "default"})
local m:= 0, M:= 0, p;
    plots:-display(
        if membertype(
            And(specfunc('VIEW'), 'patfunc'(range(realcons)$2, anything)), 
            P, p
        ) then
            subsop(
                `if`(xview::range, [p,1]= xview, [][]),
                [p,2,1]= min(m, op([p,2,1], P)), [p,2,2]= max(M, op([p,2,2], P)),
                P
            )
        else
            plottools:-transform(
                proc(x,Y)
                local y:= `if`(Y::undefined, undefined, Y);
                    if [x,Y]::list(float) then 
                        m:= min['defined'](m,y); M:= max['defined'](M,y)
                    fi; 
                    [x,Y]
                end proc
            )(P),
            'view'= [xview, m..M]
        fi, _rest
    )
end proc
: 

Example usage:

Include0View(plot(3 + sin(x), x= -Pi..Pi, thickness= 3));

Let expr be an expression that you want to remove dz from. Then do

eval(expr, dz= 1)

In the vast majority of cases, there isn't the slightest problem or name conflict with using a Maple command or package name or a procedure name from one of your own modules as a keyword parameter's keyword. The only case where there is an issue is if the keyword is also one of the 47 reserved words (see help page ?reserved).

You are dealing with permutations. It's not very useful to internally represent them as single integers. If you want to represent them that way externally -- say for a more-compact display -- that's another matter, which is easily handled with a `print/...` procedure:

`print/PERM`:= (L::list(posint))-> Typesetting:-mrow((Typesetting:-mn@String)~(L)[]):

`print/...procedure doesn't change an object's internal representation; it only changes the way it's displayed.

What you're calling "the combination of sets" is usually called the Cartesian product. It can be done numerous ways, one of which is Iterator:-CartesianProduct:

A:= {[1,2], [1,7], [2,4], [2,8]}:
B:= {[3,5,8], [5,6,8]}:
{seq}([seq](p), p= Iterator:-CartesianProduct(A,B));
{[[1, 2], [3, 5, 8]], [[1, 2], [5, 6, 8]], [[1, 7], [3, 5, 8]], [[1, 7], [5, 6, 8]],
 [[2, 4], [3, 5, 8]], [[2, 4], [5, 6, 8]], [[2, 8], [3, 5, 8]], [[2, 8], [5, 6, 8]]}

ListTools:-Flatten~(%);
     {[1, 2, 3, 5, 8], [1, 2, 5, 6, 8], [1, 7, 3, 5, 8], [1, 7, 5, 6, 8],
      [2, 4, 3, 5, 8], [2, 4, 5, 6, 8], [2, 8, 3, 5, 8], [2, 8, 5, 6, 8]}

P:= PERM~(%);
    {12358, 12568, 17358, 17568, 24358, 24568, 28358, 28568}

Finally, you want to impose that uniqueness condition:

select(p-> nops(op(p))=nops({op(p)[]}), P);   
           {12358, 12568, 17358, 17568, 24358, 24568}

That command uses the fact that the internal representation hasn't been changed. Use lprint to view the internal representation:

lprint(%);
{PERM([1, 2, 3, 5, 8]), PERM([1, 2, 5, 6, 8]), PERM([1, 7, 3, 5, 8]), 
PERM([1, 7, 5, 6, 8]), PERM([2, 4, 3, 5, 8]), PERM([2, 4, 5, 6, 8])}

 

1 2 3 4 5 6 7 Last Page 1 of 383