Joe Riel

9665 Reputation

23 Badges

20 years, 28 days

MaplePrimes Activity


These are answers submitted by Joe Riel

In addition to Carl's point, there are a few syntax errors in the modelica.  The class specifier should be model, not Model. Also, there is no semicolon after Main.  The Imports line should be removed. What version of MapleSim are you using?  The Modelica Code Editor should be able to catch those errors, when you save the model.

Did you try the Manage Style Sets option in the Format menu?  See the help page ?worksheet,documenting,styles.

The aFshear routine is attempting to assign to a parameter (R).  That is not allowed. 

You really should not be using linalg; it's been deprecated for quite a while.  There are equivalent methods in LinearAlgebra for the few linalg procedures you are using; the help pages for the linalg commands mentions what is appropriate.

Another way to do this is to use simplify with the siderels option. See the help page ?simplify,siderels for details.

eqn1 := e1*i1 + e2*i2 + e3*i3 = 0:
sol := solve( { eqn1 } , { i1 } , 'explicit' ):
eqn2 := n12 = e1/e2:
simplify(sol, {eqn2}, {e1,e2});
                       {i1 = (-e3*i3*n12-e1*i2)/n12/e1}
expand(%);
                       {i1 = -1/e1*e3*i3-i2/n12}

What version of Maple are you using? Is the error generated by the second line? Consider using the more robust with(Maplets:-Elements); using the colon-dash prevents an evaluation of Elements.

If you do this regularly, it might be useful to define a procedure/operator that performs the composition.  For example

`&@` := proc(M1 :: Matrix, M2 :: Matrix)
local M, i, j, k, m, n, p, q;
    (m,n) := upperbound(M1);
    (p,q) := upperbound(M2);
    if n <> p then
        error "Matrix dimensions are not compatible";
    end if;
    M := Matrix(m,q);
    for i to m do
        for j to q do
            M[i,j] := add(M1[i,k](M2[k,j]), k = 1..n);
        end do;
    end do;
    M;
end proc:

Here is a typical usage

(**) M1 := Matrix([[D[1], 0],[0, D[1]+D[2]],[1,D[1]-2*D[2]]]):
(**) M2 := Matrix([[U[1],U[2]],[U[3],U[4]]]):
(**) M1 &@ M2;
                          [         D[1](U[1])                       D[1](U[2])          ]
                          [                                                              ]
                          [   D[1](U[3]) + D[2](U[3])          D[1](U[4]) + D[2](U[4])   ]
                          [                                                              ]
                          [1 + D[1](U[3]) - 2 D[2](U[3])    1 + D[1](U[4]) - 2 D[2](U[4])]


(**) map(apply, %, x,y);
              [            D[1](U[1])(x, y)                             D[1](U[2])(x, y)             ]
              [                                                                                      ]
              [   D[1](U[3])(x, y) + D[2](U[3])(x, y)          D[1](U[4])(x, y) + D[2](U[4])(x, y)   ]
              [                                                                                      ]
              [1 + D[1](U[3])(x, y) - 2 D[2](U[3])(x, y)    1 + D[1](U[4])(x, y) - 2 D[2](U[4])(x, y)]

(**) convert(%, diff);
                [             d                                          d                         ]
                [             -- U[1](x, y)                              -- U[2](x, y)             ]
                [             dx                                         dx                        ]
                [                                                                                  ]
                [   /d            \   /d            \          /d            \   /d            \   ]
                [   |-- U[3](x, y)| + |-- U[3](x, y)|          |-- U[4](x, y)| + |-- U[4](x, y)|   ]
                [   \dx           /   \dy           /          \dx           /   \dy           /   ]
                [                                                                                  ]
                [    /d            \     /d            \        /d            \     /d            \]
                [1 + |-- U[3](x, y)| - 2 |-- U[3](x, y)|    1 + |-- U[4](x, y)| - 2 |-- U[4](x, y)|]
                [    \dx           /     \dy           /        \dx           /     \dy           /]


LaterThis isn't quite right, the 1 in M1 doesn't act like the identity operator. I wish Maple provided a builtin for that. You could replace it with x->x.

Am not sure this is doable.  As an aside, you might want to use the inert forms, Sum and Int, in the procedure assignments, to avoid any attempt at a futile symbolic evaluation.

As a gross simplification, I think you want something like

y := Sum(u[k]*v[k], k=1..n):
diff(y, u[j]);

to return either v[j] or, more ideally, piecewise(j :: integer[1..n], u[j], 0) (note that the latter is not actually valid Maple unless n is explicitly assigned a value). I'm not aware of any Maple packages that will do that.

The best way to do this is put the Maple source in ascii files and use version control on them.  Use either a read statement in a worksheet to read the source, or, better, create an mla (Maple Library Archive file) from the source, install it in a custom toolbox and use it from any Maple interface. 

Did you try what I suggested for your related question?  You should be able to use the same technique for a completely custom port, just enter the name you gave for the custom port in the text area. Hmm.  I see that there is a bug.  You can work around it by first inserting a copy of the custom port you created onto the main MapleSim canvas, then reclicking the Apply Custom button in the Custom Component Template (see my directions at your other post).

  1. Add a port
  2. In the Type: combo-box, select Custom (it's the last choice).
  3. In the text-area below that, enter Modelica.Thermal.FluidHeatFlow.Interfaces.FlowPort
  4. Click the Apply Custom button

The rest should be handled as any other port.  You'll see signals for the pressure, enthalpy, mass flow rate and enthalpy flow rate.

Use evalf:

sol := solve(g(x)>0,[x]):
evalf(sol);
                    [[x < -0.3399702769], [1.278826630 < x]]

Pass a positive integer as the second argument to evalf to select the number of digits

evalf(sol, 20);

Can you give an example?  If it is a differential equation you might be able to use DynamicSystem:-Linearize.

There are several things wrong with your usage:

  1. S, L, and B are not parameters, they are variables.  In the equations they should appear as S(t), etc. The use of ODETools[declare] might avoid that, but makes specifying the initial conditions more difficult.
  2. gamma has special meaning in Maple; use another variable (I used g)
  3. initial conditions must be equations, not inequalities

I may have forgotten another.  Here is a corrected version

init_conds := S(0) = 0, L(0) = 0, B(0) = 0;
sys := {init_conds
        , diff(B(t), t) = L(t)*g-g*mu
        , diff(L(t), t) = L(t)*S(t)*beta-(g+mu)*S(t)
        , diff(S(t), t) = -L(t)*S(t)*beta-`μS`+mu
       };
sol := dsolve(sys, 'numeric', 'parameters' = [mu, `μS`,beta, g], 'method = rkf45');

First, it is usually better to upload your worksheet (use the green arrow), that makes it much easier for us to try what you've done.

You can create an Array with elements from -5 to 5: 

n := 5:
U := Array(-n .. n, -n .. n):

You are executing convert(U, Matrix). By itself that returns a Matrix, however, it does not affect U, which remains an Array. That is fine, since a Maple Matrix always has indices that start at 1.

The pathname you show is almost certainly wrong in that backslashes (is this a Windows server?) need to be escaped in a Maple string. For  your example, the appropriate string would be "\\drivename\\filename.txt".  Using single forward slashes (Unix path separators) will generally work.

First 13 14 15 16 17 18 19 Last Page 15 of 114