Joe Riel

9660 Reputation

23 Badges

20 years, 4 days

MaplePrimes Activity


These are answers submitted by Joe Riel

 

A problem is that the vector is not rooted, at least not explicitly.  The root that you want is the postion vector <r,phi,z>.  Alas, MapToBasis doesn't work with a rooted vector unless it has cartesian coordinates.  The solution is to create a vector field:

with(VectorCalculus):
SetCoordinates(cylindrical[r,phi,z]):

v1 := VectorField(<3*cos(phi),-2*r,5>);
                                      _        _        _
                     v1 := 3 cos(phi) e  - 2 r e    + 5 e
                                       r        phi      z
v2 := MapToBasis(v1,cartesian[x,y,z]);
                   /    2        \
                   | 3 x         | _    / 3 x y       \ _      _
             v2 := |------- + 2 y| e  + |------- - 2 x| e  + 5 e
                   | 2    2      |  x   | 2    2      |  y      z
                   \x  + y       /      \x  + y       /

v2 is correct, however, you want to express the components in terms of r, theta, and z, so


v3 := simplify(eval(v2, [x=r*cos(phi), y=r*sin(phi)]));
                  2                 _                                _      _
 v3 := (3 cos(phi)  + 2 r sin(phi)) e  + (3 sin(phi) - 2 r) cos(phi) e  + 5 e
                                     x                                y      z

Follow up. My point about MapToBasis not working with a rooted vector in non-cartesian coordinates is incorrect. It will work, if the RootedVector constructor is used.  For example

v1 := RootedVector(root=<r,phi,z>,[3*cos(phi),-2*r,5]);
                                    [3 cos(phi)]
                                    [          ]
                              v1 := [   -2 r   ]
                                    [          ]
                                    [    5     ]

MapToBasis(v1,cartesian);
                     [              2                   ]
                     [    3 cos(phi)  + 2 r sin(phi)    ]
                     [                                  ]
                     [3 cos(phi) sin(phi) - 2 r cos(phi)]
                     [                                  ]
                     [                5                 ]

I see what is going on.  Using add should give you what you want. The problem with using sum is that it first evalutes its arguments, specifically, the summand.  But evaluating diff(f,x$n) yields

diff(f,x$n);
                                      /         -----          
                                      |          \             
1                          (-1 - n)   |           )            
- pochhammer(-n, n) (x + 1)         + |          /             
4                                     |         -----          
                                      |               /  2    \
                                      \_alpha = RootOf\_Z  + 1/

                                                     \
                                                     |
  /  1                                      (-1 - n)\|
  |- - _alpha pochhammer(-n, n) (x - _alpha)        ||
  \  4                                              /|
                                                     |
                                                     /

     1                          (-1 - n)
   - - pochhammer(-n, n) (x - 1)        
     4                                  

hence the rather strange expression following the summation.  Because add delays the evaluation of the addendum until after substituting the numeric value for n, so the usual derivative is computed.

Note that the return type (of a procedure call) is not checked unless kernelopts(assertlevel) is set to 2.  With that done, the procedure, as defined, will always return an error because the return type is never an integer.

You haven't assigned f.  Do

f := 1/(1-x^4);

Consider using ?add rather than ?sum

# Define the function
f := (x,y,z) -> x^2+y+z:

# Create a a plot transformation
F := plottools:-transform((x,y,z) -> [x,y,z]*f(x,y,z)):

# Create the surface data for S2
S2 := plot3d(1,theta=0..2*Pi,phi=0..Pi, 'coords=spherical'):

# Apply the transformation to S2
F(S2);

There's only one.

Is this what you want:

proc( ...  S :: symbol := ':-S', L :: list := [], ... )
...
end proc

The problem lies in the way you are using indexed variables.  Consider the simple example

g[j] := j^2:
p := j -> g[j]:
p(3);
                   g[3]

That returns g[3], and not the 9 that your scheme would require.  One way to fix this is to use functions instead of indexed names:

g := j -> j^2:
p := j -> g(j):
p(3);
                             9

Here is a simple workaround.  Use the postscript plot device and create the file.  Then manually edit it so that the S commands are changed to P commands (which fill the polygon).  You might have to play around with this depending on what else is plotted.  Here is what I did (this assumes you have access to the sed command on your system):


psfile := "plot.ps":
plotsetup(ps, plotoutput=psfile);
plot(sin, style=point, 'symbol=solidbox');
# Use sed to convert all S commands to P commands; save the original
# as a backup.
ssystem(sprintf("sed -i.bak 's/^S/P/' %s", psfile));

That generates solid squares.

If you don't have access to sed, you could do the conversion with Maple:

tmp := FileTools:-Text:-OpenTemporaryFile();
do
    line := readline(psfile);
    if line = 0 then break; end if;
    line := StringTools:-RegSubs("^S$"="P",line);
    fprintf(tmp, "%s\n", line);
end do:
close(tmp);
FileTools:-Rename(tmp,psfile,'force');

The reason that you cannot use _dj01ajc is that internally fdiff is setting Digits to 17, and that integration method uses hardward floating points, so will not work if Digits is greater than evalhf(Digits).  One way to get a result is to reduce Digits to 8. 

Digits := 8:
fdiff(Tproc, [1], [1,2,3]);
fdiff(Tproc, [2], [2, 10, 2.5]);

The fdiff routine should be generating an error message rather than returning the result unevaluated; I'lll submit an SCR.

Hard to say without inspecting your code.  Can you upload it?

The problem lies in the assignment to F1, you omitted a multiplication immediately following x5. Consequently Maple interprets it as a function, sort of.  That is the 2D parser makes x the function and raises that to the power of 5.

It would be helpful if you included the source of what you actually did.  The description is not precise.

roll := rand(0 .. 1):
s0 := 0: s1 := 0:
to 100 do
   s0 := s0 + roll();
   s1 := s1 + roll();
end do:

s0,s1;
                              50, 46

First 58 59 60 61 62 63 64 Last Page 60 of 114