Joe Riel

9660 Reputation

23 Badges

20 years, 6 days

MaplePrimes Activity


These are answers submitted by Joe Riel

While not as efficient, here is a variation of Roman's suggestion (I doubt ?charfcn gets used much):

L := [1,2,3,2,4,6,5,0,9,0,3,4,4]:
f := charfcn[2..3];
                                       f := charfcn[2 .. 3]
add(f(x), x in L);
                                                 4


with(group):
mulperms([[1,2]],[[2,3]]);
                                            [[1, 3, 2]]
convert(%,permlist,3);
                                             [3, 1, 2]

Probably (i.e. you are missing something).  More exactly, we are missing something, the procedure.  From the snippet you gave, I'd code it as

f := proc(a::nonnegint,b::nonnegint)
option cache;
    if   a=0 or b=0 then 1;
    else
        f(a-1,b) + f(a,b-1)
    end if;
end proc:

You need to convert the voltages to signals.  Use either the voltage or potential sensor, in the Electrical/Analog/Sensors menu.

It depends on the system. For a continuous-time transfer function system it uses ?inttrans[invlaplace] to compute the inverse laplace and then plots that.

It would work if you also passed the argument to the procedure:

add((i->if i < 2 then 1 else 0 end if)(i), i in list);

A shorter and more efficient method is to use Maple's ?if operator:

add(`if`(i<2, 1, 0), i in list);


Correction: ?sort does work on Array.  I hadn't realized that. 

Note that sort doesn't work with an Array.  Here is a modification to your routine

genRequestDist := proc (N, t)
local requests, i, r, pts, d; 
    requests := Array(1 .. N
                      , sort(RandomTools:-Generate(list(integer(range=0..t),N)))
                     );
    pts := Array(0 .. t, 1 .. 2);
    for i from 0 to t do
        pts[i, 1] := i;
    end do;
    for i to N-1 do
        d := abs(requests[i+1]-requests[i]);
        pts[d, 1] := d;
        pts[d, 2] := pts[d, 2]+1
    end do;
    pts;
end proc:

Most of the values in the second column are 0.  You could eliminate those with

N := 10^5:
A := genRequestDist(N, 36*10^5);
for i from N to 1 by -1 while A[i,2]=0 do end do:
plots:-pointplot(A[1..i,..]);


This particular problem can be readily solved by calling solve:

eqs := {NULL
        , a+b+c=1
        , a+d+e=2
        , b+d+f=2
        , c+e+f=1
       }:
solve(eqs);
                 {a = f, b = e, c = 1 - e - f, d = 2 - f - e, e = e, f = f}

and then noting that there are only two possibilties, {e=0,f=1} and {e=1,f=0} that meet the requirements.

Here is a procedure that implements that technique.  It works on similar simple problems

SolveRestricted := proc(eqs :: set(equation)
                        , given :: set(name=set)
                       )
    
local sols, free, depends, freevars
    , freechoices, dependchoices, T
    , Sols, choice, sol;
    
    sols := solve(eqs);
    (free, depends) := selectremove(evalb, sols);
    
    freevars := map(lhs,free);
    
    (freechoices, dependchoices) := selectremove(has, given, freevars);
    freechoices := convert(freechoices,list);
    freevars := map(lhs, freechoices);
    
    dependchoices := map(eq -> lhs(eq) in rhs(eq), dependchoices);
    
    T := combinat:-cartprod(map(rhs, freechoices));
    
    Sols := table();
    
    while not T['finished'] do
        choice := zip(`=`,freevars,T['nextvalue']());
        try
            sol := eval(depends, choice);
            if andmap(evalb, eval(dependchoices, sol)) then
                Sols[sol union convert(choice,set)] := NULL;
            end if;
        catch:
        end try;
    end do;
    
    return {indices(Sols, 'nolist')};
end proc:


SolveRestricted(eqs, map(`=`,indets(eqs),{0,1}));
  {{a = 0, b = 1, c = 0, d = 1, e = 1, f = 0},
   {a = 1, b = 0, c = 0, d = 1, e = 0, f = 1}}
SolveRestricted(eqs, map(`=`,indets(eqs),{0,1,2}));
  {{a = 0, b = 0, c = 1, d = 2, e = 0, f = 0},
   {a = 0, b = 1, c = 0, d = 1, e = 1, f = 0},
   {a = 1, b = 0, c = 0, d = 1, e = 0, f = 1}}
 

 

By "add" I assume you mean "catenate".  Here's one way (rather specific to your example).  For variety I used a different method to convert the first Vector to a sum.

vec2symb := proc(S :: Vector, T :: Vector)
    nprintf("%A(%A)=%A"
            , T[1]
            , T[2]
            , StringTools:-Join(map(convert
                                    , convert(S,list)
                                    ,string)
                                , "+")
           );
end proc:

vec2symb(<1,2,3>, <8,-2>);
                                  8(-2)=1+2+3

vec2symb := proc(V :: Vector)
local v;
    nprintf("%A", add(convert(v,`local`), v in V));
end proc:

vec2symb(<1,2,3>);
                                     1+2+3

vec2symb(Vector([0,1,1,0]));
                                    0+1+1+0

Your equations are for a torus, not a cylinder.  I don't understand what mu, upsilon, and omega are supposed to represent.  A cylinder might be plotted as

plot3d([x,
        r*cos(theta),
        r*sin(theta)
       ]
       , x = 0..L, theta = 0..2*Pi
       , 'scaling=constrained'
      );

Maple's plot routine resizes the dimensions to fill a given area.  To prevent that, use the 'scaling=constrained' option.  You either add that to the call to plot3d, or select the constrained option from the Projection menu in the plot dialog box.

First things first.  You do not want to use a list as your sorting structure.  Each time you assign directly to an element in a list, say with

l[i] := l[i+1];

an entirely new list is created.  That is exceptionally inefficient. Instead you should be using an ?rtable (Array or Vector) as the data structure. In your code, just reassign l (I'll use L for legibility):

n := 5:
L := Array([seq(n..1,-1)]]):

You'll have to replace nops(l) with n.

 

Normally one should use ?add rather than ?sum; see www.mapleprimes.com/forum/suggestionfrequentanswersection#comment-30664. However, the special evaluation rules of add make this a bit tricky, but doable.  Maybe the easiest way to handle it is to create an expression using an inert version of add and then subsitute the active version.  For example (in Maple 13),

R := 3*i + j * k;
                                R := 3 i + j k

inert := foldl(%add, R, (i,j,k) =~ 0..1); 
   inert := %add(%add(%add(3 i + j k, i = 0 .. 1), j = 0 .. 1), k = 0 .. 1)

value(inert);
                                      14

 

Is the data actually in a table?  Or is it an Array (or Matrix)?  If an Array (or Matrix), you could do the following

n := 100:
pts := Array(1..n,1..2):
for i to n do
    pts[i,1] := i;
    pts[i,2] := i^2;
end do:

X := pts[..,1]: # convert each column to a one-dimensional Array
Y := pts[..,2]:

plot(X,Y); # this is equivalent to the third form showin in the Calling Sequence in ?plots

A simple way to generate the sum (you may need to adjust the formula) is

S := Array(1..n):
for i from 2 to n do
    S[i] := S[i-1] + Y[i-1]*(X[i]-X[i-1]);
end do:
First 76 77 78 79 80 81 82 Last Page 78 of 114