Joe Riel

8338 Reputation

22 Badges

15 years, 329 days

MaplePrimes Activity


These are answers submitted by Joe Riel

In the Type menu, select Custom and then enter Modelica.Thermal.FluidHeatFlow.Interfaces.FlowPort in the text area and click Apply Custom.  You can also enter FlowPort_a to get a filled port or FlowPort_b to get an open port.

Something seems wrong.  I build a package with many includes. The number of source lines is over 100K.  It takes 2 seconds for Maple to process it. 

Are you sure you have write permission to the directory which is being used (execute currentdir() to determine that)?

The short answer is that unless you can just combine the modules into one, you'll probably have to edit code.  If it's a lot, you might consider how to automate it.  For example, use the exports Maple command to get the exports of a module, then use StringTools commands to update source files.  If a unix user, consider generating a sed script to do the update. Backup stuff so you can recover from the inevitable errors.

This is one of a few reasons to alway use the equation binding form in a uses statement.  For example

proc()
uses ST = StringTools;
      ST:-RegMatch(...);
end proc:

Another is that if you use the name form, an addition to the package being used could break code if you had used an identifier that matches an export. 

Because you have the source, an alternative is to hard-code a call to DEBUG() inside the procedure.  For example,
 

foo := proc()
local k,y;
    y := 0;
    for k to 10 do
        if k > 3 then
            DEBUG();
         end if;
        y := y + k;
    end do;
end proc:
foo();  # the debugger will be invoked when k reaches 4.

 

I've added an option to the Iterator:-Partition procedure that specifies the maximum value of a partition.  For example

P := Iterator:-Partition(100,'maxvalue'=35):
add(1, p=P);
                                    178299181

That took a bit under 8 minutes. The cardinality differs significantly from what you show.  Will investigate.

Later The cardinality from the Sage math output is different because it is returning partitions with distinct values.   Iterator:-Partition generates all partitions.  For example
 

(**) P := Iterator:-Partition(7,maxvalue=4):
(**) Print(P,showrank);
 1: 4 3 
 2: 4 2 1 
 3: 4 1 1 1 
 4: 3 3 1 
 5: 3 2 2 
 6: 3 2 1 1 
 7: 3 1 1 1 1 
 8: 2 2 2 1 
 9: 2 2 1 1 1 
10: 2 1 1 1 1 1 
11: 1 1 1 1 1 1 1 

 

A practical method is to create a Maple archive (mla file) from the source, then access it from Maple.  To access it from Maple you can either modify libname, or (better), install the mla into a custom toolbox where it will be automatically found.  On my linux box that means installing it in, say, /home/joe/maple/toolbox/foo/lib/foo.mla, where the package name is foo

Depends on what you want to do with the data structure.  Maple tables and MultiSets behave quite differently. 

The foldl procedure can be used to generate the expression

foldl(((o,k)->1+z^k/o),1,seq(7..1,-1)); 

In Maple2021 you can use the fold option to seq

seq[fold=(((o,k)->1+z^k/o),1)](7..1,-1);

Try the following
 

Y := Ym*(c/((d + 1)*(X - X__0) + c))^(d + 1)*exp((X - X__0)*(d + 1)^2/((d + 1)*(X - X__0) + c)):
Xsol := solve(Y = Ym/2, X):
simplify(Xsol);
                1/(d+1)*(d*X__0+X__0-c-1/LambertW(-2^(-1/(d+1))*exp(-1))*c)

 

A simple approach is to convert to a ZeroPoleGain form of transfer function and then truncate all poles and zeros greater than some arbitrary frequency.  That may give acceptable results if the frequencies of the truncated poles and zeros are much greater than the dominant ones.

Alas, in the Graph plotting returns, non-integer weights are printed as floats using sprintf("%0.3g", weight).  That should probably be modified.  There is a hack that you can use.  The idea is to temporarily replace the sprintf function with your own version, one which arbitrarily repaces any use of "%0.3g" as the format string with "%a".  Here's how you do so
 

unprotect(sprintf):
oldsprintf := eval(sprintf):
# temporarily replace sprintf with ad hoc version
sprintf := proc(fmt) oldsprintf(ifelse(fmt="%0.3g","%a",fmt),_rest); end proc:
# create the plot
P := (DrawGraph)(G, style=tree, root=Omega,size=[400,400]):
# restore sprintf
sprintf := eval(oldsprintf):
r := plottools:-rotate(P, Pi/4);

If you plan to draw several graphs, you might create your own procedure that incorporates this hack.

MyDrawGraph := proc()
global sprintf;
local oldsprintf;
    unprotect('sprintf');
    oldsprintf := eval(sprintf);
    sprintf := proc(fmt) oldsprintf(ifelse(fmt="%0.3g","%a",fmt),_rest); end proc;
    try
        return GraphTheory:-DrawGraph(_passed);
    finally
        sprintf := eval(oldsprintf);
        protect('sprintf');
    end try;
end proc:

 

For a Matrix of floats, you can map the round function to each element:

N := map(round, data);

However, by default, Import returns a DataFrame with an Array of type datatype=float[8], and mapping over that will leave the datatype=float[8], so the result still appears to be floats. You may need to first convert the data to a Matrix. Alternatively you can use the output option to Import to specify a Matrix, then map over that:

data := Import("foo.xlsx", 'output=Matrix'):
data := map(round, data);

 

It's not entirely clear what you want. Regardless, use a loop with a conditional such as

if StringTools:-RegMatch("\\.edu$", M[i,1]) then ... end if

to test the string in row 1, column 1 of the imported Matrix.

A few comments. 

  1. There is no type 'real' in Maple.  Maybe you want 'float', or 'realcons'.
  2. Adding a type declaration to procedure output (here the ' :: real) has no effect unless kernelopts(assertlevel) is set to 2 (the default is 0).
  3. A semicolon is used as a separator in the local statement; change it to a comma.
  4. Profiling won't work if an error is raised.

One way to profile the local Test2 (assuming the divide-by-zero statement is removed) is to do so inside Test.  For example

Test := proc(a,b)
local c, Ergebnis;
    Test2 := proc(d,e) #Prozedur zum Schreiben der Ausgaben
        f:=d+e;
        g:=f*d;
        5+3;
        # 3/0;
    end proc:
    debugopts('traceproc'=Test2);
    c:=a+b;
    Ergebnis := Test2(a,c);
    printf("%s\n", debugopts('procdump'=Test2)):
end proc:

Test(3,4);

One way to find an error is with the debugger, say first execute stoperror(all) then call Test.  That should cause the debugger to open at the offending statement. Alas, that won't help here because the error occurs during simplification, as the zero in the denominator is hard-coded into the source and so the error is raised when the procedure is assigned, not when it is executed.

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