Joe Riel

9530 Reputation

23 Badges

20 years, 29 days

MaplePrimes Activity


These are answers submitted by Joe Riel

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:

To generate the data you can use ?unapply to make a procedure out of the integral:

fx := unapply(int(exp(-a^2 + x),a=0..5),x);
xydata := evalf([seq([x,fx(x)], x = 0..5)]);

You may need to convert to rationals

Note that t will have to be assigned an integer.  Also, it isn't entirely clear what you want.  Is each entry of the Array a Vector?  So the (0,1) entry would be the Vector <0,1,0>?  You can accomplish that using a procedure as an in initializer:

A := Array(0..1, 1..2, (i,j) -> <i,j,0>);

              [0]           [0]           [1]           [1]
              [ ]           [ ]           [ ]           [ ]
    {(0, 1) = [1], (0, 2) = [2], (1, 1) = [1], (1, 2) = [2]},
              [ ]           [ ]           [ ]           [ ]
              [0]           [0]           [0]           [0]

    datatype = anything, storage = rectangular, order = Fortran_order)

Try using ?algsubs to replace a-b with another variable.  For example

p := expand(eval(x^2+3*x+2, x=a-b+3*c));
             2                    2              2
       p := a  - 2 b a + 6 a c + b  - 6 b c + 9 c  + 3 a - 3 b + 9 c + 2

algsubs(a-b=z, p);
                                  2    2
                       6 c z + 9 c  + z  + 2 + 9 c + 3 z

collect(%,z);
                        2                          2
                       z  + (6 c + 3) z + 9 c + 9 c  + 2

collect(%,z,factor);
                     2
                    z  + (6 c + 3) z + (3 c + 2) (3 c + 1)

That will require some modification if the polynomial does not have integer coefficients.

Is the applied force parallel to the pipe axis?  If so, you could do something like

r := 1:
fy := 1/(2*Pi*r)*cos(phi):
plot3d([r*cos(phi), y*fy, r*sin(phi)], phi=0..2*Pi, y=0..10);

Actually, you can do that:

a:=[2,5,g,f,5,h];
                                     a := [2, 5, g, f, 5, h]

a[6] := 5;
                                            a[6] := 5

a;
                                        [2, 5, g, f, 5, 5]

However, that is not efficient (Maple generates a completely new list with each insertion) and will not work with lists of more than 100 elements.  The best approach is to use an rtable (Vector or Array).

You could create a simple procedure to assign a given value to multiple indices.  For example:

multinsert := proc(A :: rtable, indexes :: list, value)
local i;
  for i in indexes do
     A[i] := value;
  end do;
  NULL;
end proc:

You could even get fancy and overload the index operator, however, that probably isn't a great idea.  Actually, I'm not sure it can be made to work here, but suspect it can.

For the first example are you asking for what values of x is A is invertible? There are three values for which it is not invertible, i.e singular.  A singular Matrix has a determinant of 0. So find the determinate in terms of x, set it to 0, and solve the equation. The Maple procedure for computing the determinant is ?Determinant, in the ?LinearAlgebra package.  You will want to use Matrix, not matrix, to construct the matrix.

It isn't clear what your second problem is expressing.

First, both procedures use the Dimension export from LinearAlgebra.  However, they assume that the user has previously called with(LinearAlgebra) so that Dimension is accessible in the short-form.  It is better not to rely on that.

The first attempt fails because resultat is cumulative.  To make it work you need to reset it to zero before summing each row, and then store the result in the Vector. For example,

sommeligne2 := proc (matrice)
local n, m, j, i, resultat, V;
    (m,n) := LinearAlgebra:-Dimension(matrice);
    V := Vector(m);
    for i to m do
        resultat := 0;
        for j to n do
            resultat := resultat + matrice[i, j];
        end do;
        V[i] := resultat;
    end do;
    return V;
end proc:

Note that I swapped m and n to the more usual convention (m is the number of rows, n the number of columns).

The second procedure fails because sum is being used in place of add. There is a difference in their operation; sum is intended for indefinite summation.  Also, each addition must be assigned to an entry of the Vector.

sml2 := proc (matrice)
local n, m, i, j, V;
    (m,n) := LinearAlgebra:-Dimension(matrice);
    V := Vector(m);
    for i to m do
        V[i] := add(matrice[i,j], j=1..n);
    end do;
    return V;
end proc:

A typical method is to create a hash from the message, see ?StringTools[Hash], then use a public-key encryption algorithm (say RSA) to encrypt that hash with your private key.  Send this signature along with the message.  The receiver decrypts the signature using your public key, then compares it to the result of running StringTools[Hash] on the message.  You can find an RSA implementation for Maple at the Maple Application Center.

First 76 77 78 79 80 81 82 Last Page 78 of 114