Joe Riel

9530 Reputation

23 Badges

20 years, 26 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Put the procedures in a startup region. Click on the gear-like symbol on the toolbar.

You can use a ?try catch statement to handle exceptions.

try
    ...
catch:
   go here if an error occurs above
end try;

 

 

First, Maple expresses angles in radians rather than degrees. See ?convert,degrees for a method for converting. Second, you might want to check your interpretation of the law of cosines.  The denominator is incorrect

Try using ?plottools[getdata].  For example,

plt := plot3d(sin(x)^2/(2+cos(y)^2), x=0..Pi, y=0..Pi):
pts := plottools:-getdata(plt)[3]:
(min,max)(pts);
                    0., 0.500000000000000000

Posting the code would help.  Note that after completing the loop

for i from 1 to 15 do
  ...
end do;

the value of i is 16 (not 15).  If you later using i without reassigning it then there could be an issue.

I don't know much about bifurcation diagrams other than what I picked up from a quick read of Wikipedia, so don't trust the following without verification.  The idea is to solve for B at equilibrium, which means the diff's are all 0.  To that, I'll first enter the system in proper Maple syntax:

sys := { NULL
, diff(A(r),r) = k + m * Y(r) - A(r) * B(r) * B(r) - A(r)
, diff(B(r),r) = 1/q * (A(r) * B(r) * B(r) + A(r) - B(r))
, diff(Y(r),r) = 1/s * (B(r) - Y(r))
}:

params := {NULL
, k = 10
, q = 5 * 10^(-3)
, s = 2 * 10^(-2)
}:

Next, modify the equations so that the diff is replaced with 0

equil := eval(sys, diff=0):

Use solve to solve the equations

sol := solve(equil, [A,B,Y](r));
(m - 1) k k k
[[A(r) = - -----------------, B(r) = - -----, Y(r) = - -----]]
2 2 m - 1 m - 1
k + m - 2 m + 1

Finally, extract the rhs of B(r), substitute the parameter values, and plot

plot(subs(sol[1], params, B(r)), m = 0..0.18);


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.

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