Joe Riel

9590 Reputation

23 Badges

19 years, 140 days

MaplePrimes Activity


These are answers submitted by Joe Riel

While there is nothing wrong with using a Vector, another approach is to use a list. For example

iterativepower := proc(base, index, n :: nonnegint)
local k;
  [seq(base^(index^k), k=0..n)];
end proc:

Unless you're interested in the discrete steps, it might be better to look at base^p, as p increases. This can be easily plotted, here with base=1+I:

plots:-complexplot((1+I)^p, p=0..25);

Before using subsindets or evalindets, it's usually a good idea to call indets to see what expressions are being operated on. Thus

x := u(i, j)^2*v(i, j)+u(i-1, j):
E := indets(x, 'specfunc(symbol, u)');         # --> {u(i, j)}
F := indets(x, 'specfunc(`+`, u)');            # --> {}
G := indets(x, 'specfunc({`+`, symbol}, u)');  # --> {u(i, j), u(i - 1, j)}

That makes sense to me (see Carl's comments for details). A variation of this is to use an unassigned symbol for the applied function in the call to subsindets:

subsindets(x, 'specfunc(symbol, u)', Z);
      Z(u(i,j))^2*v(i,j)+u(i-1,j)

I'll suggest the following.  Create a Maple module, with option package, and with exports of the desired constants, procedures.  Save this to an mla as a  Maple toolbox.  You will then be able to access any of the procedures/constants from any worksheet by using the module.  Here is example code of how you might do this (it both creates a trivial module and saves it to a toolbox).

# Code to create a simple Maple toolbox for storing constants and whatever (the exports)

MyConstants := module()
option package;
export SpeedLimit;
    SpeedLimit := 65;
end module:

# Temporary procedure to create, if needed, the toolbox directory

MakeToolbox := proc(toolbox :: string)
local dir;
uses FT = FileTools;
    dir := FT:-JoinPath([kernelopts('homedir'),"maple","toolbox", toolbox, "lib"]);
    if not FT:-Exists(dir) then
        FT:-MakeDirectory(dir, 'recurse');
    end if;
    dir;
end proc:

# Create directory and path to toolbox mla
dir := MakeToolbox("MyConstants"):
path := FileTools:-JoinPath([dir, "MyConstants.mla"]);

# Save the module (MyConstants) as a toolbox.
LibraryTools:-Save(MyConstants, path);

You can then access any of the exports (here just one, SpeedLimit) via MyConstants:-SpeedLimit, or do with(MyConstants): and then use SpeedLimit alone. In a procedure you should use a uses statement. If you save all the code above in a worksheet, and then edit the module as desired, you should be able to reexecute it to update the toolbox.

I'm assuming you have a new enough Maple that automatically picks up toolboxes put in the appropriate place.  If not, then you'll probably need to create a Maple initialization file and use it to assign the global variable libname to include the path to an mla file. That was always a sticking point for people new to Maple; the use of toolboxes simplifies the operation. 

It's not too hard to see that the only real solution for eq6 occurs at the limit when Dmax=0.  It's then easy enough to substitute that into eq7 and eq8 and solve for deltaH and de.

limit(eq6, Dmax=0);
                      0
solve(eval({eq7,eq8},Dmax=0));
              {de = -2.638478742, deltaH = 6.260000000}

I suspect that Dmax=0 is not an allowable solution, in which case there are no real solutions.

Use the :: operator rather than = to assign a property name to a variable.  While I don't know why using 'real' doesn't work, the 'realcons' property does. 

Use the method that Carl suggested, but append additional t's to the call to diff. For example,

f:= (t,y)-> -y + t*y^(1/2);
diff(f(t, y(t)), t);   # first derivative
diff(f(t, y(t)), t,t); # second derivative

Alternatively, use

diff(f(t, y(t)), [t$3]); # third derivative

You could use subs, however, you'll have to substitute for both the term and 1/term. Here's a slightly different approach, which replaces the expression of interest with the variable tmp

subsindets(X, 'anything^And(rational,(Not(integer)))', p -> tmp^signum(op(2,p)));

As a practical matter, you'd first want to inspect the elements that match the type in the subsindets call. Do that with

indets(X,'anything^And(rational,(Not(integer)))');
   {1/sqrt((n__x^2+n__y^2+n__z^2)*c^2), sqrt((n__x^2+n__y^2+n__z^2)*c^2)}

Maybe the better way is to first assign the expression of interest to a variable, then use subs

expr := sqrt((n__x^2+n__y^2+n__z^2)*c^2):
subs([expr=tmp, 1/expr=1/tmp], X);

In addition to Carl's suggestions, I think it would be clearer if you used a separate line to extract the rhs of the output of dsolve, when assigning to Y.  That way a reader could see what dsolve returned and would understand the reason for using rhs.

Consider

[a,b,c](x);
            [a(x), b(x), c(x)]

Arguments applied to a list are distributed to each element in the list. If any elements are lists, the distribution applies to them, as well. Consequently, L2(x) is converted to [[1(x)],[2(x)]].  Arguments applied to a number evaluate to the number, for example 3(x) evaluates to 3.  Your result follows from that.

(**) eq := randpoly(x) = 0;                                                       
                         5       4       3       2
               eq := -7 x  + 22 x  - 55 x  - 94 x  + 87 x - 56 = 0

(**) latex(eq);                                                                   
-7\,{x}^{5}+22\,{x}^{4}-55\,{x}^{3}-94\,{x}^{2}+87\,x-56=0

An explicit example would have been helpful.  How about View > Expand all Sections, which can be done from the keyboard via Alt-v e.

It depends on what you want to do with the saved data (a Vector here).  Access it from some other program?  Save as a spreadsheet?  Access it from another Maple worksheet? 

For the latter you could use the save command:

V := Vector(["a","b","c"]):
save V, "V.mpl":  # save as ascii to file V.mpl in current directory
restart;
read "V.mpl":
V;
                                    ["a"]
                                    [   ]
                                    ["b"]
                                    [   ]
                                    ["c"]
 ListTools:-Flatten([[a,b],[[c,d,e]]]);
               [a, b, c, d, e]

Note that that won't work if the lists were sets. For that you could use subsindets:

S := {{{c, d, e}}, {a, b}}:
{subsindets(S, set, op)};
              {a, b, c, d, e}

Maybe nicer is

map(subsindets, S, set, op);
              {a, b, c, d, e}

Element-wise binary operators act more like zip than map when both sides are containers.  To see this, do

(**) [A,B] minus~ [C,D];
            [A minus C, B minus D]

On the other hand,

(**) [A,B] minus~ C;
            [A minus C, B minus C]

So it is natural to think that your use might work. You could do something ugly like

(**) eval([{1,2},{2,3}] minus~ ''{2}'');                                                       
       [{1}, {3}]

A slightly simpler use of map is

(**) map(`minus`, [{1, 2}, {2, 3}], {2});                                                                                                                                                                        
            [{1}, {3}]

Alas, the current design of odetest expects that integration constants are named with prefix _C.  More accurately, they must match the type

And(symbol, suffixed(_C, nonnegint))
First 16 17 18 19 20 21 22 Last Page 18 of 114