Joe Riel

9610 Reputation

23 Badges

19 years, 176 days

MaplePrimes Activity


These are answers submitted by Joe Riel

MapleSim comes with DA and AD components; look in Electrical -> Analog -> Converters.

Another approach is to replace the WARNINGS procedure with something suitable.  Here's a quick hack job that demos the idea (it needs work):

Warnings := module()
option package;

local catchall, formats, warnings;

export
    Catch := proc(fmts? :: seq(string), { all :: truefalse := false })
        if all then
            catchall := true;
        else
            formats := [fmts?];
        end if;
    end proc;

export
    ModuleLoad := proc()
    global WARNING;
        unprotect('WARNING'):
        WARNING := proc(fmt)
            if catchall or Match(fmt) then
                warnings[fmt] := StringTools:-FormatMessage(fmt, _rest);
            else
                print('INTERFACE_WARN'(1,fmt,_rest));
            end if;
        end proc;
        protect('WARNING'):
        Clear();
    end proc;


export
    Display := proc()
    local msg;
        for msg in [entries(warnings,'nolist')] do
            printf("%s\n", msg);
        end do;
    end proc;

export
    Caught := proc(fmt)
        ormap(f -> SearchText(fmt,f)=1, [indices(warnings,'nolist')]);
    end proc;

export
    Match := proc(fmt)
        ormap(f -> SearchText(f, fmt)=1, formats);
    end proc;

export
    Clear := proc()
        warnings := table();
        NULL;
    end proc:

export
    ModuleUnload := proc()
        kernelopts('unread' = ':-WARNINGS');
    end proc;

    ModuleLoad();

end module:

You could use it in the following manner

with(Optimization):
expr_optimize := fSW__Ratio_Tol[XU5]*f_ratio__SpreadSpectrum[XU5]*(R34^2*k1__RT[XU5] + R34*k2__RT[XU5] + k3__RT[XU5])/R34^2;
seqUnknownRanges := (NULL
                     , R34 = 5.640*10^4*Unit('Omega') .. 6.160*10^4*Unit('Omega')
                     , k1__RT[XU5] = 4.054*10^4*Unit(1/('s')) .. 4.054*10^4*Unit(1/('s'))
                     , k2__RT[XU5] = 1.593*10^11*Unit(1/('F')) .. 1.593*10^11*Unit(1/('F'))
                     , k3__RT[XU5] = -2.645*10^15*Unit('m'^4*'kg'^2/('s'^7*'A'^4)) .. -2.645*10^15*Unit('m'^4*'kg'^2/('s'^7*'A'^4))
                     , fSW__Ratio_Tol[XU5] = 0.950 .. 1.050
                     , f_ratio__SpreadSpectrum[XU5] = 1 .. 1.250
                    ):

proc()
uses Warnings;
    Catch('all');
    NLPSolve(expr_optimize, seqUnknownRanges, 'useunits', 'method' = 'modifiednewton', 'optimalitytolerance' = 0.101);
    if Caught("convergence is not assured") then
        error "caught it";
    end if;
end proc();

Error, (in anonymous procedure) caught it

 

I don't know of a good way to do this.  I believe it is possible to use html in the entries, say to force a fixed-width font and then insert horizontal space to fake two columns, however, the result is not pretty.  My recollection is that doing so inserts unwanted vertical space between rows.   Probably you are better off just parenthesizing the constants after the name:  "some acid (3.14)".

For this case there may be a workaround.  Because digits have a fixed width (I believe), you could put the constant first and used a fixed precision with scientific notation.  Then all the values and names would align vertically.  Not ideal but maybe feasible.  If the rows were sorted numerically by the constants (rather than alphabetically by the names) then this would appear almost natural.

Am not sure what you are intending with the use of the `:-' symbol, which is the Maple member operator. Will guess you want assignment.
The piecewise function can be used to express the conditional:

Mtop := piecewise(t < l/2, X*f+t/2, X*f-t/2+l/2);

If you actually want a procedure you could do something like

Mtop := proc(t, X,f, l)
    if t < l/2 then
        X*f + t/2
    else
        X*f - t/2 + l/2
    end if;
end proc:


 

There should be a hyperlink in the preprocessor help page to the kernelopts help page; I'll submit a bug report.  Presumably an assumption was made that the reader was aware of kernelopts; all settable kernelopts options use the format kernelopts(optionname = value).

You haven't specified how the user is accessing the file.  Because it is a Maple source file (not an mw file), there are two standard ways.  From the O/S command line you can do (on linux):

$ maple test.mpl

In a worksheet you can do

> read "test.mpl":

For both cases you'll have to modify the string so it includes the appropriate path to where the file is located relative to the current directory.  Regardless, if the file contains the special symbol (a preprocessor macro) __FILE__, it will be replaced with a string corresponding to the path to test.mpl.  To get an absolute path you can insert the following assignment into test.mpl:

thisfile := FileTools:-AbsolutePath(__FILE__);

After reading the file, the variable thisfile (the name is not significant) will be assigned the absolute path to test.mpl.  You might make thisfile a local to a procedure assignment in test.mpl.  Note that preprocessor macros are only expanded when the file is read.

If you have write permission, you should be able to this simply with

save libname, "maple.ini":

with "maple.ini" replaced with the path to the file.  There is an issue with this; the save command creates assignments that are terminated with a semicolon rather than a colon.  It's best if executable statements in an initialization file print nothing, so terminating with a colon would be better.

Completely overwriting the initialization file is generally not a great idea, but may suit your purposes.  A better approach might be to manually insert the call

SetLibname():

Then assign SetLibname a procedure that assigns the global variable libname to whatever you desire and save it to an mla that Maple can find.  You could also add an initial assignment to libname to the initalization file.   With that approach you won't have to modify your initialization file; just update the mla.

It isn't clear why you want to modify libname.

I use git for all maple projects.  I don't commit mla files into the repository. I will commit manually produced mw files, however, they are slightly problematic in that there is no good way to compare (diff) two versions on different branches so merging is impractical; you have to chose one or the other. Distributing mla files is fine. On github you can create a release for a project into which you can insert built files, such as mlas. 

I've seen this and reported it. It also occurs with other dialogs.  It helps to remember that y, n, and esc are shortcuts for the choices.

Debugging this without the source is more work than I feel like dealing with at the moment.  Why not just zip the source files and post here, then anyone could rebuild your package.  

Using whattype in code is not recommended. Rather than 

... elif whattype(f) = `^` then ...
    elif whattype(f) = `.` then ...

Use either

... elif f :: `^` then ...
    elif f :: `.` then ...
or 

... elif type(f, `^`) then ...
    elif type(f, `.`) then ...

I prefer the former.

As acer described, using ':-b' = b is one way to pass-along keyword option b.  Another way, which I prefer, is to use the construct _options['b']. See the help page ?using_parameters.   Note that multiple keyword options can be passed along, _options['a','b','c'].

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.

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