acer

32313 Reputation

29 Badges

19 years, 311 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

restart;

phi := (1+sqrt(5))/2:

plots:-pointplot([seq([n, sin(n*phi)], n = 1000 .. 2000)],
                  symbol = point, axes = boxed, size=[250,250],
                  labels = [n, eval('Typesetting:-Typeset'(sin(sort('n*phi',
                                                                 order=plex('phi','n')))))],
                  labeldirections = [horizontal, vertical]);

restart;

phi := (1+sqrt(5))/2:

plots:-pointplot([seq([n, sin(n*phi)], n = 1000 .. 2000)],
                  symbol = point, axes = boxed, size=[250,250],
                  labels = [n,sin(`#mrow(mo("φ"),mo("⁢"),mi("n"));`)],
                  labeldirections = [horizontal, vertical]);

 

Download label_ts.mw

I don't mind having to force the desired ordering of the terms in the product. But it would be much better if typeset were not so weak (ie. if it were to do the full job of typesetting to a form that were not fragile w.r.t. subsequent reordering or evaluation). It's not very user-friendly, to have to go to so much effort to produce a more robust result.

You asked why it happens. It happens because that's of how convert(..,string) is handling it, using the %a format.

You might prefer to force the %g format instead.

sprintf("%g",0.12);

              "0.12"

As for your convert call, it does this:

sprintf("%a",0.12);

              ".12"

> trace(sprintf):
> convert(0.12,string);
{--> enter sprintf, args = "%a", .12
              ".12"

<-- exit sprintf (now in `convert/string`) = ".12"}
              ".12"

What do you think about the following?

restart;

expr := exp(I*x);

exp(I*x)

eq := expr = evalc(expr);

exp(I*x) = cos(x)+I*sin(x)

eval( eq, x=I);

exp(-1) = cosh(1)-sinh(1)

convert(%, exp);

exp(-1) = exp(-1)

cos(I);

cosh(1)

sin(I);

I*sinh(1)

I*sin(I);

-sinh(1)

Download eu.mw

If I understand what you're after then this seems to accomplish that last simplification, and also gets the earlier rational part in another manner.

maxcharheight_ac.mw

[edit] I will submit a bug report against simplify, for the following:

ee := exp(2*ln(1/2 - sqrt(5))*sqrt(5)):

simplify(ee); # hmm

   exp(2*(-ln(2)+ln(-1+2*5^(1/2))+I*Pi)*5^(1/2))

simplify(expand(ee));

    (1/2-5^(1/2))^(2*5^(1/2))

simplify(ee,exp);

    (1/2-5^(1/2))^(2*5^(1/2))

This is one way to get what you asked, "captions fig.1,fig.2,fig.3,fig.4 in the Tabulate command ( variable G) without taking into account the random order of the graphs".

TEST_-_Copie_ac1.mw

Hopefully you have asked for that which you actually want.

Here is one way that your example can be handled.

restart;

eq := a[n]=b*c[n]/d^2*(e+f[n])/g;

a[n] = b*c[n]*(e+f[n])/(d^2*g)

teq := c[n]*(e+f[n])=__u:

eval(isolate(simplify(eq,{teq}),__u),(rhs=lhs)(teq));

c[n]*(e+f[n]) = a[n]*d^2*g/b

Download isolate_ex.mw

You could also use solve instead of isolate. Variations can handle some cases where there are multiple solutions from solve. For some examples algsubs could be used instead of simplify (simplify with side-relations), to do the temporary substitution by a dummy name.

Are you also going to have examples where you want to treat the (smallest?) arithmetic subexpression that contains the target names, eg. both c[n] and f[n] present, say, but without your having to specify that explicitly? A clear and precise characterization of your possible examples may help.

I'm not sure that I understand your scenario. But perhaps this is close.

(edit: I am not providing you with the direct approach of simply multiplying a symbol by a unit, eg. pp:=p*Unit(m). I had imagined that you were asking about something more complicated.)

restart;

kernelopts(version);

`Maple 2021.1, X86 64 LINUX, May 19 2021, Build ID 1539851`

 

U := proc(x, u)
  if not x::complexcons then return 'procname'(x,u);
  else x*u; end if;
end proc:
`print/U` := proc(x) x; end proc:

 

pp := U(p,Unit(m));

U(p, Units:-Unit(m))

qq := U(q,Unit(s));

U(q, Units:-Unit(s))

 

Now pp and qq print nicely as just p and q. And you can substitute
numeric values for names p or q and have the units appear.

 

 

expr1 := pp*qq;

U(p, Units:-Unit(m))*U(q, Units:-Unit(s))

Now a substitution (evaluation at a point).

eval(expr1, [p=4, q=3]);

12*Units:-Unit(m)*Units:-Unit(s)

expr2 := 7*Unit(cm*s) + pp*qq;

7*Units:-Unit(cm*s)+U(p, Units:-Unit(m))*U(q, Units:-Unit(s))

Now another substituion at a point.

eval(expr2, [p=5.5, q=2.1]);

7*Units:-Unit(cm*s)+11.55*Units:-Unit(m)*Units:-Unit(s)

combine(%,units);

11.62000000*Units:-Unit(m*s)

The combining of units can be made mostly automatic.
(You don't have to make this happen automatically.)

with(Units:-Simple):

 

eval(expr2, [p=5.5, q=2.1]);

11.62000000*Units:-Unit(m*s)

Download units_hidden.mw

The implicitdiff command gives the following, directly and staightforwardly.

restart;

implicitdiff({2*x*y^3+3*x^2*y=1},{x(y)},{x},y,notation=Diff)[1];

Diff(x, y) = -(3/2)*x*(2*y^2+x)/(y*(y^2+3*x))

 

If you need the terms massaged.

 

lhs(%)=sign(numer(rhs(%)))
       *expand(numer(rhs(%))/sign(numer(rhs(%))))/expand(denom(rhs(%)));

Diff(x, y) = -(6*x*y^2+3*x^2)/(2*y^3+6*x*y)

Download implicitdiff_ex.mw

Firstly, try not to use the word "function" if you find yourself in a muddle with expressions (that depend on name t) versus operators (whose formal parameter dummy name just happens to be t). Otherwise you might be using the word ambiguously.

restart;


Here f is an expression that depends on t. There
are no operators in play here.

f := sin(x(t));

sin(x(t))

diff(f, t);

(diff(x(t), t))*cos(x(t))

restart;


Here f is an operator. It is not an expression that
depends on t.

f := t -> sin(x(t));

proc (t) options operator, arrow; sin(x(t)) end proc


But f(t) is an expression that depends on t, after
applying the operator f to t.

f(t);

sin(x(t))

diff(f(t), t);

(diff(x(t), t))*cos(x(t))


If you really want you could construct a new
operator from that.

unapply(%, t);

proc (t) options operator, arrow; (diff(x(t), t))*cos(x(t)) end proc


Alternatively we can directly construct a new
operator which returns the derivative (wrt t) of
what f returns.

D(f);

proc (t) options operator, arrow; (D(x))(t)*cos(x(t)) end proc


We can also apply that new operator to t. This
produces an expression that depends on t.

D(f)(t);

(D(x))(t)*cos(x(t))


We could now also convert that expression
from D form to active diff form.

convert(%, diff);

(diff(x(t), t))*cos(x(t))

 

Download differentiation_expr_vs_operator.mw

Also, note that Diff is an inert version of active diff. Your goal is to actively differentiate, so using inert Diff would just add more muddle here.

Here are a few ways. I used the second (red code) in the plot on the right.

I moved the angle textplot a little to the left, and reduced the font size to 14.

restart


These first two examples look ok.

 

nprintf(`#mn("%a&deg;");`,100);

`#mn("100&deg;");`

Typesetting:-mn("100&deg;");

"100&deg;"


In this next example the spacing between the number
and the degree symbol is a little too wide.

 

100*`&deg;`;

100*`&deg;`


In the next example the 100 is in italic font,
which doesn't look as good.

 

cat(100, `&deg;`);

`100&deg;`

NULL

NULL

g[1] := plot([[0, 0], [1, 0], [-1, 2], [0, 0]], style = line, color = black, axes = none)

g[2] := plots[textplot]({[-.7, 1.6, typeset(beta), 'font' = ["times", 16]], [-.6, 1, typeset(b), 'font' = ["times", 16]], [0.5e-1, .13, typeset(alpha), 'font' = ["times", 16]], [.1, 1, typeset(c), 'font' = ["times", 16]], [.5, -.1, typeset(a), 'font' = ["times", 16]], [.8, .11, typeset(psi), 'font' = ["times", 16]]})

plots[display]([g[1], g[2]], caption = ["Triangle 1", font = [TIMES, BOLD, 16]], size = [300, 300])

NULL

g[1] := plot([[0, 0], [1, 0], [2, 2], [0, 0]], style = line, color = black, axes = none)

 

Below I typed in Typesetting:-mn("100&deg;") and the
input was immediate marked up with the degree symbol

 

g[2] := plots[textplot]({[.22, .1, typeset(omega), 'font' = ["times", 16]], [.5, -.1*(1/2), typeset(p), 'font' = ["times", 16]], [.8, 1, typeset(x), 'font' = ["times", 16]], [.89, .1, Typesetting:-mn("100&deg;"), 'font' = ["times", 14]], [1.6, 1, typeset(m), 'font' = ["times", 16]], [1.75, 1.65, typeset(gamma), 'font' = ["times", 16]]})

plots[display]([g[1], g[2]], caption = ["Triangle 2", font = [TIMES, BOLD, 16]], size = [300, 300])

 

Download QuestionTypeset_ac.mw

You seem to be mistakenly conflating this GetEquations functionality with this older (deprecated) GetEquations functionality that has a different usage and syntax.

The names "foo" and "bar" are convenient short names, where the general idea is that people may recognize them as being offhand, disposable, example names.

See foobar and FUBAR, which respectively give the letter "r" as standing for "repair" and "recognition". I am more familiar with the latter.

You have to supply the initial voltage, if they don't provide it for you. Otherwise your function U(t) will not output values that are numeric. You need numeric values for plotting. That should not be surprising.

[edit] I'll note that part a) says to plot the graph of y=U(t).

You wrote, U(t)=cos(2t)*U*e^t/10, but that's not what the text image shows! The text uses a "U" with subscript "0" on the right-hand side. That's a common way to represent the initial value (constant), and is intended to be a distinct name and not the same as the "U" on the lhs.

The initial voltage should not be assigned to a name that depends on the same name U as used for the procedure. So, in Maple, U0 or U__0 would be ok, but U[0] is asking for trouble.

Note that U__0 (double underscore) prettyprints with a subscript. (See also here for shortcuts).

In this attachment I typed the keystrokes U__0 to get the subscripted name in 2D Input.

restart

U := proc (t) options operator, arrow; U__0*exp(-(1/10)*t)*cos(2*t) end proc

proc (t) options operator, arrow; U__0*exp(-(1/10)*t)*cos(2*t) end proc

U__0 := 20

20

plot(U, 0 .. 10, size = [500, 200])

Download initial_U.mw

restart;

 

 

bracket:=proc(ee::{list,set},
              {left::{truefalse,identical("{","[","(")}:=true,
               right::{truefalse,identical("}","]",")")}:=true})
  local i; uses Typesetting;
  mrow(piecewise(member(left,{true,"{"}),mo("&lcub;"),
                 left="[",mo("&lbrack;"),left="(",mo("("),mo("")),
       mtable(seq(mtr(mtd(Typeset(EV(ee[i])))),i=1..nops(ee))),
       piecewise(member(right,{true,"}"}), mo("&rcub;"),
                 right="]",mo("&rbrack;"),right=")",mo(")"),mo("")));
end proc:

 

 

sys:=[x+y-z = 3, x-y-z = 5, -x-y-z = 7];

[x+y-z = 3, x-y-z = 5, -x-y-z = 7]

bracket(sys);

"{[[x+y-z=3],[x-y-z=5],[-x-y-z=7]]}"

bracket(sys, left=false);

"[[x+y-z=3],[x-y-z=5],[-x-y-z=7]]}"

bracket(sys, right=false);

"{[[x+y-z=3],[x-y-z=5],[-x-y-z=7]]"

bracket(sys, left="[", right="]");

Vector(3, {(1) = x+y-z = 3, (2) = x-y-z = 5, (3) = -x-y-z = 7})

bracket(sys, left=false, right="]");

"[[x+y-z=3],[x-y-z=5],[-x-y-z=7]]]"

bracket(sys, left="[", right=false);

"[[[x+y-z=3],[x-y-z=5],[-x-y-z=7]]"

bracket(sys, left="(", right=")");

Vector(3, {(1) = x+y-z = 3, (2) = x-y-z = 5, (3) = -x-y-z = 7})

bracket(sys, left=false, right=")");

"[[x+y-z=3],[x-y-z=5],[-x-y-z=7]])"

bracket(sys, left="(", right=false);

"([[x+y-z=3],[x-y-z=5],[-x-y-z=7]]"

bracket(sys, right="]");

"{[[x+y-z=3],[x-y-z=5],[-x-y-z=7]]]"

Download fencing.mw

Here are various ways (since you explicitly asked about select, and a loop).

restart;

r:=rand(0...5.):

y:=[seq(r(), n=1..10)]:

#
# Kitonum's good suggestion.
#
[seq(`if`(y[n]>0 and y[n]<1,[n,y[n]],NULL), n=1..nops(y))];

[[1, .2499109628], [4, .3475034102], [10, 0.8823971507e-2]]

#
# This is slightly less efficient since it creates list [$nops(y)]
#
map(i->`if`(y[i]>0 and y[i]<1,[i,y[i]],NULL), [$nops(y)]);

[[1, .2499109628], [4, .3475034102], [10, 0.8823971507e-2]]

#
# This inefficiently creates all [i,y[i]] even if not needed.
# It also creates list [$nops(y)]
#
select(u->u[2]>0 and u[2]<1, map(i->[i,y[i]], [$nops(y)]));

[[1, .2499109628], [4, .3475034102], [10, 0.8823971507e-2]]

#
# Using a loop, which is not awful but more to code.
#
L:='L': # L will become a table
for i from 1 to nops(y) do
  if y[i]>0 and y[i]<1 then
    L[i] := [i,y[i]];
  end if;
end do:
convert(L, list);

[[1, .2499109628], [4, .3475034102], [10, 0.8823971507e-2]]

#
# This is a bad way to do it, by repeatedly
# augmenting the list.
#
L:=[]:
for i from 1 to nops(y) do
  if y[i]>0 and y[i]<1 then
    L := [op(L), [i,y[i]]];
  end if;
end do:
L;

[[1, .2499109628], [4, .3475034102], [10, 0.8823971507e-2]]

 

Now some timings, with a larger example of 10^5 elements.

Each is done after its own restart, for a fair comparison.

 

restart;

r:=rand(0...5.):

y:=[seq(r(), n=1..10^5)]:

str:=time[real]():

[seq(`if`(y[n]>0 and y[n]<1,[n,y[n]],NULL), n=1..nops(y))]:

(time[real]()-str)*'seconds';
nops(%%);

.293*seconds

20166

restart;

r:=rand(0...5.):

y:=[seq(r(), n=1..10^5)]:

#
# This is slightly less efficient since it creates list [$nops(y)]
#
str:=time[real]():

map(i->`if`(y[i]>0 and y[i]<1,[i,y[i]],NULL), [$nops(y)]):

(time[real]()-str)*'seconds';
nops(%%);

.329*seconds

20166

restart;

r:=rand(0...5.):

y:=[seq(r(), n=1..10^5)]:

#
# This inefficiently creates all [i,y[i]] even if not needed.
# It also creates list [$nops(y)]
#
str:=time[real]():

select(u->u[2]>0 and u[2]<1, map(i->[i,y[i]], [$nops(y)])):

(time[real]()-str)*'seconds';
nops(%%);

.479*seconds

20166

restart;

r:=rand(0...5.):

y:=[seq(r(), n=1..10^5)]:

str:=time[real]():

L:='L': # L will become a table
for i from 1 to nops(y) do
  if y[i]>0 and y[i]<1 then
    L[i] := [i,y[i]];
  end if;
end do:
convert(L, list):

(time[real]()-str)*'seconds';
nops(%%);

.363*seconds

20166

restart;

r:=rand(0...5.):

y:=[seq(r(), n=1..10^5)]:

#
# This is a bad way to do it, by repeatedly
# augmenting the list.
#
str:=time[real]():

L:=[]:
for i from 1 to nops(y) do
  if y[i]>0 and y[i]<1 then
    L := [op(L), [i,y[i]]];
  end if;
end do:
L:

(time[real]()-str)*'seconds';
nops(%%);

15.413*seconds

20166

 

Download list_selection.mw

[edit] If you only want the first element that satifies the condition (or if you know that your list has at most one such element) then there are approaches that can be faster. It can be beneficial to break out of the search as soone as one element is found. For example, comparing with the original seq approach,

restart;

r:=rand(1.0..5.0):

y:=[seq(r(), n=1..10^5)]:
y:=[y[1..floor(nops(y)/3)][],0.4,y[floor(nops(y)/3)+1..-1][]]:

str:=time[real]():

[seq(`if`(y[n]>0 and y[n]<1,[n,y[n]],NULL), n=1..nops(y))];

(time[real]()-str)*'seconds';

[[33334, .4]]

.230*seconds

restart;

r:=rand(1.0..5.0):

y:=[seq(r(), n=1..10^5)]:
y:=[y[1..floor(nops(y)/3)][],0.4,y[floor(nops(y)/3)+1..-1][]]:

str:=time[real]():

L:='L': # L will become a table
for i from 1 to nops(y) do
  if y[i]>0 and y[i]<1 then
    L[i] := [i,y[i]];
    break;
  end if;
end do:
convert(L, list);

(time[real]()-str)*'seconds';

[[33334, .4]]

0.83e-1*seconds

restart;

r:=rand(1.0..5.0):

y:=[seq(r(), n=1..10^5)]:
y:=[y[1..floor(nops(y)/3)][],0.4,y[floor(nops(y)/3)+1..-1][]]:

#
# If we only want the first successful element then
# the table is not necessary.
#
str:=time[real]():

for i from 1 to nops(y) do
  if y[i]>0 and y[i]<1 then
    ans := [i,y[i]];
    break;
  end if;
end do:
ans;

(time[real]()-str)*'seconds';

[33334, .4]

0.84e-1*seconds

 

restart;

r:=rand(1.0..5.0):

y:=[seq(r(), n=1..10^5)]:
y:=[y[1..floor(nops(y)/3)][],0.4,y[floor(nops(y)/3)+1..-1][]]:

str:=time[real]():

(e->[e,y[e]])(ListTools:-SelectFirst(e->e>0 and e<1, y, 'output'=':-indices'));

(time[real]()-str)*'seconds';

[33334, .4]

.112*seconds

 

Download list_selection_singleton.mw

First 79 80 81 82 83 84 85 Last Page 81 of 336