acer

32385 Reputation

29 Badges

19 years, 339 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You can use the view option to set the vertical range (or both horizontal and vertical ranges). You can use that with the plot and the implicitplot commands. For implicitplot there is also a convenient rangeasview option which forces the view to match the supplied ranges.

restart;
with(plots):

a,b:=7/10,0.2:

implicitplot(y=a*x+b, x=-10..10, y=-10..10,
             axis=[gridlines=[10,color=blue]],
             rangeasview);

implicitplot(y=a*x+b, x=-10..10, y=-10..10,
             axis=[gridlines=[10,color=blue]],
             view=[-10..10,-10..10]);

plot(a*x+b, x=-10..10, view=[-10..10,-10..10],
     axis=[gridlines=[10,color=blue]]);

plot(a*x+b, x=-10..10, view=[default,-10..10],
     axis=[gridlines=[10,color=blue]]);

plot(a*x+b, x=-10..10, view=-10..10,
     axis=[gridlines=[10,color=blue]]);

I suspect that the sky would not necessarily fall down if the Maple kernel developers allowed symbolic Matrix indexing to not throw an error.

restart

 

First, using a Matrix (capitalized), which we happen to
construct from the palette (but that aspect is not central).

 

m := Matrix(2, 2, {(1, 1) = 1, (1, 2) = 3, (2, 1) = 2, (2, 2) = 4})

Matrix(%id = 18446883814761169974)

b := m[a, 1]

Error, bad index into Matrix

b := 'm[a, 1]'

m[a, 1]

a := 1

1

b

1

a := 2

2

b

2

 

Note that attempting to evaluate m[a,1] will throw an error
if a is unassigned. The uneval-quoted reference to m[a,1] can

be tricky thing to manage, as you have to guard against

unintended evaluation.

 

a := 'a'

a

b

Error, bad index into Matrix

restart

 

Next, using a table-based matrix (uncapitalized).

Notice that the indexed reference m[a,1] does not produce an error
even when a is unassigned.

 

m := matrix(2, 2, [1, 3, 2, 4])

array( 1 .. 2, 1 .. 2, [( 1, 1 ) = (1), ( 1, 2 ) = (3), ( 2, 1 ) = (2), ( 2, 2 ) = (4)  ] )

b := m[a, 1]

m[a, 1]

a := 1

1

b

1

a := 2

2

b

2

a := 'a'

a

b

m[a, 1]

 

Download matrix_ref.mw

First lets see that PolynomialFit can indeed produce a better result, if its svdtolerance option is set fine enough.

restart;

kernelopts(version);

`Maple 2019.2, X86 64 LINUX, Oct 30 2019, Build ID 1430966`

Rok := Vector([2013, 2014, 2015, 2016, 2017, 2018], datatype = float):
TrzbyCelkemEmco := Vector([1028155, 1134120, 1004758, 929584, 995716, 1152042], datatype = float):

W := sort(Statistics:-PolynomialFit(3, Rok, TrzbyCelkemEmco, x, svdtolerance=1e-20));

HFloat(17490.364890056557)*x^3-HFloat(1.0573703094228968e8)*x^2+HFloat(2.1307569435843292e11)*x-HFloat(1.4312624246619506e14)

p1:=plot(W,x=min(Rok)..max(Rok),color=blue):
p2:=plot(Rok,TrzbyCelkemEmco,style=point,symbol=solidcircle,symbolsize=15):
plots:-display(p1,p2,view=min(TrzbyCelkemEmco)..max(TrzbyCelkemEmco),size=[500,400]);

 

Download svdtol.mw

Next, let's examine why the rank determination under PolynomialFit may have numeric difficulties using defaults. And we can do the least-squares solving using LinearAlgebra and a suitable raised working precision (Digits).

And then, at end, we'll see that CurveFitting:-LeastSquares can also find a similar result if Digits is set higher.

restart;

Rok := Vector([2013, 2014, 2015, 2016, 2017, 2018], datatype = float):
TrzbyCelkemEmco := Vector([1028155, 1134120, 1004758, 929584, 995716, 1152042], datatype = float):

pol3:=a*x^3+b*x^2+c*x+d;

a*x^3+b*x^2+c*x+d

resid:=eval~(pol3,x=~Rok)-TrzbyCelkemEmco;

Vector(6, {(1) = 8157016197.*a+4052169.000*b+2013.0*c+d-1028155.000, (2) = 8169178744.*a+4056196.000*b+2014.0*c+d-1134120.000, (3) = 8181353375.*a+4060225.000*b+2015.0*c+d-1004758.000, (4) = 8193540096.*a+4064256.000*b+2016.0*c+d-929584.0000, (5) = 8205738913.*a+4068289.000*b+2017.0*c+d-995716.0000, (6) = 8217949832.*a+4072324.000*b+2018.0*c+d-1152042.000})

A,B:=LinearAlgebra:-GenerateMatrix(convert(resid,list),[a,b,c,d]);

A, B := Matrix(6, 4, {(1, 1) = 8157016197., (1, 2) = 4052169.000, (1, 3) = 2013., (1, 4) = 1, (2, 1) = 8169178744., (2, 2) = 4056196.000, (2, 3) = 2014., (2, 4) = 1, (3, 1) = 8181353375., (3, 2) = 4060225.000, (3, 3) = 2015., (3, 4) = 1, (4, 1) = 8193540096., (4, 2) = 4064256.000, (4, 3) = 2016., (4, 4) = 1, (5, 1) = 8205738913., (5, 2) = 4068289.000, (5, 3) = 2017., (5, 4) = 1, (6, 1) = 8217949832., (6, 2) = 4072324.000, (6, 3) = 2018., (6, 4) = 1}), Vector(6, {(1) = 1028155.000, (2) = 1134120.000, (3) = 1004758.000, (4) = 929584., (5) = 995716., (6) = 1152042.000})

svd:=LinearAlgebra:-SingularValues(A);

Vector(6, {(1) = 0.2005517356e11, (2) = 8431.40030424569, (3) = 0.30315542273334386e-2, (4) = 0.9831935525e-9, (5) = 0., (6) = 0.})

Digits:=1+ceil(log[10](svd[1]/svd[4]));

21

V:=LinearAlgebra:-LeastSquares(A,B,method='SVD');
L:=Equate([a,b,c,d],convert(V,list)):
UU:=eval(pol3,L);

Vector(4, {(1) = 17490.3611109121787648, (2) = -105737008.1, (3) = 0.2130756483e12, (4) = -0.1431262115e15})

17490.3611109121787648*x^3-105737008.082130186122*x^2+213075648264.510954728*x-143126211485817.832367

p1UU:=plot(UU,x=min(Rok)..max(Rok)):
p2:=plot(Rok,TrzbyCelkemEmco,color=blue):
plots:-display(p1UU,p2,view=min(TrzbyCelkemEmco)..max(TrzbyCelkemEmco));

# Compare with CurveFitting:-LeastSquares,
# done using Digits=20 and Digits=21.
#
Digits:=20;
U:=CurveFitting:-LeastSquares(Rok,TrzbyCelkemEmco,x,curve=pol3);
p1U:=plot(U,x=min(Rok)..max(Rok)):
p2:=plot(Rok,TrzbyCelkemEmco,color=blue):
plots:-display(p1U,p2,view=min(TrzbyCelkemEmco)..max(TrzbyCelkemEmco));

20

55417.578996418964626+37231332.937900379590*x-36946.127657452668301*x^2+9.1658905419567079826*x^3

Digits:=21;
U:=CurveFitting:-LeastSquares(Rok,TrzbyCelkemEmco,x,curve=pol3);
p1U:=plot(U,x=min(Rok)..max(Rok)):
p2:=plot(Rok,TrzbyCelkemEmco,color=blue):
plots:-display(p1U,p2,view=min(TrzbyCelkemEmco)..max(TrzbyCelkemEmco));

21

-143126211486530.025986+213075648265.589385689*x-105737008.082662396656*x^2+17490.3611109998946169*x^3

sort(U);
sort(UU);

17490.3611109998946169*x^3-105737008.082662396656*x^2+213075648265.589385689*x-143126211486530.025986

17490.3611109121787648*x^3-105737008.082130186122*x^2+213075648264.510954728*x-143126211485817.832367

 

Download svd_fit.mw

The behavior which you describe with the "yyyyy" characters is its being rendered in italics, because the following space indicates to the parser that the preceding yyyyy is a name.

You can disable that behavior of rendering input variable names in italics in the CLI by issuing the command,
    interface(ansiedit=false):

But note that doing so will disable some colorizing of input, which is on by default.

See the ?interface Help page.

With a differently simplified form of the chareq expression (using Maple 18.02). The form of U2 below is quite a bit more compact, although I did not stress test any of the forms for the degree of susceptibility to numeric roundoff error in any range of En.

I had just finished writing this when I saw that dharr had submitted a second answer, also with a suggestion about NextZero (although, used with care, Calculus1:-Roots can also find more). I suppose a third Answer doesn't hurt.

restart

V0 := 1;

1

a := 2;

2

b := 1;

1

ks := sqrt(2*En);

2^(1/2)*En^(1/2)

qs := sqrt(2*(V0-En));

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

psi11 := proc (x) options operator, arrow; A1*exp(qs*x)+B1*exp(-qs*x) end proc

proc (x) options operator, arrow; A1*exp(qs*x)+B1*exp(-qs*x) end proc

psi21 := proc (x) options operator, arrow; A2*exp(I*ks*x)+B2*exp(-I*ks*x) end proc

proc (x) options operator, arrow; A2*exp(I*ks*x)+B2*exp(-I*ks*x) end proc

lp := a+b

3

psi12 := proc (x) options operator, arrow; exp(I*Kp*lp)*(A1*exp(qs*(x-lp))+B1*exp(-qs*(x-lp))) end proc

proc (x) options operator, arrow; exp(I*Kp*lp)*(A1*exp(qs*(x-lp))+B1*exp(-qs*(x-lp))) end proc

psi22 := proc (x) options operator, arrow; exp(I*Kp*lp)*(A2*exp(I*ks*(x-lp))+B2*exp(-I*ks*(x-lp))) end proc

proc (x) options operator, arrow; exp(I*Kp*lp)*(A2*exp(I*ks*(x-lp))+B2*exp(-I*ks*(x-lp))) end proc

eq1 := psi11(0) = psi21(0)

A1+B1 = A2+B2

eq2 := (D(psi11))(0) = (D(psi21))(0)

A1*(2-2*En)^(1/2)-B1*(2-2*En)^(1/2) = I*A2*2^(1/2)*En^(1/2)-I*B2*2^(1/2)*En^(1/2)

eq3 := psi21(a) = psi12(a)

A2*exp((2*I)*2^(1/2)*En^(1/2))+B2*exp(-(2*I)*2^(1/2)*En^(1/2)) = exp((3*I)*Kp)*(A1*exp(-(2-2*En)^(1/2))+B1*exp((2-2*En)^(1/2)))

eq4 := (D(psi21))(a) = (D(psi12))(a)

I*A2*2^(1/2)*En^(1/2)*exp((2*I)*2^(1/2)*En^(1/2))-I*B2*2^(1/2)*En^(1/2)*exp(-(2*I)*2^(1/2)*En^(1/2)) = exp((3*I)*Kp)*(A1*(2-2*En)^(1/2)*exp(-(2-2*En)^(1/2))-B1*(2-2*En)^(1/2)*exp((2-2*En)^(1/2)))

solve({eq1, eq2, eq3, eq4}, {A1, A2, B1, B2});

{A1 = 0, A2 = 0, B1 = 0, B2 = 0}

with(linalg):

row1 := vector([1, 1, -1, -1])

array( 1 .. 4, [( 1 ) = (1), ( 2 ) = (1), ( 3 ) = (-1), ( 4 ) = (-1)  ] )

row2 := vector([coeff((lhs-rhs)(eq2), A1), coeff((lhs-rhs)(eq2), B1), coeff((lhs-rhs)(eq2), A2), coeff((lhs-rhs)(eq2), B2)])

array( 1 .. 4, [( 1 ) = ((2-2*En)^(1/2)), ( 2 ) = (-(2-2*En)^(1/2)), ( 3 ) = (-I*2^(1/2)*En^(1/2)), ( 4 ) = (I*2^(1/2)*En^(1/2))  ] )

row3 := vector([coeff((lhs-rhs)(eq3), A1), coeff((lhs-rhs)(eq3), B1), coeff((lhs-rhs)(eq3), A2), coeff((lhs-rhs)(eq3), B2)])

array( 1 .. 4, [( 1 ) = (-exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))), ( 2 ) = (-exp((2-2*En)^(1/2))*exp((3*I)*Kp)), ( 3 ) = (exp((2*I)*2^(1/2)*En^(1/2))), ( 4 ) = (exp(-(2*I)*2^(1/2)*En^(1/2)))  ] )

row4 := vector([coeff((lhs-rhs)(eq4), A1), coeff((lhs-rhs)(eq4), B1), coeff((lhs-rhs)(eq4), A2), coeff((lhs-rhs)(eq4), B2)])

array( 1 .. 4, [( 1 ) = (-exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))*(2-2*En)^(1/2)), ( 2 ) = (exp((2-2*En)^(1/2))*exp((3*I)*Kp)*(2-2*En)^(1/2)), ( 3 ) = (I*2^(1/2)*En^(1/2)*exp((2*I)*2^(1/2)*En^(1/2))), ( 4 ) = (-I*2^(1/2)*En^(1/2)*exp(-(2*I)*2^(1/2)*En^(1/2)))  ] )

C := matrix(4, 4, 0)

array( 1 .. 4, 1 .. 4, [( 1, 2 ) = (0), ( 4, 2 ) = (0), ( 2, 2 ) = (0), ( 2, 1 ) = (0), ( 3, 4 ) = (0), ( 3, 1 ) = (0), ( 2, 3 ) = (0), ( 4, 4 ) = (0), ( 1, 4 ) = (0), ( 3, 2 ) = (0), ( 2, 4 ) = (0), ( 3, 3 ) = (0), ( 1, 1 ) = (0), ( 4, 1 ) = (0), ( 1, 3 ) = (0), ( 4, 3 ) = (0)  ] )

for i to 4 do C[1, i] := row1[i]; C[2, i] := row2[i]; C[3, i] := row3[i]; C[4, i] := row4[i] end do:

evalm(C)

array( 1 .. 4, 1 .. 4, [( 1, 2 ) = (1), ( 4, 2 ) = (exp((2-2*En)^(1/2))*exp((3*I)*Kp)*(2-2*En)^(1/2)), ( 2, 2 ) = (-(2-2*En)^(1/2)), ( 2, 1 ) = ((2-2*En)^(1/2)), ( 3, 4 ) = (exp(-(2*I)*2^(1/2)*En^(1/2))), ( 3, 1 ) = (-exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))), ( 2, 3 ) = (-I*2^(1/2)*En^(1/2)), ( 4, 4 ) = (-I*2^(1/2)*En^(1/2)*exp(-(2*I)*2^(1/2)*En^(1/2))), ( 1, 4 ) = (-1), ( 3, 2 ) = (-exp((2-2*En)^(1/2))*exp((3*I)*Kp)), ( 2, 4 ) = (I*2^(1/2)*En^(1/2)), ( 3, 3 ) = (exp((2*I)*2^(1/2)*En^(1/2))), ( 1, 1 ) = (1), ( 4, 1 ) = (-exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))*(2-2*En)^(1/2)), ( 1, 3 ) = (-1), ( 4, 3 ) = (I*2^(1/2)*En^(1/2)*exp((2*I)*2^(1/2)*En^(1/2)))  ] )

chareq := det(C);

(4*I)*2^(1/2)*exp((2-2*En)^(1/2))*(exp((3*I)*Kp))^2*exp(-(2-2*En)^(1/2))*(2-2*En)^(1/2)*En^(1/2)-(2*I)*2^(1/2)*exp(-(2*I)*2^(1/2)*En^(1/2))*exp((2-2*En)^(1/2))*exp((3*I)*Kp)*(2-2*En)^(1/2)*En^(1/2)-(2*I)*2^(1/2)*exp(-(2*I)*2^(1/2)*En^(1/2))*exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))*(2-2*En)^(1/2)*En^(1/2)-(2*I)*2^(1/2)*exp((2*I)*2^(1/2)*En^(1/2))*exp((2-2*En)^(1/2))*exp((3*I)*Kp)*(2-2*En)^(1/2)*En^(1/2)-(2*I)*2^(1/2)*exp((2*I)*2^(1/2)*En^(1/2))*exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))*(2-2*En)^(1/2)*En^(1/2)+(4*I)*(2-2*En)^(1/2)*exp((2*I)*2^(1/2)*En^(1/2))*2^(1/2)*En^(1/2)*exp(-(2*I)*2^(1/2)*En^(1/2))-4*En*exp(-(2*I)*2^(1/2)*En^(1/2))*exp((2-2*En)^(1/2))*exp((3*I)*Kp)+4*En*exp(-(2*I)*2^(1/2)*En^(1/2))*exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))+4*En*exp((2*I)*2^(1/2)*En^(1/2))*exp((2-2*En)^(1/2))*exp((3*I)*Kp)-4*En*exp((2*I)*2^(1/2)*En^(1/2))*exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))+2*exp(-(2*I)*2^(1/2)*En^(1/2))*exp((2-2*En)^(1/2))*exp((3*I)*Kp)-2*exp(-(2*I)*2^(1/2)*En^(1/2))*exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))-2*exp((2*I)*2^(1/2)*En^(1/2))*exp((2-2*En)^(1/2))*exp((3*I)*Kp)+2*exp((2*I)*2^(1/2)*En^(1/2))*exp((3*I)*Kp)*exp(-(2-2*En)^(1/2))

U1 := `assuming`([simplify(combine(evalc(eval(chareq, Kp = 0))))], [En > 0, En < 1]);

(4*I)*(-2*cos(2*2^(1/2)*En^(1/2))*exp(2*(2-2*En)^(1/2))*(1-En)^(1/2)*En^(1/2)+2*En*sin(2*2^(1/2)*En^(1/2))*exp(2*(2-2*En)^(1/2))-2*cos(2*2^(1/2)*En^(1/2))*(1-En)^(1/2)*En^(1/2)+4*(1-En)^(1/2)*En^(1/2)*exp((2-2*En)^(1/2))-sin(2*2^(1/2)*En^(1/2))*exp(2*(2-2*En)^(1/2))-2*En*sin(2*2^(1/2)*En^(1/2))+sin(2*2^(1/2)*En^(1/2)))*exp(-(2-2*En)^(1/2))

U1 := `assuming`([collect(simplify(simplify(combine(evalc(eval(chareq, Kp = 0)))), size), [exp, sin, cos], proc (u) options operator, arrow; simplify(simplify(combine(u)), size) end proc)], [En > 0, En < 1]);

(16*I)*(1-En)^(1/2)*En^(1/2)*exp(-(2-2*En)^(1/2))*exp((2-2*En)^(1/2))+(((-4*I+(8*I)*En)*sin(2*2^(1/2)*En^(1/2))-(8*I)*(1-En)^(1/2)*cos(2*2^(1/2)*En^(1/2))*En^(1/2))*exp(2*(2-2*En)^(1/2))+(4*I-(8*I)*En)*sin(2*2^(1/2)*En^(1/2))-(8*I)*(1-En)^(1/2)*cos(2*2^(1/2)*En^(1/2))*En^(1/2))*exp(-(2-2*En)^(1/2))

Student:-Calculus1:-Roots(U1, En = 0 .. 1, numeric);

[0., .2669813621]

plot(([Re, Im])(U1), En = 0. .. 1.0, view = -20 .. 20, style = [line, point], thickness = 5, color = [red, blue]);

fImU1 := unapply(Im(U1), En):

.2669813620

U2 := `assuming`([simplify(combine(evalc(eval(chareq, Kp = 0))))], [En > 1]);

8*(-1+En)^(1/2)*En^(1/2)*cos(2*2^(1/2)*En^(1/2)-(-2+2*En)^(1/2))+8*(-1+En)^(1/2)*En^(1/2)*cos(2*2^(1/2)*En^(1/2)+(-2+2*En)^(1/2))-8*En*cos(2*2^(1/2)*En^(1/2)-(-2+2*En)^(1/2))+8*En*cos(2*2^(1/2)*En^(1/2)+(-2+2*En)^(1/2))+4*cos(2*2^(1/2)*En^(1/2)-(-2+2*En)^(1/2))-4*cos(2*2^(1/2)*En^(1/2)+(-2+2*En)^(1/2))-16*(-1+En)^(1/2)*En^(1/2)

U2 := `assuming`([collect(simplify(simplify(combine(evalc(eval(chareq, Kp = 0)))), size), [exp, sin, cos], proc (u) options operator, arrow; simplify(simplify(combine(u)), size) end proc)], [En > 1]);

(8*(-1+En)^(1/2)*En^(1/2)-8*En+4)*cos(2*2^(1/2)*En^(1/2)-(-2+2*En)^(1/2))+(8*(-1+En)^(1/2)*En^(1/2)+8*En-4)*cos(2*2^(1/2)*En^(1/2)+(-2+2*En)^(1/2))-16*(-1+En)^(1/2)*En^(1/2)

Student:-Calculus1:-Roots(U2, En = 1 .. 20, numeric);

[2.375133245, 2.712788471, 9.049238832, 9.174900984]

fU2 := unapply(U2, En):

2.375133244

2.712788471

9.049238831

9.174900983

Digits := 200:

plot(U2, En = 1 .. 1000, size = [600, 300]);

 

Download qm_maple_-_periodic_potentials_acc.mw

Two ways, using a symbolic option (instead of assumptions):

restart;

kernelopts(version);

`Maple 2019.2, X86 64 LINUX, Nov 26 2019, Build ID 1435526`

combine(exp(k*(ln(t) + ln(a))) - exp(ln(t) + ln(a))^k, symbolic);
simplify(%);

exp(k*ln(t*a))-(t*a)^k

0

expand(exp(k*(ln(t) + ln(a))) - exp(ln(t) + ln(a))^k);
simplify(%,symbolic);

t^k*a^k-(t*a)^k

0

 

NULL

Download symbolic_ac.mw

It should probably emit an error if method=_MonteCarlo is forced and epsilon is supplied smaller than the method supports. And perhaps it should emit a Warning and bump up the tolerance if that method alone is supplied.

But I don't understand your initial statement, "...all the others seem to fail". Your example works even if no method or options are supplied.

Do you understand that forcing method=_CubaVegas may also fail at default options but succeed at others? It works for me using epsilon=1e-4. See the Help pages for additional details on suboptions, ie, ?evalf,int,cuba

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Linux, December 21 2015 Build ID 1097895`

int(cos(x*y), [x=-1..3, y=-1..-1/5]);
evalf[15](%);

Si(3)+Si(1)-Si(3/5)-Si(1/5)

2.00705070023234

CodeTools:-Usage( evalf(Int(cos(x*y), [x=-1..3, y=-1..-0.2])) );

memory used=158.95KiB, alloc change=32.00MiB, cpu time=15.00ms, real time=16.00ms, gc time=0ns

2.007050700

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_Gquad)) );

memory used=0.84MiB, alloc change=0 bytes, cpu time=10.00ms, real time=13.00ms, gc time=0ns

2.007050700

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_CubaVegas)) );

memory used=43.17KiB, alloc change=0 bytes, cpu time=12.28s, real time=12.28s, gc time=0ns

Int(Int(cos(x*y), x = -1. .. 3.), y = -1. .. -.2)

CodeTools:-Usage( evalf(Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_MonteCarlo, epsilon=5e-5)) );

memory used=30.62KiB, alloc change=0 bytes, cpu time=2.00ms, real time=2.00ms, gc time=0ns

2.007013766

infolevel[`evalf/int`]:=2:
forget(`evalf/int`);
CodeTools:-Usage( evalf(Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_MonteCarlo, epsilon=1e-5)) );
infolevel[`evalf/int`]:=0;

Control_multi: integrating on [-1, -1] .. [3, -.2] the integrand

cos(x*y)

evalf/int: error from Control_multi was:
"NAG d01gbc expects epsilon >= 0.5e-4, but received %1", .1e-4
memory used=212.05KiB, alloc change=0 bytes, cpu time=2.00ms, real time=7.00ms, gc time=0ns

Int(Int(cos(x*y), x = -1. .. 3.), y = -1. .. -.2)

0

 

Download evalf_Int_ac.mw

 

restart;

kernelopts(version);

`Maple 2017.2, X86 64 LINUX, Jul 19 2017, Build ID 1247392`

# current value
kernelopts(stacklimit);

8160

# output the previous value
kernelopts(stacklimit=2^15);

8160

# current value
kernelopts(stacklimit);

32768

 

Download stacklimit.mw

L := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:

[seq(L[2*i-1]..L[2*i],i=1..nops(L)/2)];

        [1 .. 2, 3 .. 4, 5 .. 6, 7 .. 8, 9 .. 10]

I don't see how your question makes it clear whether you want the braces or their contents to be colored. So I have to guess. I guess it's the contents. (If it's the brackets -- or both -- then I don't see that you've sensibly described how to color it.)

It's not clear exactly how you want the colors "tweaked" with each iteration. But you might adjust this to taste:

restart;

F := proc(n, c::list:=[0,0,0])
    local i,k:
    uses Typesetting, ColorTools;
    if n <= 0 then return mn("1",
                             ':-mathcolor'=RGB24ToHex(RGBToRGB24(c)),
                             ':-size'="16",
                             ':-fontweight'="bold");
    end if:
    F(n-2, (c+(n)*[1,0,0])/(n+1)) %+ F(n-1, (c+(n)*[0,1,0])/(n+1)):
end proc:

F(1);

Parse:-ConvertTo1D, "invalid input %1", `%+`(Typesetting:-mn("1", mathcolor = "#800000", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#008000", size = "16", fontweight = "bold"))

F(2);

Parse:-ConvertTo1D, "invalid input %1", `%+`(Typesetting:-mn("1", mathcolor = "#AA0000", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#805500", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#00D500", size = "16", fontweight = "bold")))

F(3);

Parse:-ConvertTo1D, "invalid input %1", `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#DF0000", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#608000", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#AA4000", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#807500", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#00F400", size = "16", fontweight = "bold"))))

F(4);

Parse:-ConvertTo1D, "invalid input %1", `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#EE0000", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#A25500", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#22D500", size = "16", fontweight = "bold"))), `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#DF1A00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#609900", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#AA5100", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#807D00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#00FD00", size = "16", fontweight = "bold")))))

F(5);

Parse:-ConvertTo1D, "invalid input %1", `%+`(`%+`(`%+`(Typesetting:-mn("1", mathcolor = "#FA0000", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#7A8000", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#BC4000", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#887500", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#09F400", size = "16", fontweight = "bold")))), `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#EE0E00", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#A25C00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#22DC00", size = "16", fontweight = "bold"))), `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#DF1F00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#609E00", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#AA5400", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#807F00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#00FF00", size = "16", fontweight = "bold"))))))

F(6);

Parse:-ConvertTo1D, "invalid input %1", `%+`(`%+`(`%+`(Typesetting:-mn("1", mathcolor = "#FD0000", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#A95500", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#29D500", size = "16", fontweight = "bold"))), `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#E51A00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#659900", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#AE5100", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#817D00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#02FD00", size = "16", fontweight = "bold"))))), `%+`(`%+`(`%+`(Typesetting:-mn("1", mathcolor = "#FA0500", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#7A8400", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#BC4300", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#887600", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#09F600", size = "16", fontweight = "bold")))), `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#EE1100", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#A25D00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#22DD00", size = "16", fontweight = "bold"))), `%+`(`%+`(Typesetting:-mn("1", mathcolor = "#DF2000", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#609F00", size = "16", fontweight = "bold")), `%+`(Typesetting:-mn("1", mathcolor = "#AA5500", size = "16", fontweight = "bold"), `%+`(Typesetting:-mn("1", mathcolor = "#807F00", size = "16", fontweight = "bold"), Typesetting:-mn("1", mathcolor = "#00FF00", size = "16", fontweight = "bold")))))))

 

This is somewhat fragile, depending on what you typeset and how.

 

value(subsindets(F(6),specfunc(Typesetting:-mn),
      u->op(2..,Typesetting:-Parse(u))));

21

 

Download color_recur.mw

[edit] Transitioning from color to color can be a subtle business. You might prefer the "Lab" colorspace rather than "RGB" since the former grades perceptually evenly (RGB runs evenly in terms of the monitor output, not perceptually). Two colors whose midpoint isn't some gray near the white point may also be nicer. Just let me know.

Also, the braces can be colored, but if that's desired then I'm not understanding the target details.

You can use the command evalf to compute that single floating-point arctrig call.

evalf[15](arccos(0.62))

             0.902053623592525

The command factor can be used to factor this polynomial.

p := x^5-11*x^4+27*x^3+67*x^2-320*x+300:

factor(p)

                       2        2
        (x + 3) (x - 2)  (x - 5) 

Are you trying to compute approximations of only the real roots, or also complex roots?

You still haven't shown your larger example where computation takes too long. is it a polynomial sysyem?

How much accuracy do you want?

The eliminate command can (fortuitously) be used to see that d[1] also has a special value. And c[0] and d[0] can be recognized by the trivial eq[7] and eq[8]. But RootFinding:-Isolate would also find the real solutions without that finesse.

There are various other possible apporaches (using calls to solve, eliminate, evalf, etc). But if you are only looking for the real roots of a polynomial system with exact coefficient then Isolate has the advantage of attaining a target accuracy without so much fuss over having to raise working precision to avoid roundoff error.

restart;

eq[1] := -3*c[0]+3*c[1] = c[0]*(1-259*d[0]*(1/192)+43*d[1]*(1/64)-11*d[2]*(1/64)+(1/64)*d[3])-23/6:
eq[2] := -3*d[0]+3*d[1] = d[0]*(-2+23*c[0]*(1/80)+139*c[1]*(1/320)-17*c[2]*(1/160)+3*c[3]*(1/320))-1:
eq[3] := -4*c[0]*(1/3)+c[2]+(1/3)*c[3] = (8*c[0]*(1/27)+4*c[1]*(1/9)+2*c[2]*(1/9)+(1/27)*c[3])*(1-2657*d[0]*(1/5184)-343*d[1]*(1/1728)-185*d[2]*(1/1728)-79*d[3]*(1/5184))-3:
eq[4] := -4*d[0]*(1/3)+d[2]+(1/3)*d[3] = (8*d[0]*(1/27)+4*d[1]*(1/9)+2*d[2]*(1/9)+(1/27)*d[3])*(-2+109*c[0]*(1/8640)+553*c[1]*(1/1440)+559*c[2]*(1/2880)+37*c[3]*(1/1080))-5/6:
eq[5] := -(1/3)*c[0]-c[1]+4*c[3]*(1/3) = ((1/27)*c[0]+2*c[1]*(1/9)+4*c[2]*(1/9)+8*c[3]*(1/27))*(1-673*d[0]*(1/5184)-455*d[1]*(1/1728)-505*d[2]*(1/1728)-767*d[3]*(1/5184))-49/27:
eq[6] := -(1/3)*d[0]-d[1]+4*d[3]*(1/3) = ((1/27)*d[0]+2*d[1]*(1/9)+4*d[2]*(1/9)+8*d[3]*(1/27))*(-2-173*c[0]*(1/4320)+241*c[1]*(1/2880)+59*c[2]*(1/180)+2191*c[3]*(1/8640))-11/36:
eq[7] := c[0] = 1:
eq[8] := d[0] = 0:

 

evars := {c[0],d[1],d[0]};
new := eliminate({seq(eq[i],i=1..8)},evars);
specvals:=new[1];
newsys:=new[2];
newvars:=[op(indets(newsys,name) minus evars)]

{c[0], d[0], d[1]}

[{c[0] = 1, d[0] = 0, d[1] = -1/3}, {576*c[1]+11+33*d[2]-3*d[3], 4338*c[1]*d[2]+2892*c[1]*d[3]+16992*c[2]*d[2]+11328*c[2]*d[3]+13146*c[3]*d[2]+8764*c[3]*d[3]-723*c[1]-2832*c[2]-2191*c[3]-105756*d[2]-226024*d[3]-56894, 6660*c[1]*d[2]+948*c[1]*d[3]+3330*c[2]*d[2]+474*c[2]*d[3]+555*c[3]*d[2]+79*c[3]*d[3]-66324*c[1]+106806*c[2]+41129*c[3]+4440*d[2]+632*d[3]+189064, 9090*c[1]*d[2]+4602*c[1]*d[3]+18180*c[2]*d[2]+9204*c[2]*d[3]+12120*c[3]*d[2]+6136*c[3]*d[3]-173802*c[1]-67668*c[2]+141512*c[3]+1515*d[2]+767*d[3]+201721, 19908*c[1]*d[2]+3318*c[1]*d[3]+10062*c[2]*d[2]+1677*c[2]*d[3]+1776*c[3]*d[2]+296*c[3]*d[3]-13272*c[1]-6708*c[2]-1184*c[3]-336306*d[2]-94931*d[3]-125716}]

{c[0] = 1, d[0] = 0, d[1] = -1/3}

{576*c[1]+11+33*d[2]-3*d[3], 4338*c[1]*d[2]+2892*c[1]*d[3]+16992*c[2]*d[2]+11328*c[2]*d[3]+13146*c[3]*d[2]+8764*c[3]*d[3]-723*c[1]-2832*c[2]-2191*c[3]-105756*d[2]-226024*d[3]-56894, 6660*c[1]*d[2]+948*c[1]*d[3]+3330*c[2]*d[2]+474*c[2]*d[3]+555*c[3]*d[2]+79*c[3]*d[3]-66324*c[1]+106806*c[2]+41129*c[3]+4440*d[2]+632*d[3]+189064, 9090*c[1]*d[2]+4602*c[1]*d[3]+18180*c[2]*d[2]+9204*c[2]*d[3]+12120*c[3]*d[2]+6136*c[3]*d[3]-173802*c[1]-67668*c[2]+141512*c[3]+1515*d[2]+767*d[3]+201721, 19908*c[1]*d[2]+3318*c[1]*d[3]+10062*c[2]*d[2]+1677*c[2]*d[3]+1776*c[3]*d[2]+296*c[3]*d[3]-13272*c[1]-6708*c[2]-1184*c[3]-336306*d[2]-94931*d[3]-125716}

[c[1], c[2], c[3], d[2], d[3]]

 

Solnew := RootFinding:-Isolate(newsys,newvars,digits=25):
nops(Solnew);
map(print@evalf[5],Solnew):
Rnew:=[seq(evalf[25](eval(newsys,s)),s=Solnew)]:
seq([i,(max@op)(abs~(Rnew[i]))],i=1..nops(Rnew));

8

[c[1] = -2.3306, c[2] = -22.900, c[3] = 66.253, d[2] = 29.421, d[3] = -120.18]

[c[1] = 0., c[2] = -1., c[3] = -2., d[2] = -.33333, d[3] = 0.]

[c[1] = 6.2559, c[2] = -25.023, c[3] = 207.60, d[2] = -95.022, d[3] = 159.56]

[c[1] = 9.1174, c[2] = -371.93, c[3] = 510.06, d[2] = -105.71, d[3] = 591.42]

[c[1] = 371.76, c[2] = -945.22, c[3] = 1136.0, d[2] = -4795.7, d[3] = 18630.]

[c[1] = 779.33, c[2] = -1730.0, c[3] = 2009.3, d[2] = -8192.4, d[3] = 59520.]

[c[1] = 3922.0, c[2] = -9816.4, c[3] = 11794., d[2] = -59902., d[3] = 94114.]

[c[1] = 4131.4, c[2] = -10268., c[3] = 11989., d[2] = -61067., d[3] = 0.12149e6]

[1, 0.375e-16], [2, 0.1e-20], [3, 0.1561e-15], [4, 0.86e-15], [5, 0.4e-13], [6, 0.3e-12], [7, 0.37e-11], [8, 0.818e-11]

Solnew;

[[c[1] = -2.330639949724738343595716, c[2] = -22.89982197238880713869523, c[3] = 66.25310856709412628545785, d[2] = 29.42142564084380129840955, d[3] = -120.1805216312012810212058], [c[1] = 0., c[2] = -1., c[3] = -2., d[2] = -.3333333333333333333333333, d[3] = 0.], [c[1] = 6.255927282038413380435825, c[2] = -25.02271769693028720860972, c[3] = 207.5971290707517134952033, d[2] = -95.02218904239454035739991, d[3] = 159.5606253517020917789461], [c[1] = 9.117361146634459023171301, c[2] = -371.9293025401432341913410, c[3] = 510.0565426353267608425015, d[2] = -105.7073276505637045189833, d[3] = 591.4194026642820494067401], [c[1] = 371.7635884642179771452827, c[2] = -945.2237683753527116079604, c[3] = 1136.034971220020243070197, d[2] = -4795.651786369653511157575, d[3] = 18630.10600173032965582763], [c[1] = 779.3348107669203714939377, c[2] = -1729.971889940637220732631, c[3] = 2009.330823610934201173010, d[2] = -8192.404076947565715736100, d[3] = 59519.50548749215512040560], [c[1] = 3922.030291239845500202869, c[2] = -9816.385589616708397183330, c[3] = 11794.05189113569212529481, d[2] = -59901.78175819962660063243, d[3] = 94113.88324452111009866092], [c[1] = 4131.379895585846677049795, c[2] = -10268.33219677264457867323, c[3] = 11989.31825704926459215125, d[2] = -61067.24168520026862839832, d[3] = 121488.9480819462737478459]]

#RootFinding:-Isolate(newsys,newvars,output=interval;

 

Complex solutions

 

Digits:=25;

25

Sol2:=[solve(newsys,explicit,allsolutions)]:
nops(Sol2);

10

F2:=evalf[100](Sol2):
F2:=evalf(F2):
map(print@evalf[5],F2):
R2:=[seq(eval(newsys,[s[],specvals[]]),s=F2)]:
seq([i,(max@op)(abs~(R2[i]))],i=1..nops(R2));

{c[1] = 0., c[2] = -1., c[3] = -2., d[2] = -.33333, d[3] = 0.}

{c[1] = -2.3306, c[2] = -22.900, c[3] = 66.253, d[2] = 29.421, d[3] = -120.18}

{c[1] = 1.9664-.53923*I, c[2] = 25.504+4.4859*I, c[3] = -17.994-44.772*I, d[2] = -30.377+9.9872*I, d[3] = 47.070+6.3277*I}

{c[1] = 6.2559, c[2] = -25.023, c[3] = 207.60, d[2] = -95.022, d[3] = 159.56}

{c[1] = 9.1174, c[2] = -371.93, c[3] = 510.06, d[2] = -105.71, d[3] = 591.42}

{c[1] = 371.76, c[2] = -945.22, c[3] = 1136.0, d[2] = -4795.7, d[3] = 18630.}

{c[1] = 779.33, c[2] = -1730.0, c[3] = 2009.3, d[2] = -8192.4, d[3] = 59520.}

{c[1] = 3922.0, c[2] = -9816.4, c[3] = 11794., d[2] = -59902., d[3] = 94114.}

{c[1] = 4131.4, c[2] = -10268., c[3] = 11989., d[2] = -61067., d[3] = 0.12149e6}

{c[1] = 1.9664+.53923*I, c[2] = 25.504-4.4859*I, c[3] = -17.994+44.772*I, d[2] = -30.377-9.9872*I, d[3] = 47.070-6.3277*I}

[1, 0.1e-20], [2, 0.375e-16], [3, 0.7e-17], [4, 0.1561e-15], [5, 0.86e-15], [6, 0.4e-13], [7, 0.3e-12], [8, 0.37e-11], [9, 0.818e-11], [10, 0.7e-17]

F2;

[{c[1] = 0., c[2] = -1., c[3] = -2., d[2] = -.3333333333333333333333333, d[3] = 0.}, {c[1] = -2.330639949724738343595716, c[2] = -22.89982197238880713869523, c[3] = 66.25310856709412628545785, d[2] = 29.42142564084380129840955, d[3] = -120.1805216312012810212058}, {c[1] = 1.966382890860046002901190-.5392254859538496928610527*I, c[2] = 25.50351374246731635537461+4.485878800516206959178223*I, c[3] = -17.99357494982858498521487-44.77206000855391465107483*I, d[2] = -30.37657950249959283154526+9.987184666310217030202304*I, d[3] = 47.06980718429997807669723+6.327738026273246302903227*I}, {c[1] = 6.255927282038413380435825, c[2] = -25.02271769693028720860972, c[3] = 207.5971290707517134952033, d[2] = -95.02218904239454035739991, d[3] = 159.5606253517020917789461}, {c[1] = 9.117361146634459023171301, c[2] = -371.9293025401432341913410, c[3] = 510.0565426353267608425015, d[2] = -105.7073276505637045189833, d[3] = 591.4194026642820494067401}, {c[1] = 371.7635884642179771452827, c[2] = -945.2237683753527116079604, c[3] = 1136.034971220020243070197, d[2] = -4795.651786369653511157575, d[3] = 18630.10600173032965582763}, {c[1] = 779.3348107669203714939377, c[2] = -1729.971889940637220732631, c[3] = 2009.330823610934201173010, d[2] = -8192.404076947565715736100, d[3] = 59519.50548749215512040560}, {c[1] = 3922.030291239845500202869, c[2] = -9816.385589616708397183330, c[3] = 11794.05189113569212529481, d[2] = -59901.78175819962660063243, d[3] = 94113.88324452111009866092}, {c[1] = 4131.379895585846677049795, c[2] = -10268.33219677264457867323, c[3] = 11989.31825704926459215125, d[2] = -61067.24168520026862839832, d[3] = 121488.9480819462737478459}, {c[1] = 1.966382890860046002901190+.5392254859538496928610527*I, c[2] = 25.50351374246731635537461-4.485878800516206959178223*I, c[3] = -17.99357494982858498521487+44.77206000855391465107483*I, d[2] = -30.37657950249959283154526-9.987184666310217030202304*I, d[3] = 47.06980718429997807669723-6.327738026273246302903227*I}]

 

Download poly_system.mw

So, you have four different instances of the pair of tables Beams and Beams2?

Why not store them with one more (cheap) layer of indirection? That is to say, have four differently named parent tables (eg, BeamsTable[1], BeamsTable[2], ...) each of which contains their own distinct pair?

BeamsTable[1][Beams] is one, from a pair
BeamsTable[1][Beams2] is the other, from that pair

Or you could name the distinct parents BeamsTable1BeamsTable2, etc. That could mean slightly less effort in storing them, with completely separate calls.

You don't even need to use different .mla files. You could utilize just one.

One of the points I tried to convey in my response to your previous (related) question is that you need to manage the global namespace of your Maple sessions. I likely was not clear enough about that. It should be done through deliberately assigned names (in Maple), and not attempted as a byproduct of external filenames/locations.

Saying it another way: don't store different things under identical names in .mla files if you want to retrieve them as distinct things. Trying to leverage the file system for that (provided that you don't need more than one distinct access per restart) could be accomplished, but it's really not a good way to go about it. And more general access (within restart) is going to present some near-impossible scenarios.

nb. In your earlier thread I did not mention storing in plaintext (input Maple notation), because I assumed that you would not want any solution which incurred the overhead of reparsing the language input code -- per session.

What precisely do you mean? You haven't given any example to illustrate. The LinearAlgebra:-Eigenvectors command already returns both vectors and values, so you must mean something else. I will guess.

Are you trying to say that you like the syntax where the number of computed and returned objects depends on the number of entries in the sequence on the left-hand side of the assignment statement? That is, where the particular computation (with the same right-hand side of the statement) varies according to whether the assignmnent is,
  (a,b) := ....
or
  a := ....
The former computes and returns two items (eg, both the eigen-vectors and values), while the latter computes just one (eg. only the eigen-values).

Personally, I find that syntax to be poor and disjointed. I am glad that no other commands have taken up this un-Maplelike syntax (as any further cloying attempt at Matlab emulation). I suppose it's a matter of personal preference.

For those interested, that functionality is implemented using the _nresults item in the context of procedure parameter-processing.

MTM is now a regular package of Maple (alone), rather than a toolbox. (Documentation of connectivity with Matlab is not great. But the MTM computational commands are available.)

First 133 134 135 136 137 138 139 Last Page 135 of 336