Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 354 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The two most basic (mathematically) commands for this are plot3d (for surfaces) and plots:-spacecurve (for space curves). See their help pages by entering ?plot3d or ?spacecurve. These, like all plotting commands, have a vast number of options, and there are a vast number of other 3D plotting commands. Perhaps you should describe what you want to plot.

plot3d(sin(x*y), x= -Pi..Pi, y= -Pi..Pi);

plots:-spacecurve([sin(t), cos(t), t], t= 0..10, thickness= 4);

Kitonum's Answer is essentially correct, but it may be confusing that he didn't use an arbitrary function as f in his example. The boundary condition that you requested is usually written

(D@@2)(f)(w) = 0

It could also be written D(D(f))(w) = 0 or (D@D)(f)(w) = 0. It makes no difference which of these you use; it's just a matter of style.

Understanding the difference between D and diff: In its basic form, diff takes an algebraic expression as its first argument and returns an algebraic expression. On the other hand, takes either a procedure or a function symbol (such as the f from f(x)) or a combination of those as its only argument and returns a procedure. To use that (or any) procedure, it must be applied to argument(s). That's what the (x) or (w) are, arguments.

A single is the operator for function composition: If h = f@g, then h(x) = f(g(x)) for any x (including multi-term expression sequences). The @@ is for iterated compostion of a function with itself; so f@@n = f@(f@@(n-1)) for positive integer n.

You need to delay the evaluation of the NewSystem command by making it 'NewSystem'.

The square brackets are to separate the arguments of RootLocusPlot from the arguments to animate. Usually a plot command being animated takes more than one argument, although that's not the case here. Thus, there needs to be some way to distinguish the two levels of arguments. Square brackets are the simplest choice for that way.

You just need the quotes to fix the problem, but the way that you replace the value of alpha is awkward. I'd do it like this:

num:=10*(s+alpha); den:=s*(s^2+4*s+8);
f:= unapply(num/den, alpha);
plots:-animate(
    DynamicSystems:-RootLocusPlot,
    ['DynamicSystems:-NewSystem'(f(a))],
    a=  1..10
);

 

If the original plot command was

plot(y(x), x=  a..b)

then change it to

plot([y(x), x, x= a..b], labels= ['y', 'x'])

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
        try
            return
                Optimization:-LPSolve(
                    0, {eqs[]*~seq(C)} >=~ 1, assume= integer
                )[2]
        catch:
        end try
    od;
    FAIL
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.

restart:
alllexicographic:= 
    (L::coerce(list, (L::{set, rtable})-> [seq](L)), n::nonnegint)->
        combinat:-permute(L,n)
:    
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]: 
plots:-listplot(
    F, 
    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)
or
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,

ilcm(v[]);

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.

First 87 88 89 90 91 92 93 Last Page 89 of 395