Joe Riel

8338 Reputation

22 Badges

15 years, 326 days

MaplePrimes Activity


These are answers submitted by Joe Riel

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;
export
    ModuleCopy :: static := proc(self :: foo
                                 , proto :: foo
                                )
        protect('self:-bar');
    end proc;

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

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

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

(**) foo1:-bar;
                                                             23

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.

The first column of the spreadsheet defines the values for u, the first row defines the values for v.  You've got the inputs swapped. The y2 port of IBC1 should be connected to the u pin of VLP, the v pin should be connected to the output of the u2 constant block.  With that fixed, the output is as you expect

Yes, Syrup has the equivalent of the SPICE ac circuit analysis; that's probably what it is most useful for. While it does not have the ability to create a circuit via schematic capture, it does include a simple ladder notation that can be used to quickly enter and plot a schematic for a restricted class of circuits.  The latest version of Syrup is available via the Maple Cloud; open the Maple cloud dialog (upper right corner of Maple Standard), go to the public documents and search for Syrup.

The current version can convert its models to modelica, which is the modeling language used by MapleSim.

There are a couple of issues.

The procedure boo is not an export of foo (a procedure, so it has no exports), so calling foo:-boo makes no sense.  Just call boo directly.

For a procedure to access an object's local fields, I believe it has to be a method (local or export) of the object.  The procedure boo is neither (it is local to an export of the object). A workaround is to give it a formal parameter that is passed the value of interest:

module my_class()
option object;
local hint::string:="X"; #private variable to the object

export
    foo :: static:=proc(o::my_class) #can be seen from outside
    local boo; #local proc inside proc foo

        boo := proc(str)
            print("inside boo()");
            print(str);
        end proc;

        print("in foo(), calling local proc boo()");
        print("hint is ",o:-hint); #works OK
        boo(o:-hint);
    end proc;

end module:

o:=Object(my_class);
o:-foo(o);

Another possibility is to promote boo to be be a method of my_class; it can be local.

restart;
module my_class()
option object;
local hint::string:="X"; #private variable to the object
export
    foo :: static:=proc(o::my_class) #can be seen from outside
        print("in foo(), calling local proc boo()");
        print("hint is ",o:-hint); #works OK
        boo(o);
    end proc;
local
    boo :: static := proc(o :: my_class)
        print("inside boo()");
        print(o:-hint);
    end proc;

end module:

o := Object(my_class);
foo(o);

Another solution is to create a method that accesses the field of interest, than call it.

module my_class()
option object;
local hint::string:="X";

export
    foo :: static := proc(o::my_class)
    local boo;

        boo := proc(o)
            print("inside boo()");
            print(o:-GetHint(o));
        end proc;

        print("in foo(), calling local proc boo()");
        print("hint is ", o:-hint); #works OK
        boo(o);
    end proc;
export
    GetHint :: static := proc(o :: my_class)
        o:-hint;
    end proc;
end module:

obj := Object(my_class);
foo(obj);

Another possibility, to avoid reallocating memory, is to use 1-D Array for the original data and then use ArrayTools:-Alias to partition it. For example:

A := Array(1..12, i->i):
B := ArrayTools:-Alias(A, [3,4]):
B[..,3];
                                    [7]
                                    [ ]
                                    [8]
                                    [ ]
                                    [9]

I set up links in ~/bin, which is in my PATH, to point to the installed scripts.  So usually do something like
 

ln -s /opt/maple2020/bin/maple ~/bin/maple
ln -s /opt/maple2020/bin/mint ~/bin/mint

With that, tty maple can be launched using maple on the command line.

If you don't know where maple is installed, but can run it, execute kernelopts(mapledir).

With recent versions of Maple Standard, the current directory is displayed in the status bar (bottom of window).  Click on the display to bring up a directory browser to change the current directory.

See the help page for try/catch.  It mentions that a stack overflow is not trappable, which is reasonable.

The problem in `discont/zero` is that it factors a particular expression f into -I*(I*f) then recursively applies itself to both factors, which won't terminate. 

Having a static module inside an object means that module will be shared by all objects of the class.  As such, it doesn't make sense to have non-static things inside the module. Specifically, big_car_name will be the same as the last assigned 'name' for all the objects.  If that is what you want, it seems better to just declare big_car_name as a static local to car_class.  However, you could still do what you want, but I'm not seeing a reason to be passing an object into big_car:-set_name.  So to keep the submodule, I'd do something like

car_class := module()
option object;

local name :: string :="UNKNOWN";

export
    set_name::static:=proc(o::car_class,nm::string)
        o:-name := nm;
        big_car:-set_name(nm);
    end proc;

    #this is module, that I want to be private to this class only
    #eventually, I'd like this module be in separate mpl file also.
local
    big_car :: static := module()  #module does not take arguments!

        #this below should be private only to the this module
        #and not seen by the enclosing object.
    local big_car_name :: static(string) := "UNKNOWN";

        #this export to allow parent object to call it
    export set_name :: static := proc(nm :: string)
        big_car_name := nm;
    end proc;

    end module;

end module:

o:=Object(car_class);
o:-set_name(o,"GM");

Note that I also renamed '_name' to 'nm'. While not an issue here, symbols with leading underscores are supposed to be reserved for Maple library stuff; it's better not to be use them.

There are a couple ways to do this.  One is to open attach a Maple worksheet to the MapleSim model, get the data for the simulation by using the LinkModel and Simulate, import the data for the comparison (using the Maple Import command, or something equivalent), then plot both in Maple.  Something like the following

A := MapleSim:-LinkModel():
simdata := A:-Simulate('returntype=datapoint'):
extdata := Import("MyData.xls"):
# plot the x (say 2nd col) vs t (1st col) of simulation and external data
plot([simdata[..,[1,2]], extdata[..,[1,2]]]);

An alternative approach is to do this entirely in MapleSim. Attach the external data to the MapleSim model, then insert a time table (Signal Blocks > Interpolation Tables > Time Table) and set it to use the attached data (assuming data is in proper format). The output of the block should then reproduce the data of interest. Probe it and compare to the simulated probe.

With this second approach it is fairly easy to generate an error signal between the two (form the difference, square and integrate) and then use the ParameterSweep and Optimization apps to fit model parameters.

If the read command, which reads maple source code, results in assignments to EQ_1, EQ_2, etc., then you can simply do

EQlist := [EQ_1, EQ_2, ... ];

Is that Maple15 (quite old) or Maple 2015?  Regardless, neither can read a .maple file.  The format is an sqlite database, so you should be able to use sqlite to extract the contents of the file.

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