acer

32480 Reputation

29 Badges

20 years, 6 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This is the same kind of mistake as your other example, and is not a bug.

A successful way is to use map[2], to map applyrule over B using the entire list half_angle_rule as the first argument (ie. passed to applyrule, for each entry in B).

What your orignal code instructs the elementwise operator applyrule~ to do is more like an interleaved zip action.

restart;

half_angle_rule := [
        sin(x::name) = 2*sin(x/2)*cos(x/2),
        cos(x::name) = 1 - 2*sin(x/2)^2
]:

A := < sin(u), sin(u) >;

A := Vector(2, {(1) = sin(u), (2) = sin(u)})

map[2](applyrule, half_angle_rule, A);

Vector[column]([[2*sin((1/2)*u)*cos((1/2)*u)], [2*sin((1/2)*u)*cos((1/2)*u)]])

applyrule~(half_angle_rule, A);

Vector[column]([[2*sin((1/2)*u)*cos((1/2)*u)], [sin(u)]])

zip(applyrule, <half_angle_rule>, A);

Vector[column]([[2*sin((1/2)*u)*cos((1/2)*u)], [sin(u)]])

Download map2_ex2.mw

The error message states the problem. It is not a bug.

You goal appears to be to map applyrule over each of the entries of C, with all of double_angle_rule as the first argument.

The elementwise operator applyrule~ is not correct for doing that. As you wrote it Maple is trying something more like an interleaved zip operation, but the dimensions of C and double_angle_rule do not match.

One way to accomplish the presumed goal is to utilize map[2].

restart;

double_angle_rule := [
        sin(x::name/2)*cos(x::name/2) = 1/2*sin(x),
        sin(x::name/2)^2 = 1/2*(1-cos(x)),
        cos(x::name/2)^2 = 1/2*(1+cos(x))
]:

C := < cos(1/2*u)*sin(1/2*u), cos(1/2*u)^2 >;

C := Vector(2, {(1) = cos((1/2)*u)*sin((1/2)*u), (2) = cos((1/2)*u)^2})

map[2](applyrule, double_angle_rule, C);

Vector[column]([[(1/2)*sin(u)], [1/2+(1/2)*cos(u)]])

applyrule(double_angle_rule, C[1]);

(1/2)*sin(u)

applyrule(double_angle_rule, C[2]);

1/2+(1/2)*cos(u)

Download map2_ex.mw

That message (about int being protected) can occur with Grid:-Map in at least in some old versions, eg. Maple 16.

You might pass a user-defined procedure instead, eg.

restart;

kernelopts(version);

`Maple 16.01, X86 64 LINUX, May 6 2012, Build ID 744592`

A := Matrix([[x,x^2],[2*x,sin(x)]]);

A := Matrix(2, 2, {(1, 1) = x, (1, 2) = x^2, (2, 1) = 2*x, (2, 2) = sin(x)})

Grid:-Map(e->int(e,x=0..2,numeric=true),A);

Matrix(2, 2, {(1, 1) = 2., (1, 2) = 2.666666667, (2, 1) = 4., (2, 2) = 1.416146837})

Download Gr_M16.mw

You could find both tangents to the hyperbola at x=0.504244923, and then select which touches close to y=0.3781836925.

restart;

(x0,y0) := 0.504244923, 0.3781836925:

expr := 7*x^2-7*y^2-12.0*x+9.0*y+2.25-2*x*y:

both := Student:-Calculus1:-Tangent~([solve(expr,y)],x=x0):

ans := y=~select(t->abs(eval(t,[x=x0])-y0)<1e-5,both)[];

y = 2.112372426*x-.6869693794

plots:-display(
  plots:-pointplot([[x0,y0]],symbol=solidcircle,symbolsize=15),
  plot(eval~(y,[ans]),x=-1..2,color=blue),
  plots:-implicitplot(expr,x=0..2,y=-0.5..1.5),
  view=[0..2,-0.5..1.5],scaling=constrained,size=[300,300]);

Download hyp_tang.mw

The Compiler does not know how to handle the syntax ++n and val += FN, and that's where that error message arises.

But it hardly matters, since the Compiler is not aware of combinat:-fibonnacci. You could have that problematic statement "escape" temporarily back to Maple proper, by wrapping in an eval call.

But adjusting the syntax and escaping the combinat:-fibonacci call will not -- in itself -- result in faster performance.

This looks like a contrived example, perhaps constructed to investigate compilation, etc. If so, then it might be better to tell us any other goals in detail.

It can be shown to be true (via is and combine) in a 1-line statement for your conditions r>0, r<1. (Also for the wider r>-1, r<1.)

C1 := sqrt(r+1)*sqrt(1/(r-1)):
C2 := -sqrt(r^2-1)/(r-1):

is(combine(C1-C2)=0) assuming r>0, r<1;

             true

is(combine(C1-C2)=0) assuming r>-1, r<1;

             true

note: Such situations in which an extra call to combine (or simplify, say) is needed (in order for is to get the result) are quite rare in my experience. Like obscure corners of lepidopterology. I have reported only a few such, over the years. I'll submit a report for this one too.

I prefer solutions in which the "4" does not get rendered in italics (as if it were a name...).

plots:-loglogplot(x, x = 0.1*10^(-5) .. 10,
                  title = 10^Typesetting:-Typeset(-4));

plots:-loglogplot(x, x = 0.1*10^(-5) .. 10,
                  title = 10^(-`#mn(4)`));

plots:-loglogplot(x, x = 0.1*10^(-5) .. 10,
                  title = `#msup(mn("10"),mrow(mo("&uminus0;"),mn("4")));`);

plots:-loglogplot(x, x = 0.1*10^(-5) .. 10,
                  title = InertForm:-Display(`%^`(10,-4),inert=false));

You won't be able to get 23333.33 after rounding to 6 digits, since that requires 7 digits.

Here are a few ways:

restart;

K := evalf[6](Matrix(3,[1/3,-20/3,-20/3,200/3,70000/3,1.44]));

K := Matrix(3, 3, {(1, 1) = .333333, (1, 2) = -6.66667, (1, 3) = -6.66667, (2, 1) = 66.6667, (2, 2) = 23333.3, (2, 3) = 1.44, (3, 1) = 0., (3, 2) = 0., (3, 3) = 0.})

map(x->parse(sprintf("%.2f",x)),K);

Matrix([[.33, -6.67, -6.67], [66.67, 23333.30, 1.44], [0., 0., 0.]])

K := evalf[10](Matrix(3,[1/3,-20/3,-20/3,200/3,70000/3,1.44]));

K := Matrix(3, 3, {(1, 1) = .3333333333, (1, 2) = -6.666666667, (1, 3) = -6.666666667, (2, 1) = 66.66666667, (2, 2) = 23333.33333, (2, 3) = 1.44, (3, 1) = 0., (3, 2) = 0., (3, 3) = 0.})

new := map(x->parse(sprintf("%.2f",x)),K):
new;

Matrix([[.33, -6.67, -6.67], [66.67, 23333.33, 1.44], [0., 0., 0.]])

The result here is actually as its displayed.

new[1,2]

-6.67

You could also get K printed with the effect. This does
not affect the actual values.

interface(displayprecision=2):
K;
interface(displayprecision=-1):

Matrix([[.3333333333, -6.666666667, -6.666666667], [66.66666667, 23333.33333, 1.44], [0., 0., 0.]])

A similar effect can be obtained by right-clicking on the
following outout and changing its numeric-formatting
(in-place) to "Fixed" with 2 decimal places.

K;

Matrix(3, 3, {(1, 1) = .33, (1, 2) = -6.67, (1, 3) = -6.67, (2, 1) = 66.67, (2, 2) = 23333.33, (2, 3) = 1.44, (3, 1) = 0., (3, 2) = 0., (3, 3) = 0.})

K[1,2];

-6.666666667

Download Matrix_dec.mw

You could use a kind of identity procedure that has its first procedural parameter declared with the uneval modifier.

[Int(1/sqrt(x), x), 'int(1/sqrt(x), x)', 'sin(1.2)', 'cos((1/6)*Pi)']

[Int(1/x^(1/2), x), int(1/sqrt(x), x), sin(1.2), cos((1/6)*Pi)]

(1)

((proc (x::uneval) options operator, arrow; x end proc) = value)([Int(1/x^(1/2), x), int(1/sqrt(x), x), sin(1.2), cos((1/6)*Pi)])

[Int(1/x^(1/2), x), int(1/sqrt(x), x), sin(1.2), cos((1/6)*Pi)] = [2*x^(1/2), 2*x^(1/2), .9320390860, (1/2)*3^(1/2)]

(2)

NULL

Download expr_equals_evalexpr_ac.mw

It works in Maple 2017 onwards.

If you copy&paste that pretty-printed output then what you get pasted in contains,

    1/(4*(x - 2))

And that becomes 1/(4*x - 8) due to automatic simplification.

However, if instead you line-print rf using the lprint command then you can get a (more correct and accurate) input form, which here happens to not automatically simplify.

restart;

r:=(x^4-8*x^3+24*x^2-24*x+12)/((4*x^2*(x-2)^2));

(1/4)*(x^4-8*x^3+24*x^2-24*x+12)/(x^2*(x-2)^2)

rf:=convert(r,fullparfrac,x);

1/4-(3/4)/x-(1/4)/(x-2)+(3/4)/(x-2)^2+(3/4)/x^2

lprint(rf)

1/4-3/4/x-1/4/(x-2)+3/4/(x-2)^2+3/4/x^2

1/4-3/4/x-1/4/(x-2)+3/4/(x-2)^2+3/4/x^2

1/4-(3/4)/x-(1/4)/(x-2)+(3/4)/(x-2)^2+(3/4)/x^2

Download lprint_pasted.mw

ps. As a long-standing habit I almost never copy&paste from 2D Output, due to various historical issues and problems with doing so. I usually copy from line-printed form.

Those are available in my Maple 2021.1 from the Large Operators palette.

Here's a way that doesn't require the ad hoc steps either of having to enter 3/100 manually or of having to refer to subexpression position via subsop. (It's so ad hoc that one might as well manually and explicitly write out the desired result, with protection against automatic simplification.)

Retaining the number of trailing zeroes (or not) is possible, but more effort.

f := 0.03 - 0.03*cos(5.885*t);

0.3e-1-0.3e-1*cos(5.885*t)

temp:=subsindets(f,float,u->convert(u,rational,exact));

3/100-(3/100)*cos((1177/200)*t)

ans := ``(evalf(content(temp))) * evalf(temp/content(temp));

``(0.3000000000e-1)*(1.-1.*cos(5.885000000*t))

simplify(expand( f - ans ));

0.

Download some_float_thing.mw

Also, we don't know whether you want a result that can be further manipulated (I guess so), or just a nice printing of the desired form. That can affect how some approaches are set up. Please provide the context.

An alternative is to freeze (or equivalent) the floats, after pulling off their sign. Then factor, revert while protecting against automatic simplification, etc. The trick there is ensuring that any minus-sign doesn't accidentally also get factored out front...

Your worksheet seems to have been last saved by you in Maple 13.

Using Maple 16.02 (the oldest I have at hand) it succeeds for your tau_l=0.8 if Digits is raised for the computations done prior to the problematic fsolve call, and if Digits is temporarily reduced for that call.

restart; with(plots)

Digits:=15:

The value of the parameters

omega_2 := .9892367:

eq_n := d-omega_4*omega_3/(omega_2*(omega_2*(1+n)^3+omega_2*(1+n)^2+omega_3*(1+n))):

fsolve({eq_n});

{n = .204400893732215}

x := 0.1e-1*T:

{nu = 1.03105988003254}

N1 := 1:

tau_c := 0.4551282e-1:

e1 := 9*(5.25*5)/(7*(24-10.35)*12):

tau_l := 0.8e-1:

eq_l3 := (1+n)*(1-tau_l)*(1-l2)/(Gamma*(1-tau_l-tau_upsilon)*(1-e1-l1))-(1-l3)/(nu*(1-l2));

1.22319829096998/Gamma-1.44893115172597+1.44893115172597*l3

{Gamma = 1.12560976598776, l3 = .250000000000000}

IOR := .2578598:

.83005166510992

.287475393180557

h := (Gamma*l1+l2)*h2/(1+n)+omega_3*h2*l3/(omega_2*nu*(1+n)^2);

.540810514922412

0.419629983047938e-1

.232264170334192

Upsilon := w*(nu*h2*(Gamma*l1+l2)*(1+n)*omega_2+omega_3*h2*l3)/(nu*((2+n)*(1+n)*omega_2+omega_3));

0.619481908316401e-1

cpp := (1/3)*theta_4*(2*(Upsilon-upsilon)+Gamma*w*h2*l1/(1+n)-upsilon);

0.112091197673597e-1

eq_chi := cpp*N4+(1+n)*omega_2*nu*exp(x)*chi = tau_upsilon*((Upsilon-upsilon)*omega_3/((1+n)^2*omega_2)+(Upsilon-upsilon)/(1+n)+Gamma*w*h2*l1/(1+n)-upsilon)+(1+r)*chi:

fsolve({eq_chi});

{chi = 0.530719545110145e-2}

oas := .522*cpp:

a := k-chi;

0.366558028536924e-1

EQ1 := a = a2/((1+n)*omega_2)+a3/(omega_2*(1+n)^2)+omega_3*a4/(omega_2^2*(1+n)^3):

The equations to solve

EQ2 := c = y-f*e1-(1+n)*omega_2*nu*exp(x)*k:

EQ4 := Gamma*(1-tau_l-tau_upsilon)*(1-e1-l1)/((1+n)*c1) = (1-tau_l)*(1-l2)/c2:

EQ6 := c2 = (1+(1-tau_a)*r)*c1/((1+rho)*nu*exp(x)):

EQ9 := (1+rho)*kappa_2*c2 = (1+n)*omega_2*c1:

EQ11 := Gamma*l1+(1-tau_l)*l2/(1-tau_l-tau_upsilon) = nu*(1+n)*(1/kappa_2-1)*(1+f*(1+n)/((1-tau_l-tau_upsilon)*w*Gamma*h2))/psi:

EQ12 := nu*exp(x)*a2 = (1-tau_l)*Gamma*w*h2*l1/(1+n)+epsilon_1+eta_1-tau_upsilon*(Gamma*w*h2*l1/(1+n)-upsilon)-(1+tau_c)*c1-f*e1:

EQ13 := nu*exp(x)*a3 = (1-tau_l)*w*h2*l2+(1+(1-tau_a)*r)*a2/omega_2+eta_2-tau_upsilon*(Upsilon-upsilon)-(1+tau_c)*c2-(1+n)*epsilon_1:

EQ14 := nu*exp(x)*a4 = (1-tau_l)*w*h2*l3/nu+(1+(1-tau_a)*r)*a3/omega_3+eta_3-tau_upsilon*(Upsilon-upsilon)-(1+tau_c)*c3:

EQ15 := (1+(1-tau_a)*r)*a4/omega_4+(1-tau_b)*(benef-gis)+gis = (1+tau_c)*c4:

EQ16 := tau_a*r*a+tau_c*c+tau_l*w*h+tau_b*(benef-gis)*N4 = eta_1*N1+eta_2*N2+eta_3*N3+(benef-cpp)*N4:

EQ17 := eta_2 = theta_2*(w*h2*l2+r*a2/omega_2):

EQ19 := f*e1/(c1+f*e1) = f_c1:

EQ21 := (tau_a*r*a+tau_l*w*h+tau_b*(benef-gis)*N4)/(r*a+w*h+(benef-gis)*N4) = tau:

EQs := {EQ10, EQ11, EQ12, EQ13, EQ14, EQ15, EQ16, EQ17, EQ18, EQ19, EQ2, EQ20, EQ21, EQ3, EQ4, EQ5, EQ6, EQ7, EQ8, EQ9}:

sv := {a2 = 0.1221680719e-1, a3 = 0.1221680719e-1, a4 = 0.1221680719e-1, benef = 0.1124557996e-1, c = .1412084225, c1 = 0.4267487699e-1, c2 = 0.5054102276e-1, c3 = 0.5985711412e-1, c4 = 0.6e-1, eta_2 = 0.4379459675e-2, eta_3 = 0.4e-2, f = 0.2810224635e-2, gis = 0.1e-2, kappa_2 = .7624704939, rho = .1236315697, tau_a = 0.1502430093e-1, tau_b = 0.7118933432e-1, theta_2 = 0.3946903560e-1, theta_3 = 0.39e-1, epsilon_1 = 0.2278732126e-1}:

Digits, oldDigits := 10, Digits;

10, 15

{a2 = 0.2181958727e-1, a3 = 0.1124241131e-1, a4 = 0.1842706633e-1, benef = 0.2325955123e-1, c = .1716741092, c1 = 0.5077912975e-1, c2 = 0.5518159721e-1, c3 = 0.5996575141e-1, c4 = 0.6516468394e-1, eta_2 = 0.1043313324e-1, eta_3 = 0.3091761489e-2, f = 0.3389901163e-2, gis = 0.6199270941e-2, kappa_2 = .8435924269, rho = .2996595542, tau_a = .1664750365, tau_b = -.6526622810, theta_2 = 0.9203906044e-1, theta_3 = 0.39e-1, epsilon_1 = 0.5153824973e-1}

15

eval(map(rhs-lhs, EQs), newsol);

{-0.153701e-9, -0.35502e-10, -0.21572e-10, -0.20677e-10, -0.148362e-10, -0.942622e-11, -0.93461e-11, -0.82466e-11, -0.30785e-11, -0.27822e-11, -0.14772e-11, 0.26576e-12, 0.105684e-11, 0.26276e-11, 0.33262e-11, 0.105704e-10, 0.114792e-10, 0.123763e-10, 0.137975e-10, 0.8559e-9}

NULL

Download ACCOLLEY_Delali_-_Demographics_3_ac.mw

restart;

 

`#mover(mo("="),mo("?"));`

`#mover(mo("="),mo("?"));`

 

`print/queryequal` := proc(a,b)
   uses Typesetting;
   mrow(mrow(Typeset(a),
        mo("&InvisibleTimes;"),
        mover(mo("="),mo("?")),
        mo("&InvisibleTimes;"),
        Typeset(b)));
end proc:

 

queryequal(X, Y);

queryequal(X, Y)

queryequal( sum(f(n),n=1..infinity), sqrt(Pi)/2);

queryequal(sum(f(n), n = 1 .. infinity), (1/2)*Pi^(1/2))

Download mover_ex.mw

In the last example above the result is an actual expression (which you could further manipulate programmatically if you wanted). It is an unevaluated function call to the unassigned global name queryequal.

In 2D Math entry mode you could get a similar rendering effect directly on input, by using the Layout palette for placing ? above =, etc. Here's what I got with that approach. I put in an extra space on either side of the symbol, and the result was this multiplication of terms. (I don't find that useful for further manipulation. But you could also just use the palette approach for non-executable 2D Math used for discourse rather than further computation.)

restart

sum((1/2)*f(n)*`#mover(mo("&equals;"),mo("&quest;"))`*sqrt(Pi), n = 1 .. infinity)

sum((1/2)*f(n)*`#mover(mo("&equals;"),mo("&quest;"))`*Pi^(1/2), n = 1 .. infinity)

lprint(%)

sum(1/2*f(n)*`#mover(mo("&equals;"),mo("&quest;"))`*Pi^(1/2),n = 1 .. infinity)

Download mover_2dinput.mw

First 75 76 77 78 79 80 81 Last Page 77 of 337