Joe Riel

9575 Reputation

23 Badges

19 years, 52 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@acer The OP will have to clarify, but my guess is that he is writing the code in a worksheet and used that method to break the code into chunks instead of one giant input region.  I would not recommend that style.  In external files, use preprocessor $include statements.

@nm My mistake.  I had forgotten about the use of A in foo and was testing the use of _self:-A and A in ModuleCopy. On reflection that made no sense in that there the A appears on the lhs, so wouldn't affect the "otherwise unused" nag.

As before, you can eliminate this nag by adding, somewhere in the assignment to A_class,

$ifdef MINTONLY
      A;
$endif

The preprocessor conditional isn't necessary, the naked A will do, but it's generally better to be clear.

@nm Note that the workaround (using a preprocessor conditional to fake usage) to selectively suppress the mint warning is independent of whether you use _self:-A or A in the code.  

@nm Here's a workaround, again using preprocessor macros.  Not ideal, but it avoids the mint nags and allows using the object local variables without the object name prepended (A vs _self:-A).
 

kernelopts('assertlevel'=2):

$ifdef MINTONLY
$define USE_SELF _self;
$define USE_PROTO proto;
$else
$define USE_SELF
$define USE_PROTO
$endif


A_class:=module()
option object;
local A :: integer :=0;
export
    ModuleCopy :: static := proc( _self, proto :: A_class,m::integer)
        USE_SELF; USE_PROTO;
        A := m; #initialize object private variable
end proc;

export foo :: static := proc(_self,$)
local eq;
    USE_SELF;
    eq := A^2;
    return eq;
end proc;

end module:


a := Object(A_class, 23):
foo(a);

Just a note; I frequently find it useful to make parameters to ModuleCopy optional by giving them defaults based on the proto parameter; if that was done here you wouldn't need USE_PROTO.  For example
 

export
    ModuleCopy :: static := proc( _self, proto :: A_class, m :: integer := proto:-A)
        USE_SELF;
        A := m; #initialize object private variable
end proc;

 

@nm Try the following.  It runs with assertlevel=2 and is mint clean (I never use maplemint):

kernelopts('assertlevel'=2):

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 :: A:-B;
        a := Object(B);
        a:-n := 2;
        a:-foo(23);
    end proc;
end module:


A:-foo();

 

Please upload a worksheet with the equations.  Use the green up-arrow on the toolbar of this site when replying.

I hadn't considered using codegen[optimize] directly in the Custom Component template.  Will create a request for enhancement.

With Emacs, I search for the regular expresssion \<i\>.  An alternative is to use the debugger.  Consider
 

foo := proc()
    for cnt to 20 do
        "whatever";
       i := cnt;
    end do;
end proc:

stopwhen([foo,i]):
foo();

That will cause the debugger to stop at the statement which assigns the i.

The solution includes the equations {Vx[XQ601A] = v[D], v[D] = v[D]}.  Syrup interprets the presence of Vx[XQ601A] and v[D] to mean there are an unsolved variables (they are solving variables).

@mehdibgh I assume that in the real problem you are using Matrices or Arrays, which are mutable Maple structures (in this context, mutable means they can be changed without reallocating memory). If possible, the best approach would be to continually reuse an assigned Matrix, or small number of Matrices. In the toy problem you gave, my suggestion computes a Matrix with symbolic values one time, however, the following loop then generates a separate Matrix with each increment.  If you don't need to save all the resulting matrices, you could do something like the following
 

U := simplify((A+1/A).B);
V := copy(U); # one time allocation of V
for s to n do
    subs['inplace'](t=s, V); # modify V 
    # do something with V     
    V[] := U[];              # transfer content of U to V, but don't allocate more memory
end do:

 

@pallav It's called the empty symbol.  Look for help page for emptysymbol or the expression itself (``).  Because it typically doesn't display, a function call using the empty symbol as the function will appear as a set of parentheses enclosing the arguments to the function call. 

Note, the help page for the emptysymbol is a bit strange in that the third paragraph describes how one can assign an expression to the emptysymbol (a roundabout way of saying it isn't protected). I cannot think of any good reason to do this. A nice feature of the empty symbol is that, as Kitonum shows, the expand procedure will undo it (that fact should really be mentioned in the help page).

That change is not advisable.  Note that in your case, the parameter s_rel0 = 0, so if the absolute value was used, contact would effectively never occur. The elasto-gap device is supposed to model lift-off (i.e. force goes to zero when spring lifts off a surface); as such it has to consider the sign of the distance.  The confusion comes about because, when thinking about physical distances it is natural to consider only the magnitude and not the sign. 

@Christian Wolinski Thanks for the correction.

My first version of Maple was Maple V.  It included a hard-cover Maple V Language Reference Manual, which is close to what you want, but isn't really more useful than the current programming guide, though it did contain a formal syntax of the Maple language written in BNF grammar. 

@Carl Love Am submitting a request for enhancement to add a suitable ModuleType method to MutableSet.

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