Joe Riel

9470 Reputation

23 Badges

18 years, 64 days

MaplePrimes Activity


These are answers submitted by Joe Riel

To avoid unassigned locals from generating mint nags, you can declare them as type nothing.  For example

foo := proc(c1, c2)
local x :: nothing;
    c1*x + c2;
end proc:

That should mint clean (haven't actually tried it).

The A:- are not required in foo.  Without them, mint is clean.  That aside, there are constructs that generate harmless mint nags.  To avoid them preprocessor conditionals can be employed.  For example, consider adding the following to your B object:

    local m := 23;
    export
        foo :: static := proc(_self, x)
            m + x;
        end proc;

When minted you'll get the nag "These parameters were never used:  _self".  One solution is

    export
        foo :: static := proc(_self, x)
$ifdef MINTONLY
            _self;
$endif            
            m + x;
        end proc;

In the mint startup file (~/.mintrc) I have

-DMINTONLY
-D_DEBUG_jriel

That causes the preprocessor variables MINTONLY and _DEBUG_jriel to be assigned (true) when minting. You could, instead, pass them as arguments to mint.  With MINTONLY assigned, the preprocessor conditional inserts the _self; statement into the stream, and so prevents the generation of the warning.

Addendum My foo is separate from your foo; mine is an export of B.  Here's the complete source I used

A := module()

local
    B := module()
    option object;
    export n::integer := 1;
    local m := 23;
    export
        foo :: static := proc(_self, x)
$ifdef MINTONLY
            _self;
$endif
            m + x;
        end proc;
    end module;

export
    foo := proc()
    local a :: B;  # mint complains that A is global not declared!
        a := Object(B);
        a:-n := 2;
        a:-foo(23);
    end proc;
end module:

 

Here's more or less what you want, I believe,

g := proc(`n+1/3`)
local n;
    n := `n+1/3` - 1/3;
    if n = 0 then 1 else 0 end if;
end proc:

Note that the construct `n+1/3` is just a fancy looking symbol. 

A simpler approach is

g := charfcn[1/3]:

 

An alternative is to use assign.  A downside is that you then have to forward-quote the assignee, else an error will be raised:
 

A := module()
local r :: integer := 0;
export
    set_r := proc(rr :: integer)
        assign('r', rr);
    end proc;
export
    get_r := proc()
        r;
    end proc;
end module:

A:-set_r(10);
A:-set_r(20);
A:-get_r();

I don't see any advantage to doing this versus adding an explicit NULL.

The actual problem is the use of D as an argument node for the two subcircuit definitions.  Because D is an assigned Maple procedure, it gets replaced with an internal name, D0, however, the replacement is not being done everywhere (the constraints are missed).  If you replace the D with d then you will get a solution. I'm looking into a fix.

A nicer way to pass-on a keyword parameter is to use _options['debug']. See the help page using_parameters.

An alternative approach is to use MapleSim:-Tools:-MapleToModelica, which can produce a Modelica block suitable for use in MapleSim.

A better way to do this is something like
 

U := simplify((A+1/A).B);
for s to n do
    V[s] := eval(U, t=s);
end do:

 

Here's a somewhat crude approach:

AssocPower := proc(ex? :: string)
    local ex := StringTools:-SubstituteAll(ex?, "^", "&&^");
    ex := parse(ex);
    eval(ex, `&&^` = `^`);
end proc:

AssocPower("a^b^c");
                                         a^(b^c)

That works because the &&- operators (see operators,precedence) are right-associative, unlike the &- operators, which are left-associative. 

Alas this simple approach, which calls parse, won't handle general Mathematica expressions, so doesn't really help you. Also, as the precedence of &&- operators is slightly greater than the ^ operator, in Maple, there can be other issues.  For example
 

AssocPower("a^b!");   #--> (a^b)!
parse("a^b!"); #--> a^(b!)

 

Presumably a bug in the external routine.  Here's a simple workaround,

SplitString := proc(s :: string, len :: posint)
local i;
    seq(s[i..i+len], i=1..length(s), len);
end proc:

 

ModuleLoad is executed when the code is loaded from a Maple archive (mla file).  It won't be executed if the module has been assigned in another way (say by entering it as text).  A workaround is to modify your source to call ModuleLoad when it is evaluated:

foo := module()
option package;
export ModuleLoad := proc() .... end proc;
...
ModuleLoad(); # call ModuleLoad when evaluating the source for foo
end module:

 

A workaround is to introduce another parameter, say sqrt3 = sqrt(3) and assign a = L/sqrt3.  You can then backsubstitute sqrt3 = sqrt(3) in the extracted equations.

Followup That doesn't address your request to keep a.  Because L only enters through a (I believe, haven't carefully checked your model), you should be able to do subs(L = a*sqrt3, sqrt3 = sqrt(3), %);

I have written a package, Bark, available on the Maple Cloud, that partially addresses this issue.  I use it to convert Maple programs into command line tools. Because I work almost exclusively on Linux, it hasn't been tested much on Windows, though I did so originally.  However, on Windows it requires Cygwin (it creates a small bash file that calls maple).  It possibly could be extended to work from PowerShell, however, I didn't know enough about PowerShell to do so.

There are quite a few ways to do this in Maple.  Here's one. 

M := Matrix([[1,2,"A"],[2,3,"B"],[3,4,"A"]]):

# create list of indices of the desired rows
rows := [seq(ifelse(M[i,3]="A", i, NULL), i=1..upperbound(M,1))]:

# create submatrix that contains the desired rows
M[rows,..];

 

Function calls use parentheses, not square brackets.  Also, the exponent should be applied after the parentheses.  That is, change f^2[n-2] to f(n-2)^2 and f[n-1] to f(n-1).  To compute the derivative, do eval(diff(f(18),x), x=2*Pi).

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