Joe Riel

9470 Reputation

23 Badges

18 years, 64 days

MaplePrimes Activity

These are answers submitted by Joe Riel

Have you tried using a table to position the various elements?   Split the table into an appropriate number of rows and columns, possibly joining some cells to make larger cells, and insert the embedded components into the cells.  You can make the dividers invisible.  While it's not perfect, it works reasonably well.

You stated the input is a set, but assigned a list to S.  I'm going to assume that the elements are symbols, but the same symbol can appear more than once.  Solving that is equivalent to finding all partitions of a multiset, which can be achieved with the Iterator:-MultiPartition procedure.   Presumably this could be simplfied if only distinct symbols are allowed (i.e partitions of a set).  Here's a solution

SumsOfList := proc(L :: list(symbol) )
local A, M, N, S, W, i, j, l, n, x;
    x := convert(L, 'compose', 'set', 'list');
    n := numelems(x);
    S := add(L);
    N := map2(coeff, S, x);
    M := Iterator:-MultiPartition(N);
    A := Array(1..0);
    for W in M do
        l := length(M);
        A ,= [seq(add(W[i,j]*x[i],i=1..n),j=1..l)];
    end do;
    convert(A, 'list');
end proc:

                 [[a + b + c], [a + b, c], [a + c, b], [a, b + c], [a, b, c]]
        [[2 a + b + c], [2 a + b, c], [2 a + c, b], [2 a, b + c], [2 a, b, c], [a + b + c, a], [a + b, a + c], [a + b, a, c], [a + c, a, b], [a, a, b + c], [a, a, b, c]]


An immediate issue is that simplify is not threadsafe, so parallelizing the routine using Threads is doomed.  You could do so using the Grid package, for example

CleanExpr := proc(expr, i, phi, coe, coefmodel)
local aaa, bbb, ccc, ind;
        aaa := simplify(subs(coefmodel,expr)):
        if has(aaa,I) then
            return NULL;
            bbb := simplify(subs(coefmodel,phi)):
            ccc := simplify(subs(coefmodel,coe)):
            ind := i:
            return [aaa,bbb,ccc,ind];
        end if:
        return NULL;
    end try:
end proc:

sys := [NULL
        , (-x*rho*xi[6]*(beta - 1)*sqrt(((rho + beta - 1)*sigma - beta + 1)^2*xi[8]^2/(beta - 1)^2) - xi[8]*(-2*y*sigma*xi[7]*xi[6]^2*(beta - 1)^2 + (sigma*rho + (sigma + 1)*(beta - 1))*x*rho*xi[6] + 2*sigma*z*rho^2*xi[8]))/(2*xi[6]*xi[8]*rho*(beta - 1))
        , (-(beta - 1)*(-y*sigma*xi[7]*xi[6]^2*(beta - 1)^2 + rho^2*(sigma*z*xi[8] + x^2))*xi[6]*sqrt(((rho + beta - 1)*sigma - beta + 1)^2*xi[8]^2/(beta - 1)^2) - (2*sigma*(beta - 1)^2*(y*xi[7]*(rho + beta - 1)*sigma/2 + x^2*rho + y*(beta - 1)*xi[7]/2)*xi[6]^3 + 2*x*z*rho*sigma*xi[8]*(beta - 1)^2*xi[6]^2 + (-z*xi[8]*(rho + beta - 1)*sigma^2 + ((2*beta^2*z - 3*beta*z + z)*xi[8] + x^2*rho - (beta - 1)*(-2*beta*y*xi[7] + x^2))*sigma + x^2*(beta - 1))*rho^2*xi[6] + 2*x*z*rho^3*sigma*xi[8])*xi[8])/(2*xi[8]*sigma*(beta - 1)*(rho^2 + (beta - 1)^2*xi[6]^2)*xi[6]*xi[7])
        , (-(-x*sigma*(beta - 1)^2*xi[6]^3 + (beta - 1)^2*(sigma*y*xi[7] + x^2)*xi[6]^2 - rho^2*sigma*x*xi[6] - sigma*z*rho^2*xi[8])*(beta - 1)*rho*sqrt(((rho + beta - 1)*sigma - beta + 1)^2*xi[8]^2/(beta - 1)^2) + xi[8]*(-2*y*sigma^2*xi[7]*(beta - 1)^4*xi[6]^4 + 2*(rho*(rho + beta - 1)*sigma/2 + (beta - 1)*((-beta + 1/2)*rho + y*(beta - 1)*xi[7]))*sigma*(beta - 1)^2*x*xi[6]^3 + (beta - 1)^2*(((-y*xi[7] + 2*z*xi[8])*rho + y*(beta - 1)*xi[7])*sigma^2 + (x^2*rho + (beta - 1)*(-2*beta*y*xi[7] - 2*beta*z*xi[8] + x^2 + y*xi[7]))*sigma - x^2*(beta - 1))*rho*xi[6]^2 + 2*(rho*(rho + beta - 1)*sigma/2 + (beta - 1)*((-beta + 1/2)*rho + y*(beta - 1)*xi[7]))*sigma*x*rho^2*xi[6] + xi[8]*sigma*z*((rho - beta + 1)*sigma - beta + 1)*rho^3))/(2*xi[8]^2*sigma*(beta - 1)*rho*(rho^2 + (beta - 1)^2*xi[6]^2))
coefmodel := {beta = 8/3, rho = 28, sigma = 10}:
phi := [[], [], []]:
coe := [[], [], []]:

result := [Grid:-Seq](CleanExpr(sys[i], i, phi[i], coe[i], coefmodel), i = 1 .. numelems(sys)):


You have declared xpsn, ypsn, and zpsn as local to ppp; as such they are not accessible in Qprj.  Maybe you meant to make them local to rt?

MapleSim comes with DA and AD components; look in Electrical -> Analog -> Converters.

Another approach is to replace the WARNINGS procedure with something suitable.  Here's a quick hack job that demos the idea (it needs work):

Warnings := module()
option package;

local catchall, formats, warnings;

    Catch := proc(fmts? :: seq(string), { all :: truefalse := false })
        if all then
            catchall := true;
            formats := [fmts?];
        end if;
    end proc;

    ModuleLoad := proc()
    global WARNING;
        WARNING := proc(fmt)
            if catchall or Match(fmt) then
                warnings[fmt] := StringTools:-FormatMessage(fmt, _rest);
            end if;
        end proc;
    end proc;

    Display := proc()
    local msg;
        for msg in [entries(warnings,'nolist')] do
            printf("%s\n", msg);
        end do;
    end proc;

    Caught := proc(fmt)
        ormap(f -> SearchText(fmt,f)=1, [indices(warnings,'nolist')]);
    end proc;

    Match := proc(fmt)
        ormap(f -> SearchText(f, fmt)=1, formats);
    end proc;

    Clear := proc()
        warnings := table();
    end proc:

    ModuleUnload := proc()
        kernelopts('unread' = ':-WARNINGS');
    end proc;


end module:

You could use it in the following manner

expr_optimize := fSW__Ratio_Tol[XU5]*f_ratio__SpreadSpectrum[XU5]*(R34^2*k1__RT[XU5] + R34*k2__RT[XU5] + k3__RT[XU5])/R34^2;
seqUnknownRanges := (NULL
                     , R34 = 5.640*10^4*Unit('Omega') .. 6.160*10^4*Unit('Omega')
                     , k1__RT[XU5] = 4.054*10^4*Unit(1/('s')) .. 4.054*10^4*Unit(1/('s'))
                     , k2__RT[XU5] = 1.593*10^11*Unit(1/('F')) .. 1.593*10^11*Unit(1/('F'))
                     , k3__RT[XU5] = -2.645*10^15*Unit('m'^4*'kg'^2/('s'^7*'A'^4)) .. -2.645*10^15*Unit('m'^4*'kg'^2/('s'^7*'A'^4))
                     , fSW__Ratio_Tol[XU5] = 0.950 .. 1.050
                     , f_ratio__SpreadSpectrum[XU5] = 1 .. 1.250

uses Warnings;
    NLPSolve(expr_optimize, seqUnknownRanges, 'useunits', 'method' = 'modifiednewton', 'optimalitytolerance' = 0.101);
    if Caught("convergence is not assured") then
        error "caught it";
    end if;
end proc();

Error, (in anonymous procedure) caught it


I don't know of a good way to do this.  I believe it is possible to use html in the entries, say to force a fixed-width font and then insert horizontal space to fake two columns, however, the result is not pretty.  My recollection is that doing so inserts unwanted vertical space between rows.   Probably you are better off just parenthesizing the constants after the name:  "some acid (3.14)".

For this case there may be a workaround.  Because digits have a fixed width (I believe), you could put the constant first and used a fixed precision with scientific notation.  Then all the values and names would align vertically.  Not ideal but maybe feasible.  If the rows were sorted numerically by the constants (rather than alphabetically by the names) then this would appear almost natural.

Am not sure what you are intending with the use of the `:-' symbol, which is the Maple member operator. Will guess you want assignment.
The piecewise function can be used to express the conditional:

Mtop := piecewise(t < l/2, X*f+t/2, X*f-t/2+l/2);

If you actually want a procedure you could do something like

Mtop := proc(t, X,f, l)
    if t < l/2 then
        X*f + t/2
        X*f - t/2 + l/2
    end if;
end proc:


There should be a hyperlink in the preprocessor help page to the kernelopts help page; I'll submit a bug report.  Presumably an assumption was made that the reader was aware of kernelopts; all settable kernelopts options use the format kernelopts(optionname = value).

You haven't specified how the user is accessing the file.  Because it is a Maple source file (not an mw file), there are two standard ways.  From the O/S command line you can do (on linux):

$ maple test.mpl

In a worksheet you can do

> read "test.mpl":

For both cases you'll have to modify the string so it includes the appropriate path to where the file is located relative to the current directory.  Regardless, if the file contains the special symbol (a preprocessor macro) __FILE__, it will be replaced with a string corresponding to the path to test.mpl.  To get an absolute path you can insert the following assignment into test.mpl:

thisfile := FileTools:-AbsolutePath(__FILE__);

After reading the file, the variable thisfile (the name is not significant) will be assigned the absolute path to test.mpl.  You might make thisfile a local to a procedure assignment in test.mpl.  Note that preprocessor macros are only expanded when the file is read.

If you have write permission, you should be able to this simply with

save libname, "maple.ini":

with "maple.ini" replaced with the path to the file.  There is an issue with this; the save command creates assignments that are terminated with a semicolon rather than a colon.  It's best if executable statements in an initialization file print nothing, so terminating with a colon would be better.

Completely overwriting the initialization file is generally not a great idea, but may suit your purposes.  A better approach might be to manually insert the call


Then assign SetLibname a procedure that assigns the global variable libname to whatever you desire and save it to an mla that Maple can find.  You could also add an initial assignment to libname to the initalization file.   With that approach you won't have to modify your initialization file; just update the mla.

It isn't clear why you want to modify libname.

I use git for all maple projects.  I don't commit mla files into the repository. I will commit manually produced mw files, however, they are slightly problematic in that there is no good way to compare (diff) two versions on different branches so merging is impractical; you have to chose one or the other. Distributing mla files is fine. On github you can create a release for a project into which you can insert built files, such as mlas. 

I've seen this and reported it. It also occurs with other dialogs.  It helps to remember that y, n, and esc are shortcuts for the choices.

Debugging this without the source is more work than I feel like dealing with at the moment.  Why not just zip the source files and post here, then anyone could rebuild your package.  

Using whattype in code is not recommended. Rather than 

... elif whattype(f) = `^` then ...
    elif whattype(f) = `.` then ...

Use either

... elif f :: `^` then ...
    elif f :: `.` then ...

... elif type(f, `^`) then ...
    elif type(f, `.`) then ...

I prefer the former.

As acer described, using ':-b' = b is one way to pass-along keyword option b.  Another way, which I prefer, is to use the construct _options['b']. See the help page ?using_parameters.   Note that multiple keyword options can be passed along, _options['a','b','c'].

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