acer

32313 Reputation

29 Badges

19 years, 312 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Your code is set up to only ever execute the Bez:-Click procedure, upon clicking. And that procedure is only set up to add the current clicked point.

What you want, I think, is to have the Click code call procedures which appropriately add or remove a point, according to the state of the checkboxes. You  can do that in two ways, as conditonal code in the Click procedure:
1) have Click examine the values of the checkboxes, and dispatch according to procedures which add/remove the current clicked point.
2) have Click examine a module local which stores the current mode or operation (adding, or removing), and dispatch accordingly.

Also, if you select/toggle-on either of the checkboxes then you'd want the other unselected/toggled-off. Instead of putting in code to manage all that, it's simpler to replace the two checkboxes with a pair of radio-buttons in the same "group". That way the GUI automagically toggles the other off when either is toggled on. (That's the main distinction of of radio buttons versus checkboxes.)

The modification in the attechment takes route 1), and examines the values of the radio buttons in the conditonal check. The way I have it, there is no action code directly inside the radio buttons.

An alternative to the conditional checks on the values of the radio buttons is to have a new module local which stores the running state/purpose, and do the conditional checks on that local instead. Then you could have the action code of those radio buttons set the value of that local appropriately. I did not do it that way, but both ways can work.

Also, I changed the reset checkbox into a button.

I also added a line which (I hope) will make the Plot1 component be set into a state where mouse manipulation actions are click/click-drag instead of point-probe/etc. Without that your original worksheet was re-opening for me with the manipulator in the wrong state.

sketch_ac.mw

(I used Maple 2015.2 for the changes.)

[edit] If your collection of checkboxes/radiobuttons has only two members, reflecting a single boolean condition, than another alternative is to use just a single toggle-button. (You could even toggle its caption between "add" and "remove".)

Maple is a case-sensitive language, and the command you were trying to utilize is spelled with, all in lowercase.

You accidentally used the capitalized name With.

Note that you can also call the GetProperty command by its fully qualified name. See attached.

CreatingSlider_ac.mw

Most "new" user-level Library commands (created since around 2000) have so-called Camel case spelling, but there are many much older commands that have purely lowercase spelling.

You haven't shown us how you were testing a pair of expressions against each other.

If you were using evalb then you should read its Help page carefully.

Here are a couple of approaches,

restart;

expr1 := -a*b + a*c:
expr2 := a*(c-b):

is(expr1-expr2=0);

           true

evalb(simplify(expr1-expr2=0));

           true

eq1 := expr1 = expr2;

    eq1 := -a b + a c = a (c - b)

is((rhs-lhs)(eq1)=0);

           true

evalb(simplify((rhs-lhs)(eq1))=0);

           true

# note the following

evalb(expr1=expr2);

           false

evalb(eq1);

           false

If your were doing something else, or had additional examples, then you should show that here explicitly.

This is not really satisfactory, but I'll mention it nonetheless,

restart;
ode:=diff(y(x),x) = 2*(2*y(x)-x)/(x+y(x)):
ic:=y(0)=2:

combine(dsolve([ode,ic],'implicit')) assuming x>0, y(x)>2*x;

     ln(2*(y(x)-x)^2/(y(x)-2*x)^3) = 0

combine(dsolve([ode,ic],'implicit'), symbolic) assuming x>0;

     ln(2*(y(x)-x)^2/(y(x)-2*x)^3) = 0

Your essential problem is not due to differences between map and elementwise ~ .

It is due to the difference between a matrix (as implemented via arrays) and a Matrix.

Your code assigns a matrix to outCx, since that is what linalg:-multiply returned, for Ts_sksulXCin each a Matrix.

Your code assigns a 3x1 Matrix to outCy, since Ts_sksul, XCin are each a Matrix and that's what `.` returned (with appropriate dimensions).

You got confused about the problem because your examples differed in more that a single way. You guessed the wrong difference, as the cause of the discrepancy.

See the attachment for revisions, etc.

Q20210612_ac.mw

You should not be using linalg:-multiply, since (amongst other reasons) that is deprecated. Use `.` or LinearAlgebra's Multiply command instead.

The error message may be indicating that the name t has been previously assigned a value. Is that the case?

What happens if you do 

   t:='t';

right before calling NonlinearFit?

It would be better if you could upload and attach a worksheet that reproduces the problem. (Green up-arrow in the Mapleprimes editor.) Then we could tell whether the other arguments being passed were also valid, etc.

It might work better using Sum instead of sum. But an actual worksheet would be better.

If I understand correctly what you are after, here is one way.

[edit] I have added some alternatives in my comments under your Reply below. That includes plots:-display(seq(...),insequence) as well as use of Explore.[end edit]

Notice that the number of frames (frames option) and the range 1..nops(L) passed to the animate command both match the number of entries in the list L. Notice also the trunc call, so that the list L is indexed by integers instead of the passed floats.

restart;

F := theta -> plot(sin(x*theta), x=0..2*Pi,
                   caption=typeset("theta =",sprintf("%.2f",theta))
                   ):

L := [seq(sqrt(i),i=1..20)]:

plots:-animate(F, [L[trunc(i)]], i=1..nops(L),
               paraminfo=true,
               frames=nops(L));

discretelist_anim.mw

Of course you can comment out the caption option of the plotting command, or alter how the value gets used (you don't need to make it a float, but I dislike jitter as the caption length varies...).  You could also pass paraminfo=false to the animate command. I set both those up so that you could see the effect.

It's often difficult to pinpoint the precise cause of a problem without having code that reproduces that problem. And you haven't supplied that (or even the call-stack in the debugger session).

In which case perhaps trying alternatives might be more straightforward than guessing back and forth as to the underlying cause.

You might try these instead (in your procedure):

is(tmp_1);

is(simplify(tmp_1));

is((rhs-lhs)(tmp_1)=0);

is(simplify((rhs-lhs)(tmp_1))=0);

evalb(simplify((rhs-lhs)(tmp_1)=0));

Without knowing your general case, I might prefer the 4th or 3rd of those.

By the way, if you are trying to establish a mathematical equivalence then evalb(simplify(...=...)) is not best in general (even if it works for your example, including at the top level). That is because, in general, two expressions from each side of an equation that are mathematically equivalent might be represented in separate classes that don't produce a exactly matching simplifed/canonical form (including under simplify). This might not be the case in your given example, but I offer it as a general consideration.

This attachment has two ways to handle your followup example, which you gave as,

   fcty := RootOf(T, r);
   polarplot(fcty);

mpprime_acc.mw

[edit] I've replaced my earlier attachment and removed the method=_d01ajc suggested by Preben for your original issue, which works well in Maple 2020.2 but not Maple 2021.1 due to a bug. I have replaced that method specification by use of the operator-form calling sequence (using unapply), as an alternate mechanism for prevent discontinuity checks. This works quickly in both my Maple 2020.2 and 2021.1.

By the way, it looks like you're still using Maple 2020.0, and the update to point-release 2020.2 is a free download.

The animate command is part of the plots package.

It won't work if you call the only plain name animate without having loaded the plots package (or that command).

It works for me if instead I call it as plots:-animate, or plots[animate] in very old versions. Ie,
   F:=...
   plots:-animate(...)

It works for me if I first load that command from the plots package. Ie,
   with(plots,animate):
   F:=...
   animate(...);

It works for me if I first load the whole plots package. Ie,
   with(plots):
   F:=...
   animate(...);

 

It's not quite clear precisely how you wish to extend your given example.

But this might give you some hints, as two ways to regenerate your given example, along with a simple extension.

restart;
my_alph := [ "A1", "B1", "C1", "D1", "E1", "F1", "G1", "H1", "I1",
             "J1", "K1", "L1", "M1", "N1", "O1", "P1", "Q1", "R1",
             "S1", "T1", "U1", "V1", "W1", "X1", "Y1", "Z1", "AA1",
             "AB1", "AC1", "AD1", "AE1", "AF1", "AG1", "AH1", "AI1",
             "AJ1", "AK1", "AL1", "AM1", "AN1", "AO1", "AP1", "AQ1",
             "AR1", "AS1", "AT1", "AU1", "AV1", "AW1", "AX1", "AY1",
             "AZ1", "BA1", "BB1", "BC1", "BD1", "BE1", "BF1", "BG1",
             "BH1", "BI1", "BJ1", "BK1", "BL1", "BM1", "BN1", "BO1",
             "BP1", "BQ1", "BR1", "BS1", "BT1", "BU1", "BV1", "BW1",
             "BX1", "BY1", "BZ1" ]:

AZ := StringTools:-Explode(StringTools:-Iota("A" .. "Z")):

ans1 := [map(cat,AZ,"1")[],
         map[2](cat,"A",AZ,"1")[],
         map[2](cat,"B",AZ,"1")[]]:

evalb(ans1=my_alph); # they are the same

               true

ans2 := [seq(map[2](cat,p,AZ,"1")[], p=["","A","B"])]:

evalb(ans2=my_alph); # they are the same

               true

#
# And now one way to extend it. (output omitted...)
#
[seq(map[2](cat,p,AZ,"1")[], p=["",AZ[1..7][]])];

Do you need to know how to get a generated list whose desired number of entries is known beforehand, but might not be a multiple of 26? The math for that is not difficult, but I don't know whether you need that step. Would you want that number constructed from the ranges of values that Ql, Tl will take?

The last example above can be modified, say altering the p=["",AZ[1..7][]] portion to get additional entries or nesting.

In 2D Input mode, use the key-strokes y _ _0 ( ie. y underscore underscore 0 ) to enter a subscripted name for the initial value. (That keeps the variable distinct from the name y.)

In several places your document muddles up text, inlined 2D Math, and executable 2D Input.

Also, your sheet does quite a lot of cut&paste of values, but you could instead make it flow nicely in a programmatic manner. Ideally you should rarely if ever have to cut&paste previously computed values, since that is error prone, awkward to read, and does not allow recomputation if any parameter values are changed, etc.

See attachment, and check for mistakes(!).

Worksheet_1_ac.mw

Adjust to suit your own style, add back the removed commentary, etc.

Note that some of your original comments are incorrect. For example you had, "Now that we know that the half-life of the isotope is roughly 0.693147180559945 years..." but that is wrong. The half-life is given as 24360 years. The computed value 0.6931.. simply approximates ln(2). What you were solving at that part of the sheet is actually the value of the parameter k.

Member vv is correct, in that the Tabulate approach in Maple 2015 needs interface(typesetting=extended) or equivalent for the piecewise call to pretty-print as desired. In Maple 2017 the default was changed to extended.

Also, in your DocumentTools:-Layout approach the calls to Equation could simply be passed the (documented) typesetting=extended option. So both approaches can work even in Maple 2015.

See attached,

DT_piecewise_ac.mw

Your followup remark used the word "depends". And since that is what seems to really matter here, why not utilize the depends command?

Also, it seems more robust to remove the piecewises which depend upon x, rather that merely select those which happen to have identically t as one side of only some non-compound relation.

I added conditional t<0 or x[1]<0 to make it harder.

expr := piecewise(x[1](t)<0, -1, x[2](t)<1, 0, 1) + f(t)
        + piecewise(t<0, 0, t<1, 1, 0) + x(t)*piecewise(t<0, 1, t<1, 0, 1)
        + a*piecewise(t<0, 3, t<1, -1, 2)
        + a*piecewise(t<0 or x[1]<0, 3, t<1, -1, 2);

# testing whether the piecewises depend upon x
#
indets(expr,And(piecewise,
                satisfies(pw->not depends(pw,[x]))));

# testing only whether the conditionals of the piecewises depend upon x
#
indets(expr,And(piecewise,
                satisfies(pw->not ormap(depends, op~(1,PiecewiseTools:-ToList(pw)),[x]))));

# first of those, but in two separate steps...
indets(expr, piecewise);
remove(pw->depends(pw,[x]), %);

pw_depends.mw

This is not fast, since it has to decode the 2D Math contents.

But it can help in the case that the input code is in only 2D Math form. Ie, when the desired/queried-for code appears only in 2D Input but not also as plaintext.

This approach also happens to search the 1D Maple notation plaintext code, as well as conversions of input from 2D Math.

rough_mw_text_search.mw

Of course you'd need to adjust how ListDirectory is called, for your machine and directory locations. You could also make it more defensive, add bells & whistles, etc.

By the way, the Maple program code contents are not in a "binary format". The encoded portions are in a base64 encoding of Maple's .m dotm format. That is neither impossible to decode nor exceptionally strange, and in the attachment that aspect is all handled automatically by the WorksheetToMapleText command.

ps. On my Linux machine I use its grep utility to search files for plaintext strings. But 2D Math is a trickier situation.

First 86 87 88 89 90 91 92 Last Page 88 of 336