Carl Love

Carl Love

26488 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

If you "know" f (except for C), then your second relation, f(x^2) + g(x) = sin(x) - x^4, completely determines g (except for C). So, x*D(f)(x) + D(g)(x) is completely determined (the disappears), and it's not equal to cos(x) - 3*x^3.

Did you perhaps mean, instead of "know", that -x^2/2 + C was just a guess or ansatz for f?

To distribute a denominator over the terms of a numerator, use expand. So, expand(eq_i4).

How about this?

AllEdgesDistance:= proc(G::GRAPHLN, v)
uses GT= GraphTheory;
local 
    VL:= GT:-Vertices(G), V:= table(VL=~ [$1..nops(VL)]),
    D:= GT:-AllPairsDistance(G)[V[v]], e, u
;
    sort([seq]([min(seq(D[V[u]], u= e)), e], e= GT:-Edges(G)))
end proc
:    
P:= GraphTheory:-SpecialGraphs:-PetersenGraph();
AllEdgesDistance(P,1);
[[0, {1, 2}], [0, {1, 5}], [0, {1, 6}], [1, {2, 3}], [1, {2, 9}], [1, {4, 5}],
 [1, {5, 8}], [1, {6, 7}], [1, {6, 10}], [2, {3, 4}], [2, {3, 7}], [2, {4, 10}], 
 [2, {7, 8}], [2, {8, 9}], [2, {9, 10}]]


 

The counting work can be done---using a single pass through the list---by ListTools:-Collect

L:= [A,B,A,C,A,B,D,E,A,F,G,H,H,G,I,P,Q,W,A]:
interface(rtablesize=nops(L)):
MyTable:= <
    <Data | Frequency>,
    (rtable@sort)(
        ListTools:-Collect(L), key= curry(sprintf,"%a")@curry(op,1)
    )
>;

You can then use ExcelTools:-Export to send that to Excel. I don't know about Word.

The set of all vertices at a given distance d (which defaults to 2 in the procedure below) from a given vertex v is returned by this procedure. It avoids the need to scan through all vertices and measure their distance from v. This will be more efficient if the number of vertices is large and d is small.

DistNVertices:= proc(G::GRAPHLN, v, d::nonnegint:= 2)
local V:= {v}, U:= {v};
    to d do 
        V:= `union`(({op}@GraphTheory:-Neighborhood)~(G,V)[]) minus U;
        U:= U union V
    od;
    V
end proc
:

 

Given any table, you can construct its setwise inverse table with this procedure:

TableInverse:= (T::table)->  (([lhs]~)~@ListTools:-Classify)(rhs, [entries](T, ':-pairs')):

Example of use:

T:= table():  R:= rand(0..5):  for i to 9 do for j to 9 do T[i,j]:= 'R'()$2 od od:

TI:= TableInverse(T):
T[6,7];

                              1, 2

TI[1,2];
                    {[2, 5], [6, 7], [7, 2]}

If the table is one-to-one (aka injective), or you want to ignore multiple indices mapped to the same entry, then a simpler procedure can be used:

TableInverse1to1:= (T::table)-> (table@(rhs=lhs)~@[entries])(T, ':-pairs'):

The time complexity of TableInverse is O(n*) where n is the number of indices, and the * represents unknown but small (< < n) logarithmic factors. The time complexity of TableInverse1to1 is simply O(n).

You can teach diff a recursive formula for the derivative of P(n,x). Once you do that, it'll be able to automatically do higher-order derivatives and/or derivatives of compositions (such as with cos(theta)).

Important: If you want to do this, do not use with(orthopoly). Instead, if and when you want to eliminate P from an expression ex, do eval(ex, P= orthopoly:-P).

`diff/P`:= proc(n,x,z)
    if depends(n,z) then 
        error "derivative of P wrt its 1st argument not defined"
    else
        diff(x,z)*n/(x^2-1)*(x*'P'(n,x) - 'P'(n-1, x))
    fi
end proc
:
#Optional (only affects display): Display P(n,x) with the n as a 
#subscript:
`print/P`:= (n,x)-> nprintf(`#msub(mi("P"),mo("%a"))`, n)(x)
:
dP:= diff(P(n, cos(theta)), theta$2);
simplify(eval(dP, n=2));
simplify(eval(%, P= orthopoly:-P));

 

I don't know what version of Maple you are using. I am using Maple 2020. So, I don't know if this Answer will work for you. It's useful to make assumptions on x and alpha. If need be, the system can internally derive an appropriate assumption for t based on those. It may be counter-productive to make an assumption on t

This works instantaneously for me:

b:= GAMMA(2-alpha)/(1-alpha)/GAMMA(1-alpha):
J:= Int((x-t)^(-alpha)*a*(t-b*ln(1+t/b)), t= 0..x);
value(J) assuming x > 0, alpha > 0, alpha < 1;

If you need to resort to numerical integration, there are appropriate easy ways to do that in Maple. The method that you show is not very good.
 

Here's another way:

numboccur(evalb~(A >~ B), true)

@mthkvv As far as I know, it's not possible to programmatically set the fps (frames per second) with any of the animation commands: plots:-animateplots:-display, or Explore. You must set it from the toolbar (or context menu) animation controls, which only appear when the animation is the current on-screen "context".

If you save the animation to a .GIF file, then you can change the fps using numerous freely downloadable GIF-editing apps.

An often-used workaround is to repeat frames. So, to change from the default 10 fps to x fps, repeat each frame round(10/x) times. However, if you do too much of this, the GUI can become overwhelmed by the amount of data and become unbearably sluggish. It largely depends on the amount of numerical data in each frame.

Change to

f:= unapply(convert(g(x), surd), x);

I'm not 100% sure that this will work with in Maple 13. Let me know. If it doesn't work, I can give you something else.

But regardless of whether it works with or not, you should change f as shown. Here's a rule to help decide between x-> ... and unapply(..., x): If the right side of the arrow (in this case convert(g(x), surd)) contains a symbolic operation that doesn't depend on the specific value(s) of the variable(s) on the left side of the arrow (in this case x)---it only depends on x as a symbol---then use unapply. The convert(g(x), surd) is a purely symbolic operation: It has no dependence on the numeric value of x.

If you fail to follow this rule, the result will still often "work" in a sense, but if it does work, it'll always be extremely inefficient. The most-common violations of this rule involve putting diff or int on the right side of the arrow (in which case the result usually won't work with numeric values). (I'm not saying that you should never put those on right side of the arrow; you need to consider the situation from the symbolic perspective explained in the previous paragraph.)

This functional-compostion diagram illustrates the above. I copied it from help page ?operators,D:

       function application -->
 f   -----------------------------   f(x)
           <-- unapply
 |                                    |
 |                                  d | ^
 |                                  i | |
 |D()                               f |
 | |                                f | i
 | |                                  | n
 | V                                | | t
 |                                  V |
 |                                    |
       function application -->
D(f) ----------------------------   f'(x)
           <-- unapply

 

Note that you've erroneously put a space after GAMMA. It must be, for example, GAMMA(alpha+1) instead of GAMMA (alpha+1). This type of error is only possible in 2-D Input.

A vertically stacked array of three plots can be made by

restart:
F:= (c::list(numeric))-> 
    alpha-> 
        t-> add(c[i]*(t^alpha)^(i-1)/GAMMA((i-1)*alpha+1), i= 1..nops(c))
:
Alpha:= [0.2, 0.6, 0.8, 1.0]:
tr:= 0..1:
c:= Record(
    "R"= [0.46, 9.1625, 8.8318, 11.6888],
    "L"= [0.32, 0.09282, 2.1126. 3.9028],
    "T"= [0.52, 0.0569, 0.0243, 1.3102]
):
plots:-display(
    <seq(
        plot(
            F(c[x])~(Alpha), tr, legend= (alpha=~ Alpha),
            title= typeset(x, " for various ", alpha),
            labels= [t, x]
        ),
        x= exports(c)
    )>,
    view= [tr, DEFAULT]       
);

If you want all the plots to have the same scale on the vertical axis, change DEFAULT to
0..max(seq(max(F(c[x])~(Alpha)(rhs(tr))), x= exports(c)))

The plots can also be horizontally arrayed.

SumNeighborhood:= (G::GRAPHLN, v)->
    add(GraphTheory:-Degree~(G, GraphTheory:-Neighborhood(G, v)))
:

Make it a list: numelems([b]);

My procedure for this uses neither a remember table nor recursion. It does have something like a "reverse remember table". The sequence values are stored internally as hardware floats for faster computation.

This procedure is about 29 times faster than Kitonum's procedure at generating the first 2^13 entries of the sequence.

A:= proc(N::And(posint, Not({1,2})))
local 
    n, m, p, U:= table([HFloat(1)= 1]), 
    A:= rtable(1..N, [1,0], datatype= float[8])
;
    for n from 2 to N-1 do
        p:= A[n];
        m:= U[p]; 
        A[n+1]:= `if`(m::posint, n-m, min(abs~(p -~ A[..n-1])));
        U[p]:= n       
    od;
    seq(trunc(a), a= A)
end proc
:
S:= CodeTools:-Usage([A(2^13)]):
memory used=151.81MiB, alloc change=27.49MiB, 
cpu time=453.00ms, real time=460.00ms, gc time=0ns

S[..30];
[1, 0, 1, 2, 1, 2, 2, 1, 3, 1, 2, 4, 1, 3, 5, 1, 3, 3, 1, 3, 2, 
  10, 5, 8, 2, 4, 14, 4, 2, 4]

 

First 57 58 59 60 61 62 63 Last Page 59 of 382