acer

32405 Reputation

29 Badges

19 years, 350 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Perhaps you're after this kind of functionality,

solve( Or(And(x + y = 2,y = 1,x > 0),And(x^2 = 4, x < 0, y = 0)) );
 
         {x = 1, y = 1}, {x = -2, y = 0}

restart;

eq := A=P*(1+r/n)^(n*t);

A = P*(1+r/n)^(n*t)

ans:=combine(simplify(evalindets(solve(eq,n,allsolutions),suffixed(_Z),u->0)));

-r*ln(A/P)/(r*t*LambertW(-ln(A/P)*(A/P)^(-1/(r*t))/(r*t))+ln(A/P))

evalf(eval(eval(eq, n=ans), [P=5,A=10,r=1/10,t=2]));

10. = 10.00000001

Download solve_ex2.mw

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...

First 74 75 76 77 78 79 80 Last Page 76 of 336