Joe Riel

9660 Reputation

23 Badges

20 years, 5 days

MaplePrimes Activity


These are answers submitted by Joe Riel

That depends on what you mean be flattening.  Depending on the problem, you might be able to do

map(op, L);

or (newer Maple required):

op~(L);

Look at g5.  The mean and variance are not independent, there is no solution (for b and c).

Compilation isn't possible here with the calls to solve.  You might try substituting ?fsolve for solve, which could make the calls faster.  If a and b are simple expressions of x, you might be able to solve everything symbolically then create a procedure that returns the specific solutions given parameter values.

There are two problems with your input.  First, Maple uses square-brackets to delineate lists, not as parentheses.  Second, the differential equation is second order, there is no reason to specify the initial second derivative (dsolve complains). The following works,

f := ((diff(y(x), x))*(diff(y(x), x, x))/sqrt(y(x)^2+diff(y(x), x))+diff(y(x), x, x)) = x^6:
integ := dsolve({f, y(0) = 2, D(y)(0) = 1.5}, numeric, range = 0 .. 10):
integ(1);
                                           d
         [x = 1., y(x) = 3.51232025340609, -- y(x) = 1.59936902917771]
                                           dx

That is a linear operator on the tangent space.  I don't see how you plan to assign a sign to it.  You can use the ?DifferentialGeometry package to compute it,


with(DifferentialGeometry):
DGsetup([x,y,z],M):
f := x^2 + x*y + sin(z);
                                  2
                            f := x  + x y + sin(z)

ExteriorDerivative(f);
                        (2 x + y) dx + x dy + cos(z) dz


This particular example can be handled by declaring and using a discrete-time variable (which only change at events).  Here oldy is declared as a discrete-time float and its value at t=3 is saved.  Then at t=5 it is transferred to y:

restart;
eq := { diff(y(t),t) = y(t) };
ic := { y(0) = 2, oldy(0)=0 };

discvars := [ oldy(t) :: float ]:

ttrip := 5:

evts := [ NULL
          , [ t = ttrip-2,  oldy(t) = y(t) ]
          , [ t = ttrip,    y(t) = oldy(t) ]
        ]:

integ := dsolve( eq union ic, numeric, 'events'=evts, 'discrete_variables' = discvars):

plots:-odeplot(integ, [t,y(t)], 0..6);

You can use the ?gfun package, ?rsolve, and ?sum to handle this:

L := [1, 5, 9, 13, 17]:
# Convert the list to a recurrence equation
R := gfun:-listtorec(L,u(n));
        R := [{-u(n + 2) + 2 u(n + 1) - u(n), u(0) = 1, u(1) = 5}, ogf]

# Use rsolve to solve the recurrence.
u := rsolve(R[1],u);
                                 u := 4 n + 1

# Note that u(0)=1, not u(1)=1.  Let's shift that so v(n)=u(n-1)
v := eval(u, n=n-1);
                                 v := 4 n - 3

# Use sum to compute a symbolic expression for the n-th partial sum; factor it.
V := factor(sum(v, n=1..n));
                               V := n (2 n - 1)

# Plug-in a few values
eval(V, n=1);
                                       1

eval(V, n=100);
                                     19900

# check
add(v, n=1..100);
                                     19900

For finite n you could do

n := 30:
y := add(x[i]^2,i=1..n);
solve({seq(diff(y,x[i]), i=1..n)}, {seq(x[i],i=1..n)});

Thinks get more interesting if you want to take the derivative of an indefinite sum, say

n := 'n':
y := Sum(x[i]^2, i=1..n):
diff(y, x[k]);

You would really like this to return something like

charfcn[1..n](k)*2*x[k]

See ?charfcn for details.  I don't know that there is a package for doing this; maybe in the Application Center.

Did you try it with the compiler option selected? 40 seconds seems slow.  On my 920 it runs in less than half a second.

You haven't assigned accel.  The call to UpdateAllVelocities raises an error because the passed arguments don't match the declaration.  Assign accel a Matrix and it works.

The usual way to do this is to call evalf.  Better yet, express the sum in an inert form (using ?Sum) and then call evalf. That is

 S := Sum(ln(x)/((x)^(2)+3*x+2),x=1..infinity):
 evalf(S);

Alas, Maple is not able to numerically evalute the sum, at least not without a little help. Try the following

S1 := applyop(convert,[1,2],S,parfrac,x);
                           infinity
                            -----
                             \            /  1       1  \
                     S1 :=    )     ln(x) |----- - -----|
                             /            \x + 1   x + 2/
                            -----
                            x = 1

S2 := applyop(expand,1,S1);
                              infinity
                               -----
                                \      /ln(x)   ln(x)\
                        S2 :=    )     |----- - -----|
                                /      \x + 1   x + 2/
                               -----
                               x = 1

S3 := map(op(0,S2), op(S2));
                       /infinity      \   /infinity          \
                       | -----        |   | -----            |
                       |  \      ln(x)|   |  \      /  ln(x)\|
                 S3 := |   )     -----| + |   )     |- -----||
                       |  /      x + 1|   |  /      \  x + 2/|
                       | -----        |   | -----            |
                       \ x = 1        /   \ x = 1            /

At this point it is easier to do a bit of manual work.

S3 = (ln(1)/2 + ln(2)/3 + ln(3)/4 + .... ) - ( ln(1)/3 + ln(2)/4 + ln(3)/5 + ... )
   = ln(1)/2  + (ln(2)-ln(1))/3 + (ln(3)-ln(2))/4 + ...
   = sum(ln(1+1/k)/(k+2), k = 1..infinity)

so

S4 := Sum(ln(1+1/k)/(k+2), k = 1..infinity):

evalf(S4);
                          0.6017824584

As a check

evalf(add(op(1,S),x=1..10000));
                                 0.6007616145

Here's one approach.

Clean := proc( Opts :: list, P :: list)
local opts, k, nm;
    ASSERT(nops(Opts) = nops(P));
    opts := Opts;
    for k to nops(P) do
        if P[k] = -1 then
            nm := opts[k];
            opts := map(L -> `if`(L::list
                                  , remove(`=`,L,nm)
                                  , L
                                 )
                        , opts);
        end if;
    end do;
    return opts;
end proc:

Clean([Joe, [Mike, Abraham, Leon, Joe], [Terresa, Cody, Joe]], [-1,2,2] );
                 [Joe, [Mike, Abraham, Leon], [Terresa, Cody]]

While it isn't impossible, it is difficult and probably not worthwhile to do that.  As assigned, the expression ALL does not contain L1, but rather the value of L1.   To do what you want you could use forward quotes when assigning ALL:

ALL := '[L1,L2]';

Now ALL contains the names L1 and L2.  With some care and use of the uneval parameter modifier (see ?parameter_modifiers) and the ?eval procedure, you can inspect and manipulate both the name and its value.  However, doing so is tricky.

My suggestion is that you don't do this.  A simpler approach is to use a table

T[L1] := [1,2,3]:
T[L2] := [2,3,4]:
T[ALL] := [L1,L2]:

Then you could do

for L in T[ALL] do
   if StringTools:-RegMatch["1", L] then
        T[L] := map(`+`, T[L], 1);
   end if;
end do;

Here's an approach using ?rsolve, Maple's recurrence equation solver

G:=s->q*(1-p*s)^(-1);
                                            q
                               G := s -> -------
                                         1 - p s


req := g(k+1) = G(g(k));
                                               q
                         req := g(k + 1) = ----------
                                           1 - p g(k)


rpoly := simplify(denom(rhs(req))*req);
                     rpoly := (-1 + p g(k)) g(k + 1) = -q


rsol := simplify(rsolve({rpoly, g(0)=s},g(n)));
                         1/2      n               1/2             n
rsol := (s %2 (1 - 4 q p)    + s 2  %1 (1 - 4 q p)    + s %2 - s 2  %1

                 (1 + n)         /                      1/2               n
     - 2 %2 q + 2        %1 q)  /  (-%2 + %2 (1 - 4 q p)    + 2 p %2 s + 2  %1
                               /

        n               1/2    (1 + n)
     + 2  %1 (1 - 4 q p)    - 2        p %1 s)

      /         q         \n
%1 := |-------------------|
      |                1/2|
      \-1 + (1 - 4 q p)   /

      /         2 q        \n
%2 := |- ------------------|
      |                 1/2|
      \  1 + (1 - 4 q p)   /


simplify(eval(rsol,n=0));
                                       s

simplify(eval(rsol,n=1));
                                        q
                                   - -------
                                     s p - 1

simplify(eval(rsol,n=2));
                                 q (s p - 1)
                                --------------
                                -1 + q p + s p

Look at the value of SEqn, it has the form

{ (1+x1)*exp(x1) = Int( f(v), v = k*Eg1 .. infinity), ... }

where k is a number.  fsolve won't handle those.  It returns unevaluated.

First 66 67 68 69 70 71 72 Last Page 68 of 114