Carl Love

Carl Love

19037 Reputation

24 Badges

7 years, 347 days
Mt Laurel, New Jersey, United States
My name was formerly Carl Devore.

MaplePrimes Activity

These are answers submitted by Carl Love

Like this:

eq1:= -2*t1 - 4*t2 - 2*t3:
eq2:= t1 + 2*t2 + t3:
AnyIntegerSol:= proc(eqs::set(linear))
    for local C in Iterator:-CartesianProduct([-1,1] $ nops(eqs)) do
                    0, {eqs[]*~seq(C)} >=~ 1, assume= integer
        end try
end proc
AnyIntegerSol({eq1, eq2});
                   [t1 = -1, t2 = 0, t3 = 0]


The command combinat:-permute handles the "with repetitions" case. With a minor adjustment, shown below, it will handle vector input.

    (L::coerce(list, (L::{set, rtable})-> [seq](L)), n::nonnegint)->
alllexicographic(<A,B,A>, 3);
               [[A, B, A], [A, A, B], [B, A, A]]

With additional minor adjustments, it could also handle string input, and it could make the output format the same as the input format.

Here's one of several ways:

F:= [0.5623, 0.4402, 0.3168, 0.0689]: 
    style= point, symbol= diagonalcross, symbolsize= 24, 
    color= red, axes= boxed, labels= ['x', 'F'],
    view= [0..nops(F)+0.5, 0..1.2*max(F)]

It's not a dumb question; indeed, the issues involved are fairly deep and idiosyncratic to Maple.

First, this issue has nothing to do with VectorCalculus. It would also happen with a plain Vector.

There are occasionally situations where a Vector (Matrix, rtable, etc.) contains a symbolic entry (such as your A), that symbol is assigned a value, and the Vector (rtable, etc.) appears to not be updated. Unfortunately, this can be quite confusing to the user. If you perform subsequent computation with V, the result will use the information A=1, and that will be shown as expected. But if want to explicitly see that in V itself, you need to use either

rtable_eval(V, inplace)

The first of these makes the update in a copy of V, without changing itself. This would allow you to assign another value to A and have that change affect (note that this is a potentially beneficial aspect of this weird behavior). The inplace version makes the update to itself.

An alternative is

indets(sol, _t[nonnegint]);

This will ensure that you only get variables whose names are _t with a nonnegtive integer as an index.

To convert a list or a set into an expression sequence, use A[]. (Two alternatives that require more typing are op(A) or seq(A).) So,


By the way, your loop-based converter is extremely inefficient, as is any Maple loop that appends items one at a time onto a list, set, or expression sequence. I'd guess that this is the most-common cause of inefficiency in Maple programs.

Using a list or set of 3000 elements, compare your converter with my loop-based converter:

`convert/exprseq`:= (L::{list, set})-> 
    (for local item in L do item od)
V:= [$1..3000]:
CodeTools:-Usage(convert(V, exprseq)):
memory used=24.75KiB, alloc change=0 bytes, cpu time=0ns, 
real time=0ns, gc time=0ns

I'm not suggesting that this is a good way to do this particular job! Appending [] is (I think) a constant-time operation. It just returns the pointer to the underlying sequence. I just post this to show you the difference between an inefficient quadratic-time loop and a closely related linear-time loop.

I find frontend difficult to use; the rules for what is and isn't frozen are quite elaborate. In this case, it's only a specific type that we want to freeze: unknown functions (or unknown functions of constants). I'd use freeze/thaw like this:

fsolvefunc:= ()->
    (thaw @ [fsolve] @ op @ subsindets)(
        [args], typefunc(anything, Not(mathfunc)), freeze
fsolvefunc({x(0) + y(0) = 5, x(0) - y(0) = 3}, {x(0), y(0)});
                     {x(0) = 4., y(0) = 1.}

To restrict to unknown functions of constants, replace anything with constant.

If you want to apply the derivative identity that you suggest (I'm not claiming that there's any mathematical justification for it), do

map2(diff, f(a,b), a+b)

If your Maple version has the overload command (I don't recall if Maple 12 does), then you can easily redefine diff so that it automatically does the above whenever a sum appears as the 2nd argument to diff.

Although A is recreated for each invocation of B, this may be worthwhile in terms of efficiency if A can be simplified by using information passed in through B's parameters. This happens much more frequently than you might expect. 

A method that combines features of both nesting and not nesting is "templates": Define a "template" for A (which I'll call A_template) outside B that uses some unassigned global variables (appropriately weirdly named such that they'd never conflict with actually assigned global names). Inside B, do

A:= subs([_G1= e1, _G2= e2, ...], eval(A_template)); #The eval is necessary!

where is local to B_G1_G2, etc. are the special globals in A_template; and e1e2, etc. are expressions computed in that depend on B's parameters. This usage of subs is undocumented, has been around for ages, is extremely powerful, is frequently used in Maple's own library code, and is often the only efficient way to do something. I don't know why the names used must be global, but a simple experiment will show that that's true.

Like this:

f:= (x,K)-> (4/Pi)*add(sin((2*k-1)*x)/(2*k-1), k= 1..K):
plots:-animate(plot, ['f(x,n)', x= -Pi..Pi], n= [$1..50]);

Note the extreme occurence of Gibbs phenomenon (Wikipedia link): Even at 50 terms, the error near the discontinuities (-Pi, 0, Pi) is very large.

Put a single call to the command randomize() somewhere not in a loop after the restart but before any commands that generate random numbers. It's essential that it be a single call and not in a loop, because you don't want two calls to randomize in the same clock cycle, which can very easily happen because the clock is coarsely grained. If two calls happen in the same clock cycle, then the random sequence is reset to the same position in each of the calls.

If p is your formula constructed with Maple's standard boolean operators (and, or, notxor, implies), then do

Logic:-Export(Logic:-Import(p), 'form'= 'MOD2')

You can also construct your input formula using the Logic package's own boolean operators: &and&or&not, etc. I recommend against this for cases of direct user input because these operators do not follow standard rules of operator precedence, so an extreme number of parentheses are required.

These are called partial derivatives. The f_y means the partial derivative with respect to y, and f_z is with respect to z.

Here's one way, the command. This command refers to the variables based on their positions in the function's definition, which is the first line below:

f: = (y, z) -> y * sin (z) + 2 * cos (y):
#Partial derivative with respect to the first variable, y:
D[1](f)(Pi/2, Pi); #Pi is capitalized.

#Partial derivative with respect to the second variable, z:
D [2] (f) (Pi / 2, Pi); 
                             - - Pi

Referring to the independent variables by their position numbers may seem like a bad idea at first, but it turns out to be a lot less to type than referring to them as y and z.

Put your cursor within the section that you want to execute and press Enter (or Return on some keyboards).

Simply using x[1] as an unassigned name doesn't create a table x; however, assigning to x[1] does create a table. The unintentional creation of these tables is one of the most common causes of bugs in Maple programs. Thus, it's safer to use x__1. But, if you actually want the subscript to be programmatically indexable (as in k:= 1; x[k];), then it's much easier to use x[...].

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