Joe Riel

9530 Reputation

23 Badges

20 years, 26 days

MaplePrimes Activity


These are answers submitted by Joe Riel

Are you entering text in a math region?  Look at the context bar, the "Text" field should be selected.  If "Math" is selected then you are entering text in a math region.

To match a parenthesis, you need to escape it by preceding it with a backslash, otherwise the parenthesis starts a group.  Doubling the parentheses, as you did, just creates two groups, both of which match exactly the same text. In fact, you actually need to precede the parenthesis with two backslashes because Maple backslashes must be doubled (escaped) to be entered into strings.

The way to handle this substitution is to use \# fields in the replacement string.  A \# string is a backslash (doubled) followed by an integer; the field is replaced with the matching group.  See ?RegSubs for details. I would create a regular expression with two groups, the first matches upto the first insertion point, the second matches to the end.  In the replacement text, insert these two groups, using \\1 and \\2, interspersed with the added text.

To match the text surrounded by parentheses I'd use the trick of matching the opening parenthesis, followed by anything that is not a closing parenthesis, followed by the closing parenthesis. The partial regular expression for that is "\\([^)]+\\)", where [^)] matches any character that is not a closing parenthese.  You might want to use * rather than + to permit matching no characters, but that is a detail. 

Thus,

str := ( "(4) dup 0 stringbbox 452 exch sub exch pop 2582 exch m show\n"
         "(x) dup 0 stringbbox 908 exch sub exch pop 3800 exch m show\n"
       ):

StringTools:-RegSubs("(exch m show\n\\([^)]+\\) )(dup 0 stringbbox [0-9]+ exch sub exch pop [0-9]+ exch m show\n)"
                     = "\\1TickLabelFont\\2AxisLabelFont"
                     , str);

To handle the ORIENTATION, do

str := "ORIENTATION(45.,45.,45.)":
StringTools:-RegSubs("(ORIENTATION\\([0-9.+-]+,[0-9.+-]+),[0-9.+-]+\\)"="\\1)",str);
                                                        "ORIENTATION(45.,45.)"

To match square-brackets, and other special symbols, escape them with a backslash, doubled as before. See ?regular_expressions for details. Or just ask here.


u := a+b*x:
eqs := { eval(u,x=h) = 4, eval(diff(u,x),x=6)=4 };
                          eqs := {b = 4, a + b h = 4}

solve(eqs, {a,b});
                             {a = -4 h + 4, b = 4}

Frequently it is possible to use ?frontend with ?diff to compute the derivative you want. For example, here is a simple procedure to compute the Euler-Lagrange equations from the Lagrangian:

T := 1/2*m*diff(x(t),t)^2:
V := m*g*x(t):
L := T - V;
                                  /d      \2
                       L := 1/2 m |-- x(t)|  - m g x(t)
                                  \dt     /


EulerLagrange := proc(L,X::set(name),t)
local x;
    { seq(diff(frontend(diff, [L, diff(x(t),t)]),t)
          - frontend(diff, [L,x(t)]) = 0
          , x = X) };
end proc:

deqs := EulerLagrange( L, {x}, t);
                                  / 2      \
                                  |d       |
                       deqs := {m |--- x(t)| + m g = 0}
                                  |  2     |
                                  \dt      /

dsolve(deqs);
                                      2
                                   g t
                         {x(t) = - ---- + _C1 t + _C2}
                                    2

 

 

The differential equations are badly formatted.  For example, unless K and y1 are assigned something else, diff(K,y1) evaluates to 0.  Also, it is quite unlikely that both diff(Y1(t),t) and diff(K,Y1) should both appear in the set, as they do.

You can do that with the ?VectorCalculus package. However, the expression given is for a 2D curve. The binormal and torsion apply to 3D curves. Maybe the z-component is t?

Eliminating the expression may be difficult, but converting the equations to the form

diff(u(x),x) = F1( u(x), delta(x) );
diff(delta(x),x) = F2( u(x), delta(x) );

is easy enough.  Just do

convert(solve(convert({eq1,eq2},D), D({u,delta})(x)), diff);

A better approach may be to remove the undefined points immediately after creating the plot structure.  While not the most efficient (and I worry about these huge plots you allude) a generic method is something like

cleanplot := subsindets(testplot, 'list({numeric,undefined})'
                    , L -> if hastype(L,'undefined') then NULL else L end if
                   ):

This won't work with plots that use rtable structures.

While it should not effect what needs to be done, I believe that the original poster wants L*s and C*s, not Ls and Cs.

Do you mean after the radix mark?  For example

x := -23.12345:
digs := abs(op(1, frac(x)));
                digs := 12345
add(k, k = convert(digs,base,10));
                            15

The procedure Percentile is not assigned. Did you mean to use ?Statistics[Percentile].  Is W supposed to  be in terms of the variables w[i]?

In this case it is both easy and tricky to locate the error.  Tricky because the error occurs during the creation of a module.  Simple because we got luck (sort of) .  Just do the following (this only works if you have a version of Maple with the actual error).

> restart;
> with(Statistics):
> i := 1:
> stoperror(traperror):
> RandomVariable(ProbabilityTable([1/2, 1/2]));
Error, summation variable previously assigned, second argument evaluates to %1, 1 = 1 .. 2
SumTools:-Preprocess:
  13       error "summation variable previously assigned, second argument evaluates to %1", ind = rng

DBG> where
TopLevel: Statistics:-RandomVariable(ProbabilityTable([1/2, 1/2]))
        [ProbabilityTable([1/2, 1/2])]
Statistics:-RandomVariable: return procname('_R',args[1])
        [_R, ProbabilityTable([1/2, 1/2])]
Statistics:-RandomVariable: T := Statistics:-Distribution(R)
        [ProbabilityTable([1/2, 1/2])]
Statistics:-Distribution: T := Statistics:-Distributions:-Inventory:-NewInstance(args[1])
        [ProbabilityTable([1/2, 1/2])]
Statistics:-Distributions:-Inventory:-NewInstance: return Statistics:-Distributions:-Inventory:-GetDistributionByName(dn)(op(dp))
        [[1/2, 1/2]]
ModuleApply: MakeDistribution(args)
        [[1/2, 1/2]]
MakeDistribution: module () export Conditions, ParentName, Parameters, CDF, Mean, ProbabilityFunction, RandomSample, RandomVariate; options Distribution, Discrete; Conditions := [plist::('list(realcons)')]; ParentName := ':-ProbabilityTable'; Parameters := [plist]; CDF := t -> sum(plist['k'],('k') = 1 .. min(floor(t),nops(plist))); ProbabilityFunction := t -> piecewise(t < 1,0,t         []
`unknown/6C11C8`: Mean := sum(i*[1/2, 1/2][i],i = 1 .. nops([1/2, 1/2]))
        [1/2, 1 = 1 .. 2]
sum: input := SumTools:-Preprocess(args)
        [1/2, 1 = 1 .. 2]
SumTools:-Preprocess:
  13       error "summation variable previously assigned, second argument evaluates to %1", ind = rng

You can see the error occuring in the arguments to the printed lines.  Look carefully at the module that is created in the call to MakeDistribution.  Note that the Mean export is assigned as

Mean := sum(i*plist[i],i = 1 .. nops(plist));

There's the problem,  i is a global variable.  Another issue is that the sum should be an add. Of course, that would have masked this problem, since an add wouldn't fail here, but could otherwise (say if i were protected).

Could be, I'm also using linux. 

There are two problems.  Because you are using actual underscores (rather than indices) for the names, you cannot use

seq( ... fp_i ... , i = 1..9)

to reference the fp_x variables.  You can fix that by using the catenate operator, ||

col := seq(fn_||i = (1-1/tau)*fp_||i + 1/tau * feq(i), i = 1..9):

The second problem is that while you have 10 equations, you only give solve 7 variables.  You need to specify more variables. For example

eqs := { massconserv, col };
vars := { seq(fp_||i, i=1..9), rho_wall }:
solve(eqs, vars);

I'm having a hard time reading the Maple code, the font displays badly on my machine.  It appears that you wrote

col := seq(fn_i = ... , i = 1..9);

You probably want to change that to

col = seq(fn[i] = ... i=1..9);

Just to confuse the matter, they could be equivalent, since typing underscore in 2D match is equivalent to using square brackets, however, if you had done that I wouldn't expect to *see* the underscore in the text, it would have expanded to a subscript.

First 45 46 47 48 49 50 51 Last Page 47 of 114