Joe Riel

9630 Reputation

23 Badges

19 years, 243 days

MaplePrimes Activity


These are answers submitted by Joe Riel

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).

Am not certain, but believe there is not a way to do this, at least if you want to refer to the object itself from a procedure in a submodule. You could, of course, do
 

A:=module()
    option object;
    local name::string:="";

    export ModuleCopy::static:= proc( self, proto, name::string, $)
         self:-name := name;
    end proc;

    export process_1::static:=proc(_self,$)
       B:-process_2(name);
    end proc;

    #method process_2 is now inside a module.
    local B :: static := module()
    export
        process_2::static:=proc(nm :: string)
            printf("in B:-process_2: %s\n",nm);
        end proc;
    end module;

end module:

o:=Object(A,"me"):
o:-process_1();

 

This looks like a bug.  I'll report it.  Note that the help page for copy does not state that it is intended for copying objects, however, it doesn't say what it does if the input is other than a table, rtable or record and the deep option is used.

What were you intending? 

2 3 4 5 6 7 8 Last Page 4 of 114