Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are answers submitted by Joe Riel

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):

To read from an Excel spreadsheet, use ?ExcelTools[Import].  There are multiple ways to read from a text file; start with ?readdata.

The ?odeplot procedure does not work with that expression; it requires that the expression can be fully evaluated at time t. Following is a method to do this, using a simple example

deq := diff(x(t),t) + x(t) = 1:
dsol := dsolve({deq, x(0)=0},numeric,output=listprocedure);
xt := eval(x(t), dsol);
Xt := t -> evalf(Int(xt,t..t+tau));
tau := 1:
plot([xt,Xt], 0..1);

There are a lot of problems with that modelica.  I can clean some up, but others are more substantial.  From a practical point, the real problem is that the template code (I assume you are using the Custom Modelica Component template) is suppressing a useful error messag returned by the flattener (code that parses the Modelica).  I'll be fixing that bug.  In the meantime I'm going to explain a workaround so that you can see the error messages.

Save your modelica to a file (say basisFunction.mo).

In Maple, assign the following procedure

flatten := proc( modelica :: string, model :: string )
uses MM=MapleSim:-Modelica;
    MM:-PrintResult(MM:-Flatten(modelica,model));
end proc:

Now call the procedure, passing it the name of the saved Modelica file and the Modelica class of interest

flatten("basisFunction.mo", "basisFunction");
Error, (in MapleSim:-Modelica:-EvaluateExpression) cannot resolve
`basisFunction.theta_r[1,1]`; there is no `theta_r[1,1]` in model
`basisFunction`

I've included a typical error message.  The error is a bit cryptic, but the reason for it is that the declaration of theta_r does not include dimensions.  Actually, for that parameter there is another issue. linsolve returns a vector (one dimensional) but you are accessing theta_r with two dimensions.  You'll have to resolve that. 

Other problems include bPen being declared twice, parameters c and bFunc being given no initial value (actually, your code is assigning to parameters, which is not allowed, it should be a variable).  

Let me know if that allows you to resolve the bugs.



You could try a ?piecewise expression:

piecewise( h(t)>0, 0, F(h(t))) 

where F(h(t)) is an expression for the force during compression

Remove the embedded graph from the spreadsheet; that, apparently, is interfering with the import of the Matrix.

 

The integrand has the opposite parity of n, so the integral is zero for n even.

The declarations of x1 and x2 don't make sense.  The left part should be a Modelica type; what you have is referencing a variable in the class.  I'm not quite sure what you intend. If you want two real inputs, one for angle, one for angular velocity, just do

Modelica.Blocks.Interfaces.RealInput phi annotation(...);
Modelica.Blocks.Interfaces.RealInput omega annotation(...);

and use phi and omega where you have x1 and x2 (or rename the inputs to x1 and x2). Alternatively, if you want a rotational flange as a connection and will sense phi and omega from it, you could do

Modelica.Mechanics.Rotational.Interfaces.Flange_a  flange_a annotation(...);
Real phi, omega;
equation
phi = flange_a.phi;
omega = der(phi);
...

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