Joe Riel

9540 Reputation

23 Badges

18 years, 270 days

MaplePrimes Activity

These are answers submitted by Joe Riel

Not quite sure what you mean by white space in this context; ReadFile returns a string with newline characters. You could do, for example,

str := FileTools:-Text:-ReadFile(somefile):
lines := StringTools:-Split(str, "\n");

to create a list of strings, one for each line in the original file.

The Syrup package, which is available on the Maple Cloud, has a ladder input notation that can be used to generate images of certain types of circuits.  For the example above you could do

ckt := [ (R1(4) &+ V1(3)) &// R2(3) &// (R3(1) &+ V2(4))]: 

It's not the nicest looking rendition but is fast and easy to enter.

Differentiating the sliding average returns a delay-differential equation that dsolve can handle numerically.  That is,

deq := diff(xavg(t),t) = (x(t) - x(t-T))/T

You could then do, for the first case

dsol := dsolve(subs(T=1/2), [deq, xavg(0) = 0]), 'numeric'):
plots:=odeplot(dsol, 0..3);

The plot is shifted vertically because I set xavg(0) = 0.

You can enter the system using the ZeroPoleGain form:

zpk := ZeroPoleGain([1],[1,2],1):

Alas, when converting to other forms the zero/pole will get cancelled.  Note that the cancellation option is normally false; it is used to actively cancel pole/zero pairs that are within a given distance, set by the relativeerror option.  So that won't help you.  What you can try, as a workaround, is to enter an offset as a symbolic parameter and give it a default of 0:

zpk := ZeroPoleGain([1+delta],[1,2],1, parameters=[delta=0]):

The parameter values are used with certain operations such as when generating plots, etc.  Here is the State Space representation.

ss := StateSpace(zpk):
use ss in a,b,c,d end use;
   Matrix(2, 2, [[0, 1], [-2, 3]]), Matrix(2, 1, [[0], [1]]), Matrix(1, 2, [[-1 - delta, 1]]), Matrix(1, 1, [[0]])

To avoid the issue, you can pass additional arguments to ResponsePlot:

p2:=DS:-ResponsePlot(sys_filter2, DS:-Step(), duration=0.0001,color=blue,legend="step2", dsolveargs=[stiff=true]):


For an Array that could be done by passing a sorting procedure to the sort procedure.  Alas, the DataFrame object assigns the sort method that it uses and it currently doesn't provide for an option for a sorting procedure.  One workaround is to apply the regular sort procedure to the list of row indices of the DataFrame and then use the resulting permutation to sort the DataFrame. Here's an example, using the Flashlight example you pointed to

Prows := [seq(1..upperbound(Flashlight,1))]:
CostMax := max(Flashlight["Cost"]):
P := sort(Prows, 'key' = proc(i) Flashlight[i,"Batteries"]*(CostMax+1) + Flashlight[i,"Cost"] end proc):
Flashlight[P,..]; # permute the rows 

Note that the example used a key function rather than a sorting function; doing is more efficient in that it only has to be evaluated once for each row.

Two approaches

catint1 := proc(a,b)
end proc:

catint2 := proc(a,b)
end proc:

The second appears to be faster.

Another possibility is to return a record; slots without values can be assigned NULL or whatever you prefer.  An advantage to that approach is that it is frequently much clearer in the code what is being returned.  This is particularly the case when returning more than a few expressions. 

dummy := proc(expr,num)
end proc:



I avoid this problem entirely by using a Makefile to build and install an mla from Maple source files (i.e. ascii text files).  However, I'm not 100% sure that that works on Windows (I use Linux) which has an annoying habit of preventing files (mlas, in this case) from being deleted if in use. 

The help page to which you are referring, ?repository,management, uses, say, $VERSION as a convenient shorthand for the major version of Maple with no implication that such an operating system environment variable has been assigned. On linux the o/s environment variable MAPLE is assigned when Maple is launched, the others not.  To get the install directory for a particular Maple toolbox, do, for example,

kernelopts('toolboxdir' = 'MapleSim');
convert(data, listlist);

@nm I misunderstood your question (didn't read it thoroughly).  I thought you wanted to access the value with a getter method and change it with a setter method. What you want is to be able to access it directly, but be able to change it only via a setter method.  Hmm.  You should be able to protect it to accomplish that.

foo := module()
option object;
export bar;
    ModuleCopy :: static := proc(self :: foo
                                 , proto :: foo
    end proc;

    set :: static := proc(self :: foo, val);
        self:-bar := val;
    end proc;
end module:
(**) foo1 := Object(foo):
(**) foo1:-bar;

(**) type(foo1:-bar, 'protected');

(**) foo1:-bar := 23;
Error, attempting to assign to `bar` which is protected.  Try declaring `local bar`; see ?protect for details.
(**) set(foo1, 23);

(**) foo1:-bar;

A remember table is not an rtable but a regular Maple table (the "r" in rtable stands for rectangular; rtables are used for Arrays and Array-like structures). Maple tables don't have a last element; that is, there is no way to distinguish the order in which elements were inserted into a table.

If you want the last value computed by a procedure with a remember table, you can assign the computed value, inside the procedure, to a global or module-local, then inspect it when the computation is finished. Note that the last computed value is not necessarily the last returned value; previously computed values may be returned without a computation (that's the point of the remember table).

If you actually want the last returned value, you could wrap the procedure with the remember table insider a larger procedure that calls the one with the remember table and assigns the returned value to a global/module-local.

Assuming you want the last computed value, here is a clever method that avoids using either a module-local or a global. Instead it directly assigns the last computed value to a fixed place in the remember table.

foo := proc(x)
option remember;
local ret;
     # compute value and assign to ret
     foo("last") := ret;
end proc:
foo("last") := "foo was never called": # preassign the last value

To get the last computed value, call foo("last").

Internally 1/(x*y) is represented as, essentially, x^(-1)*y^(-1), so there is no x*y term.

First 9 10 11 12 13 14 15 Last Page 11 of 114