acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Another workaround that I see for this problem with the maplet plotdevice is to add the style=line option to the plot command.

That can be done for all 2D plots via the command,
   plots:-setoptions(style=line):
which can be added to the start of a worksheet or an initialization file.

(That does not interfere with the default behavior of plots:-pointplot.)

You might find this less intrusive on your other computations than a workaround such as increasing Digits above 15, or setting UseHardwareFloats to false, etc, which may have broad reaching effects on calculations.

Your first attempt using solve fails because the remaining variables are not free of conditions.

You could think of it like so; solve baulks at returning a solution for T & a if there are remaining conditions on some of the other names involved.

Here are some alternatives to Rouben's natural suggestion to specify {T,a,I__cm} as the second argument to solve.

The first uses eliminate instead of solve, and it reveals a relationship amonsgt the remaining variables. (That happens to be the third equation, which here seems obvious but for other examples might not be so apparent.)

The second uses the parametric option to the solve command. Notice that if m=0 then T=0 and I__cm=0 also. In that case a can be anything, and not just g/2.

You could also specify a subset of the remaining variables as the parameters.

restart;

sys := {I__cm = m*r^2, r*T = I__cm*a/r, g*m - T = m*a};

{I__cm = m*r^2, r*T = I__cm*a/r, g*m-T = m*a}

R := eliminate(sys, {T, a});

[{T = g*m*I__cm/(m*r^2+I__cm), a = g*m*r^2/(m*r^2+I__cm)}, {-m*r^2+I__cm}]

S := solve(R[2], I__cm);

{I__cm = m*r^2}

eval(R[1], S);

{T = (1/2)*g*m, a = (1/2)*g}

solve(sys, {T, a}, parametric = full);

piecewise(r = 0, [], -m*r^2+`#msub(mi("I"),mi("cm"))` = 0, piecewise(m = 0, [{T = 0, a = a}], r = 0, [{T = -a*m+g*m, a = a}], m <> 0 and r <> 0, [{T = (1/2)*g*m, a = (1/2)*g}]), `and`(r <> 0, -m*r^2+`#msub(mi("I"),mi("cm"))` <> 0), [])

solve(sys, {T, a}, parameters = {I__cm}, parametric = full);

piecewise(-m*r^2+`#msub(mi("I"),mi("cm"))` = 0, [{T = (1/2)*g*m, a = (1/2)*g}], -m*r^2+`#msub(mi("I"),mi("cm"))` <> 0, [])

solve(sys, {T, a}, parameters = {m}, parametric = full);

piecewise(-m*r^2+`#msub(mi("I"),mi("cm"))` = 0, piecewise(m = 0, [{T = 0, a = a}], m <> 0, [{T = (1/2)*g*m, a = (1/2)*g}]), -m*r^2+`#msub(mi("I"),mi("cm"))` <> 0, [])

solve(sys, {T, a}, parameters = {r}, parametric = full);

piecewise(r = 0, [], -m*r^2+`#msub(mi("I"),mi("cm"))` = 0, piecewise(r = 0, [{T = -a*m+g*m, a = a}], r <> 0, [{T = (1/2)*g*m, a = (1/2)*g}]), `and`(r <> 0, -m*r^2+`#msub(mi("I"),mi("cm"))` <> 0), [])

Download solveSysac.mw

You were already using k for the index of summation (sum call) that gets computed by f. That k was not being declared local to f. And the index name is not local to the sum call.

Then you try to use k in a wrapping seq call, as the index name. So, when seq invoked f, k takes a numeric value -- and is not free for use as an index name by sum.

You could use a different name (eg. kk) as the index name in that seq call.

Or you could change f from an operator into a procedure with local k.

Or you could change f to use add instead of sum, since in this situation add can safely use its own local instance of the index name.

For example, implementing both the second and third approaches (my preference),

Least-Squares_Fitting_in_Maple_video_ac.mw

I did the above in Maple 2019, since that was the version in which your attachment was last saved.

Usng 2D Input you should be able to simply utilize the keystrokes A__* , ie. A, underscore, underscore, *. That produces the underlying expression `A__*` which automatically gets typeset in the desired way.

If the subscipt is more complicated (than just *) you should be able to build it up in 2D Input using the Layout and other palettes.

Sometimes it may be necessary also to right-click on the input item and use the menu choice 2-D Math -> Convert To -> Atomic Variable. But that it not necessary for your example.

The attachment below shows a variety of ways to do your example in 1D plaintext Maple code.

restart;

plot(x^2, labels=[`A__*`, ""])

plot(x^2, labels=[A[`&ast;`], ""])

plot(x^2, labels=[`#msub(mi("A"),mi("*"));`, ""])

P := (b,s) -> nprintf("#msub(%a,%a);",
                      convert(Typesetting:-Typeset(b),`global`),
                      convert(Typesetting:-Typeset(s),`global`)):

plot(x^2, labels=[P(A,`*`), P(Z,`+`)])

Download misc_subscripts_1D.mw

If you want to remove overhead of doing it via an OS system call then you might consider using Maple's external calling.

You'd need to compile&link your routine to a shared library (.so or .dll, according to platform), rather than as a main executable.

Apart from removing overhead of the system call (a kind of scripting), external calling also allows inplace hardware array passing.

See the help pages for define_external and externalcalling.

Ideally, only when a procedure or appliable module is documented for users should it be called a command. In the Maple programming language "command" doesn't really have a technical meaning.

The phrase "internal command" is suboptimal, because "internal" denotes something undocumented while "command" denotes something made for users and which should be documented. Better would be internal procedure. I wouldn't be surprised to learn that I sometimes misuse that term.

None of these should ever be called function! There used to be a policy in Maplesoft's R&D that that term would not be used in documentation except for the special Maple language technical meaning as the type named function (ie. an unevaluated function call). It was a sensible policy because Maple had expressions and procedures, and it's very important for users to keep those two things conceptually separate; it's just too easy for users prone to calling both of those things "function" to become confused between those two concepts.

The word "function" also has another, quite specific, technical mathematical meaning, and also yet another common meaning in computer science. It's better to avoid the latent ambiguity.

Whether or not a procedure returns a value or not (ie. returns NULL) is irrelevant to what it should be called.

If you want one word for most of these then I'd suggest either procedure or command. (Even in the case of an appliable module the procedure assigned to the module's ModuleApply member is what gets invoked. So even there it's not so much of a stretch to use that term.)

The word restart is an exception. It could be considered as a language keyword rather than a procedure in the usual sense. And it is documented. So calling it a command makes sense. Something similar might be said for the error statement.

There's no perfect solution. As you can see, I side with your summary about the word procedure: "My inclination is to call everything for which one uses a functional call (section 3.8) as a procedure." But command is not inherently terrible, even if it lacks a tight technical language definition and can sometimes lead to ambiguity.

The word I'd advise most against using is function, because it has a technical meaning which does not match how people would often use it.

note: see also type/callable

Here is more recovery:

Regnede_Eksamenssæt_ac.mw

There might be a missing 2D Math expression, near the beginning of section (iii), in the line starting,
  "G er undergruppe af..."

I will add this to an earlier bug report of similar problems.

Somehow you've managed to get an extra, hidden Execution Group between the
   proc(ix,iy)
and the
   global T

I don't know how you managed that. I can cut&paste that procedure definition from my answer to your previous Question, into a new Execution Group, without that happening.

I notice that the 1D code appears to reside inside a Document Block, instead of the usual (single) Execution Group. I suspect that this may be the cause of the problem. I personally would only use Execution Groups (red > cursor) for 1D code inside a Document.

(See the entries in the "Insert" menu from the GUI's menubar. Or use Ctl-k as a keyboard shortcut.)

The densityplot command is passing floating-point values to your procedure f. But the indices of your tables are integers.

Try this (for your second attached Document):

f := proc(ix,iy)
    global T: local x:=trunc(ix), y:=trunc(iy);
    print(x,y," Returning ",T[x][y]):
    return T[x][y]:
end:

The problem in your first Document is different -- some of the inner tables' indices are HFloats, since the part 2*A[1 .. (), 2 .. 3] results in a datatype=float[8] Matrix, with the entries in B[5..,2..] being HFloats as a default consequence. There are various ways to "fix" that. But I'll wait to see if you intend on using floats or integers in some final densityplot construction, ie. perhaps a merging of your second Document's two densityplots with the kind of float values in the Matrix A of your second Document.

In any case, you'll need to ensure that the values used to index into the tables actually match the indices of said tables.

ps. It's spelled table, uncapitalized.

If the option restricttoranges is not specified as true (and it defaults to false) then the procedure is sampled at the midpoints between the grid values.

Notice the positions of the tickmarks on the axes.

It looks as if what you expected was the result from this:

   plots:-densityplot(g, 1 .. 4, 2 .. 8, grid = [5, 5], restricttoranges = true)

note: You can also supply just that option name alone, to get it specified as true.

The subs command substitutes into the stored structure. But N__1/N is not present alone as a separate structural subexpression of q*N__1/N. All three multiplicands in the expression are stored "together". That's why your first example did not succeed.

That is an important reason why the algsubs command exists, to do a substitution mathematically (as opposed to structurally). That command can handle your first example,

g := q*N__1/N

q*N__1/N

algsubs(N__1/N = X__1, g)

q*X__1

Download algsubs_ex.mw

See the Help page for algsubs for more examples. There are also a few examples of differences between subs and algsubs on the Help page for the subs command.

Your second example worked because the lhs of your substitution equation matched the whole expression (which is, of course, structurally present).

The Typesetting system has to be very careful about inadvertantly evaluating expressions, hence the special evaluation behaviour of its Typeset command.

The fact that the Typeset procedure's first parameter is specified with the uneval modifier doesn't mean that its output is "of type uneval", as you phrased it. You've misused that terminology. Yes, the first argument passed to that procedure is not evaluated as usual. (See ?type,uneval for a technical description of that term.)

There is a related export of the Typesetting module, Typesetting:-EV, which can often be utilized to get the kind of evaluation that you might want when calling Typesetting:-Typeset on, say, and assigned name. For example,

ee := sin(x);

sin(x)

Typesetting:-Typeset(ee);

ee

lprint(%);

Typesetting:-mi("ee")

Typesetting:-Typeset(Typesetting:-EV(ee));

sin(x)

lprint(%);

Typesetting:-mrow(Typesetting:-mi("sin",fontstyle = "normal"),Typesetting:-mo(
"&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mi("x")))


Download TS_ex.mw

The mi stands for mathematical identifier, in MathML parlance. (See here.) Maple's typesetting renders such in italics by default, unless modified by a property such as fontstyle, etc.

That contrasts with, say, mo which as MathML stands for mathematical operator. Maple renders such in upright Roman by default.

You could use the piecewise command. For example,

f := x -> piecewise(x>0, x, x<0, -x);

f := proc (x) options operator, arrow; piecewise(0 < x, x, x < 0, -x) end proc

f := x -> piecewise(x>=0, x, x<0, -x);

f := proc (x) options operator, arrow; piecewise(0 <= x, x, x < 0, -x) end proc

plot(f);

Download pw_ex.mw

Or, as 2D Input (I used command-completion here),

f := proc (x) options operator, arrow; piecewise(0 <= x, x, x < 0, -x) end proc

proc (x) options operator, arrow; piecewise(0 <= x, x, x < 0, -x) end proc

Download pw_ex2d.mw

Here is one way to handle this example. (I did not bother to make it work for other flavors of radical, or products involving floats and radicals and other multiplicands.)

This gets the same form as your showed and named Desired.

restart;

with(LinearAlgebra):

interface(imaginaryunit=j):

Amat := Matrix(2, 2, [[-0.1428571428*K__D, -0.1081971238], [376.9911185, 0]]);

Matrix(2, 2, {(1, 1) = -.1428571428*`#msub(mi("K"),mi("D",fontstyle = "normal"))`, (1, 2) = -.1081971238, (2, 1) = 376.9911185, (2, 2) = 0})

T:=Eigenvalues(Amat);

Vector(2, {(1) = -0.7142857140e-1*`#msub(mi("K"),mi("D",fontstyle = "normal"))`+0.2000000000e-9*sqrt(0.1275510203e18*`#msub(mi("K"),mi("D",fontstyle = "normal"))`^2-0.1019733868e22), (2) = -0.7142857140e-1*`#msub(mi("K"),mi("D",fontstyle = "normal"))`-0.2000000000e-9*sqrt(0.1275510203e18*`#msub(mi("K"),mi("D",fontstyle = "normal"))`^2-0.1019733868e22)})

Desired := sqrt((2.000000000*10^(-10))^2 * (1.275510203*10^17*K__D^2 - 1.019733868*10^21));

(0.5102040812e-2*K__D^2-40.78935472)^(1/2)

evalindets(T,&*(float,`+`^(1/2)),u->signum(op(1,u))*(op([2,1],u)*op(1,u)^2)^(1/2));

Vector(2, {(1) = -0.7142857140e-1*`#msub(mi("K"),mi("D",fontstyle = "normal"))`+sqrt(0.5102040812e-2*`#msub(mi("K"),mi("D",fontstyle = "normal"))`^2-40.78935472), (2) = -0.7142857140e-1*`#msub(mi("K"),mi("D",fontstyle = "normal"))`-sqrt(0.5102040812e-2*`#msub(mi("K"),mi("D",fontstyle = "normal"))`^2-40.78935472)})

Download Q20230110_m1_ac.mw

You can put use these commands to set those as defaults for the session, for 2-D and 3-D plots respectively.

plots:-setoptions('symbol'=':-solidcircle','symbolsize'=12);
plots:-setoptions3d('symbol'=':-solidcircle','symbolsize'=12);

 

First 52 53 54 55 56 57 58 Last Page 54 of 336