Joe Riel

9665 Reputation

23 Badges

20 years, 29 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Using system("start ...") on Windows seems the easy way to go.  Things are more complicated in *nix-land, where there isn't a universal way to launch a system browser.  Here I hacked up a procedure, OpenBrowser, and a module (MapleConfig, used to find browser executable from config file in *nix) that should work with either Windows, Linux, or Mac, though I haven't tested on the Mac.

OpenBrowser := proc(uri :: string)
local browser,cmd,platform;
platform := kernelopts('platform');
if platform = "unix" then
browser := MapleConfig:-Get("Browser", 'strict');
elif platform = "windows" then
browser :="start";
else
error "do not know how to access browser";
end if;
cmd := sprintf("%s %s %s", browser, uri
, `if`(platform = "unix", "&", ""));
system(cmd);
NULL;
end proc:

module MapleConfig()
export Get, ConfigFile;
local MajorVersion;

Get := proc( field :: string
, { strict :: truefalse := false }
, $
)
local configfile
, line
, match
, val
;
uses FT = FileTools;
configfile := ConfigFile();
if not FT:-Exists(configfile) then
error "could not find config file '%1'", configfile;
end if;
match := cat(field,"=");
try
do
line := FT:-Text:-ReadLine(configfile);
if line = NULL then
error "field %1 not found in config file";
end if;
if SearchText(match, line) = 1 then
break;
end if;
end do;
finally
FT:-Text:-Close(configfile);
end try;
val := line[length(match)+1..];
if strict and val = "" then
error "no value given in configuration file for %1", field;
end if;
return val;
end proc;

ConfigFile := proc()
StringTools:-Join([kernelopts('homedir')
, ".maple"
, MajorVersion()
, "maplerc"
], kernelopts('dirsep')
);
end proc;

MajorVersion := proc()
local ver;
ver := convert(kernelopts('version'),string);
substring(ver, SearchText(" ",ver)+1 .. SearchText(".",ver)-1);
end proc;

end module:

These ideas are useful, thanks.  Anyone know where Maple's configuration file exists on a Windows installation?  I don't use Windows enough to recall.  On linux, it typically is at ~/.maple/15/maplerc, with 15 being replaced by the major release. How 'bout on a Mac? 

There is an extra opening parenthesis to the left of Ts(t).

That's the basic idea. Thanks. The problem with that is that it requires specific knowledge of the browser executable.  I'd like to be access the browser from Maple with code that works on various platforms. I suppose one way to do this is to extract the executable information from Maple's configuration file. That's a bit kludgy, but doable, however, that only handles part of the problem.  What I'd really like to do is simply call a command, say, DisplayInBrowser("some url"), and the configured browser would open with the contents of "some url" displayed. The GUI already has this ability, what is missing is an API accessible to the user.

One way to do this is to connect an ideal rolling wheel (1-D Mechanical --> Rotational --> Common --> Ideal Rolling Wheel) to the output, set the radius of the wheel to whatever is appropriate, then attach a probe to the hub.  MapleSim currently doesn't output units; the plots are scaled in the standard SI units (velocity is in meters/second).  One way to scale the plot is to multiply the radius of the wheel by 1000.

Given that the Ackermann function will rapidly consume all of Maple's stack space, the following might be instructive.  Note the use of the forward quotes (and ?procname) to prevent full evaluation.

A := proc(m,n)
    if m=0 then 'procname'(args)
    elif n=0 then procname(m-1,1);
    else
        'procname'(m-1,procname(m,n-1));
    end if
end proc:

A(4,10);
       A(3, A(3, A(3, A(3, A(3, A(3, A(3, A(3, A(2, A(1, A(0, A(0, 1))))))))))))))

Note that ?mul acts analogously to ?add; you may or may not want to replace the ?product with ?mul. To see the difference, try Robert's routine with, say, F(a,-1).

 

plot3d(x^2+y^2+2*x, x = 0 .. 3, y = piecewise(x<2,sqrt(4-x^2),0) .. sqrt(9-x^2);

You can use the MathML notation when defining aliases.  For example,

alias(`#msup(mi("y"),mi("*"))` = ystar):

That  creates the symbol with the star in the exponent slot.

Also, there is another facility, ?macro, for achieving almost the same thing. The order of the defining equation is reversed:

macro(ystar = `#msup(mi("y"),mi("*"))`):

In some ways macro makes more sense here, where you are creating a shortcut for entering a name.

The drawback with either technique is that they don't expand during input. Because I normally use Maple input that isn't an issue, however, if you are using 2D input it would be nice if the pretty-printed form appeared while typing, that is, as an actual shortcut.

The following does what you want. The technique is to declare the parameters as ?uneval, and then evaluate them inside the body of the procedure.

f := proc(A::uneval, B::uneval)
local a,b,La,Lb;
    a := convert(A,string);
    b := convert(B,string);
    La := eval(A);
    Lb := eval(B);
    return a = La, b = Lb;
end proc:

A1 := [1,2]:
B1 := [3,4]:

f(A1,B1);
                         "A1" = [1, 2], "B1" = [3, 4]

 

It isn't apparent that a symbolic solution can be found; the equations correspond to a set of quartic polynomials.

You can always use backquotes (also known as left single quotes) to form a Maple ?name from non-alphabetic characters:

`Y*` := whatever;

You could manually restructure the sum:

H:=proc(y,a,b) local z;
    z := piecewise((y>0), a,b);
    z + y;
end proc:
prep2trans(H);
proc(y, a, b)
local z;
    z := (if 0 < y then a else b end if); z + y
end proc

As Acer points out, op(0,.) is the way to go. One might imagine that ?unapply could be used here.  That is, 

unapply(f(x),x);
                                    x -> f(x)

could return f, rather than a procedure.  Just thinking

Note that eval isn't doing anything special here, other than substituting and evaluating an expression.  In the first case, g(u) becomes proc() ll end(u), which evaluates to ll.  In the second, g(u) becomes ll(u), and unless ll is assigned a procedure, it returns unevaluated.

 

First 48 49 50 51 52 53 54 Last Page 50 of 114