Joe Riel

9530 Reputation

23 Badges

20 years, 26 days

MaplePrimes Activity


These are answers submitted by Joe Riel

I don't enjoy booting into Windows, so will show one approach that works in Linux.

Here is the file I created, named UpdateFile and made executable

#!/bin/bash

maple -q local cnt,file;
    file := "/home/joe/tmp.dat";
    cnt := readdata(file,integer);
    writedata(file,[cnt[1]+1],integer);
end proc();
EOF

From the command line

$ echo 0 > tmp.dat
$ ./UpdateFile && cat tmp.dat
1
$ ./UpdateFile && cat tmp.dat
2

@Christopher2222 Somewhat surprisingly, this problem is more difficult than it first appears. I've tried a few configurations with multibody components, however, they have not been completely successful. Investigating.

The ?product command is for computing indefinite products (symbolic products), while the ?mul command is for computing a definite product, that is one in which the terms and end points are defined. A practical difference is that mul does not first evaluate the multiplicand.

To see what is happening, use the inert form of product,

Product( (2*i-1) mod 3 + 1, i=1..10 );
                              10
                           --------'
                          '  |  |
                             |  |    (2 i + 3)
                             |  |
                             |  |
                            i = 1

Maple has evaluated the expression (2*i-1) mod 3 + 1 before passing it to Product.  That gives 2*i+3.  In product, that is then used to compute the result.

Does it make sense to connect a translational spring to a revolute joint? A rotational spring I understand; it applies a torque to the joint as it pivots. What do you expect the translational sprint to do? To connect a rotational spring, connect it to the unfilled circular port. However, the revolute joint takes spring and damping parameters, so that generally isn't required.

Maybe you want a translational spring between two arbitrary points.  Assuming the movement is in a plane, you can attach separate revolute joints to each, then connect the revolute joints with a prismatic joint.  The prismatic joint has spring coefficient and damper parameters, so you can use those, or you could attach a 1D translational spring between the two rectangular ports on the prismatic joint.

 

In each procedure that accesses a member of LinearAlgebra, you can do

myproc := proc()
local x,y,z;
uses LinearAlgebra;
...
end proc:

That isn't the best style in that it exposes all exports of LinearAlgebra to your procedure, which could be an issue if you happen to use a local procedure/variable with the same name as an export of LinearAlgebra.  The way I avoid that is the following

myproc := proc()
...
uses LA = LinearAlgebra;
   ...
   M := LA:-MatrixMultiply(...);
end proc:

Using this form of ?uses allows a reasonably convenient shortcut to access LinearAlgebra exports, but doesn't export the exports, so accidental conflicts do not occur.

An easy way to debug this is to use the Maple debugger:

stoperror(all):
(**) decom(3,2);
Error, invalid subscript selector
decom:
  13         s[i,k] := [op(s[i,k]), op(f[i,k,l])]
DBG> s;
[]  

The expression s[i,k] is invalid with i and k integers (here 1, 1), and s assigned an empty list.

 

If you are satisfied with the output in text format, rather than typeset, you can do

printf("%{}a\n",<f1,f2,f3>):

A Maplet is a GUI interface that can be created programatically from Maple code and can be launched from either Standard Maple or tty Maple.  It contains typical GUI-type features: radio buttons, check boxes, text areas, math input/output, plot regions, etc. Unlike Embedded Components, a Maplet resides in its own window, outside the worksheet. The package for creating maplets, ?Maplets, is part of Maple.

MapleSim is a multidomain simulator, a separate product of Maplesoft that uses Maple internally. MapleSim includes libraries of electrical, mechanical, hydraulic, magnetic, and signal components, and has 3D visualization capability.

Try the GreaterEqual block in Signal Blocks --> Relational

Here's an alternative approach.  Rather than using ?VectorCalculus or the rather old ?geom3d package, it uses the ?DifferentialGeometry package, which is not specialized to three dimensional Euclidean geometry.  The downside is that simple operations require more setup, and the package takes some study to use (it comes with a series of lessons and tutorials that are helpful).

DifferentialGeometry does not assign a projection operator, but we can use its methods to write one. I'll assume that the we want to project onto an embedded manifold using the inherited metric of the surrounding manifold.  Here's a procedure that does that

Project := proc( T, g2, V )
local M1,M2,B1,g1,U1,U2,W1,eqs,v;
uses DifferentialGeometry
    , DifferentialGeometry:-Tensor
    , DifferentialGeometry:-Tools
    ;

    M1 := DGinfo(T, "DomainFrame");
    M2 := DGinfo(T, "RangeFrame");

    # Get the basis for M1
    B1 := Tools:-DGinfo(M1, "FrameBaseVectors");

    # Pullback the metric on M2 to M1
    g1 := Pullback(T, g2);

    # Construct unit vector fields on M1
    U1 := map(v -> v/sqrt(TensorInnerProduct(g1,v,v)), B1);

    # Push them onto M2
    U2 := map2(Pushforward, T, U1);

    # Compute the projection onto the unit vectors
    W1 := zip((u1,u2) -> u1*TensorInnerProduct(g2,u2,V), U1, U2);

    # Change coordinates to those of M1.  The Tools:-DGinfo export
    # should have a method for doing this, but I couldn't find it.
    eqs := map(L -> L[2]=L[1], op([1,2],T));
    W1 := eval(W1, eqs);

    # Sum the projected vectors
    add(v, v = W1);

end proc:

Here we use it to project a constant vector field in R2 onto an embedded circle.

with(DifferentialGeometry): with(Tensor):
# Assign E2 as a two-dimensional Euclidean space (did I mention this required more setup?)
DGsetup([x,y],E2):

# Define the metric
gE2 := evalDG( dx &t dx + dy &t dy):

# Define a constant vector field in E2 (D_x and D_y are the unit vectors in the x and y directions)
V := evalDG(a*D_x + b*D_y):

# Now define a circle. The transformation (C) embeds S1 into E2.
DGsetup([theta],S1):
C := Transformation(S1,E2,[x=R*cos(theta),y=R*sin(theta)]):

# Now project V onto C
Project(C, gE2, V) assuming R>0;
                     D_theta (cos(theta) b - sin(theta) a)
                     -------------------------------------
                                       R

CrossProduct(diff(S1,u),diff(S1,t));

You'll want to normalize it. Also need to pick an orientation (pointing in or out).

As stated the rules of the game are not well defined. The usual way these things work is that the sailor only changes directions at the corners.  There are alternatives.  One is that he has to turn left or right.  Another is that he chooses one of the four possible directions (with equal probability).  Consider the latter game.  Such a random walk can be decomposed into two independent random walks on a line, where each walker can choose to go forward or backward at each step (block). That is, if the coordinates of the 1D walks are i and j, then the coordinates of the 2D walk are [(i+j)/2, (i-j)/2].  Here is a simple implementation of that

Walk := proc(n);
local pick, i,j,edge,step;
    pick := rand(0..1);
    (i,j) := (0,0);
    edge := 2*n;
    for step do
        i := i + 2*pick()-1;
        j := j + 2*pick()-1;
        if edge < abs(i+j)
        or edge < abs(i-j) then
            return step;
        end if;
    end do;
end proc:

Does the console report an error message?  Try increasing the reporting level to "verbose" (there is a drop-down menu on the bottom menu bar, you may have to click the console icon to display it). 

 

There are several issues with the procedure. I haven't attempted to figure out what it is you are trying to do, but instead will point out the immediate problems I see.

From the parameter name (f), and its usage in the procedure, it appears as though f should be a function.  However, in the example call you give you are passing it the integer 1.  Technically that is allowed in Maple, any number, x, can be applied to an argument (or arguments) and returns itself. For example

1(x) evaluates to 1.

You use c in the procedure but never assign it.

The first conditional will always evaluate to false since abs is a non-negative function.

Are you sure you want to use ?signum in the second conditional?

This appears to be a directed graph.  You can represent it using the ?GraphTheory package,

with(GraphTheory):
V := [O,x,x1,x2,y,y1,y2,z,z1,z2]:
E := {[O,x],[x,x1],[x,x2],[x2,O],[O,y],[y,y1],[y,y2],[y2,O],[O,z],[z,z1],[z,z2],[z2,O]}:
Gr := Graph(V,E);
DrawGraph(Gr);
A := {[O,R],[x1,f(R)],[y1,G(N)],[z1,h(N)]};
map(L -> SetVertexAttribute(Gr,L[1],value=L[2]), A):

First 38 39 40 41 42 43 44 Last Page 40 of 114