Joe Riel

9660 Reputation

23 Badges

20 years, 7 days

MaplePrimes Activity


These are answers submitted by Joe Riel

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.

Is the volume of the n-doughnut given by #Dn(R,r) = #Bn-1(r)#S1(R), with # being the appropriate measure.  R is radius of rotation.

There are a few problems, some syntactical, some semantical.   First let's deal with the syntax.

When you enter the code, Maple prints the error you see.  It also moves the cursor to near the offending position.  In this case it moves it just before the T in the assignment T := T + 2*sum(...).  The problem there is that the do keyword is missing. Fix that, then re-execute.  Now the cursor moves to the call to sum.  The call is syntactically incorrect, it is missing a closing parenthesis (there are also semantic issues we will deal with shortly).  Fix that and re-execute.  Now the cursor moves to the end proc.  The problem there is that you did not close the if statement.  Add an end if.  At this point we have

Simpson:=proc(f,N,a,b);
    if (N,odd)=true then
        print("N has to be even.");
    else
        N:=N:
        a:=a:    b:=b:
        h:=(b-a)/N:
        for i from 1 to N/2 do
            S := S + 4*sum(f(x2i-1)):
        od:
        for i from 1 to N/2-1 do
            T := T + 2*sum(f(x2i));
        od:
    end if;
    S:=(h*(T+S+a+b))/3;
end proc:

The procedure is now syntactically correct. You will get some warnings about undeclared locals.  Those should be declared. 

What remain are quite a few programming bugs.  Rather than me fixing them, I'll give you some suggestions:

(N,odd) is merely a sequence. You should use either type(N,odd) or N::odd. 
print("N has to be even") is okay, however, it is better to use an error statement:  error "N has to be even".  Actually, it is better to declare that the parameter N must be even in the parameter list and then do away with the internal type check.  That is, do

Simpson := proc(f, N::even, a, b)

As you will quickly find out, a := a; and b := b; do not work (they wil generate errors).  You cannot generally assign to parameters (there are exceptions, but this isn't one of them). 

The calls to sum are invalid.  Sum requires a second argument.  However, you shouldn't be using sum for definite summation.  Instead use add.  Actually, it isn't clear why you are using sum/add anyway.  You're alreading computing the sum in the loop.  The loops could be replaced with calls to add, but this is a refinement.

Is this what you want:

Matrix(3,3,f);
                                        [f(1, 1)    f(1, 2)    f(1, 3)]
                                        [                             ]
                                        [f(2, 1)    f(2, 2)    f(2, 3)]
                                        [                             ]
                                        [f(3, 1)    f(3, 2)    f(3, 3)]

Assign f appropriately
 

`&//` := proc()
local z;
    1/add(1/z, z in [_passed]);
end proc:

R_total := R1 &// (s*L1) &// (1/s/C1) &// R2;
                                            1
                     R_total := -------------------------
                                 1      1             1
                                ---- + ---- + s C1 + ----
                                 R1    s L1           R2


normal(R_total);
                                  R1 s L1 R2
                  ------------------------------------------
                                     2
                  s L1 R2 + R1 R2 + s  C1 R1 L1 R2 + L1 R1 s
collect(%,s,factor);
                                  R1 s L1 R2
                    ---------------------------------------
                     2
                    s  C1 R1 L1 R2 + L1 (R2 + R1) s + R1 R2

I don't know that Maple has many tools for directly manipulating sums.  You could always use a purely syntactical approach:

> S := Sum(kx*x[i]+ky*y[i], i=1..n);   
                                                   n
                                                 -----
                                                  \
                                            S :=   )   (kx x[i] + ky y[i])
                                                  /
                                                 -----
                                                 i = 1

> map(op(0,S), op(S));              
                                          /  n          \   /  n          \
                                          |-----        |   |-----        |
                                          | \           |   | \           |
                                          |  )   kx x[i]| + |  )   ky y[i]|
                                          | /           |   | /           |
                                          |-----        |   |-----        |
                                          \i = 1        /   \i = 1        /

> expand(%);                        
                                             /  n       \      /  n       \
                                             |-----     |      |-----     |
                                             | \        |      | \        |
                                          kx |  )   x[i]| + ky |  )   y[i]|
                                             | /        |      | /        |
                                             |-----     |      |-----     |
                                             \i = 1     /      \i = 1     /


eq := expand(cos(3*x)) = cos(3*x);
sol := solve(eq, {cos(x)}):
eval(sol[1], x=theta/3);
     theta                                      2 1/2 (1/3)
{cos(-----) = 1/2 (cos(theta) + (-1 + cos(theta) )   )
       3

                               1
     + 1/2 -----------------------------------------}
                                         2 1/2 (1/3)
           (cos(theta) + (-1 + cos(theta) )   )


Use the partition option.  That is, ApproximateInt(..., partition=5).

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