acer

32303 Reputation

29 Badges

19 years, 308 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

In my Maple 2024 GUI preferences file I have this item:

ScrollableMathTableOutput=false

and I don't get the scrollable Matrix display.

Here's an example of using Statistics:-NonlinearFit on your problem.

FindOptimizedParametersFit_ac.mw

Here are some ways to get just that one result.

nb. The OP did not tell us explicitly whether he wanted only real solutions, though he did try RealDomain as well as the assumption x>0.

restart;

eqx := x^(3/2) = a;

x^(3/2) = a

solve({eqx,a>-infinity},x);

{x = a^(2/3)}

PDEtools:-Solve({eqx,a>-infinity},x);

{x = a^(2/3)}

RealDomain:-solve(eqx,{x});

{x = a^(2/3)}

solve({eqx,Or(a<0,a>0)},x) assuming Or(a<0,a>0);

{x = a^(2/3)}

Download solve_par_real.mw

The functionality for alternate spellings of keyword parameters is available syntax.

It is documented on the Help page for topic parameter_processing.

See below, the parameter declaration,
   {[color,colour]:="b"}
in the definition of the procedure assigned to name foo.
 

restart

coltest:=proc(c)
  if c="b" then return 1
   elif c="r" then return 2
   elif c="g" then return 3
  end if;
end proc:

 

foo:=proc(a,{[color,colour]:="b"})
local COL;
   COL:=coltest(colour);
if COL=1 then return a
  elif COL=2 then return a^2
  elif COL=3 then return a^3
  else error `wrong colour`;
end if ;
end proc:

 

foo(3,colour="r")

9

foo(2,colour="p")

Error, (in foo) wrong colour

foo(3,color="r")

9

foo(2,color="p")

Error, (in foo) wrong colour

Download 2024-03-21_Q_colour_or_color_ac.mw

I also added a linebreak after the caption of the first plot, to give a little more space between the plot and what follows below it. I made the two slightly different so that you could choose what aspects you'd prefer.

I also set the size, and reduced the vertical view. (Change back, if unwanted.)

I got rid of the y-axis by setting its color to white. If you actually want all 4 edges of the boxed axes -- but not any y-ticks, say -- then please describe the effect you're after explicitly.

NULL

restart

with(Statistics)

NULL

A := [521, 383, 249, 238, 200, 146, 136, 135, 124, 123, 113, 113, 109, 106, 105, 95, 83, 82, 73, 69, 63, 45, 31, 30, 26, 18]

B := [1620, 521, 383, 249, 238, 200, 146, 136, 135, 124, 123, 113, 113, 109, 106, 105, 95, 83, 82, 73, 69, 63, 45, 31, 30, 26, 18]

BoxPlot([A], title = `#ms("Population density",mathcolor="blue");`, deciles = false, orientation = horizontal, width = .1, view = [0 .. 600, 0 .. .12], titlefont = [Tahoma, bold, 14], caption = typeset(`#ms("People per square km",mathcolor="red");`, "\n"), captionfont = [Tahoma, bold, 12], color = "Spring_Blue", mean = false, axis[2] = [color = "white"], axes = normal, size = [600, 300])

BoxPlot([B], title = `#ms("Population density",mathcolor="blue");`, deciles = false, orientation = horizontal, width = .1, view = [0 .. 1630, 0 .. .12], titlefont = [Tahoma, bold, 14], caption = `#ms("People per square km",mathcolor="red");`, captionfont = [Tahoma, bold, 12], color = "Spring_Blue", mean = false, size = [600, 300])

 

 

Download S5StatBoxPlotBtest_ac.mw

The Tabulate command will place its results in a (Task) region that appears below the normal output region of an Execution Group (or Document Block).

When called from within a procedure, a Tabulate call can be used something a bit like a print/lprint call, in the sense that it can be done before the return from the procedure.

2024-03-18_Q_Format_Returned_Results_into_a_Table_ac.mw

nb. If you make two or more Tabulate calls in a single Execution Group then the last will clobber the earlier. So you may well want to keep your calls to your procedure (as you already have them) in their own separate Execution Groups.

It seems that it can be done -- at least for smaller n -- by temporary substitutions a[i]=S[i]+b[i], then resubstituting for S[i] at the end.

The timing increases with n. Perhaps over badly. I lost patience waiting for P(7) to finish. There are also memory consumption issues involved. The OP did mention "small m" in the Question's title, however.

Of course, this is somewhat ad hoc and tailored for the problem at hand. I started by considering replacing a patterned collection of the arguments to the trig calls present. I tried a few, before success.

It might, however, suggest a broader approach. I mean, something other than scanning around speculatively for substitutions or selective freezing.

restart;

sineExpr:=(m::posint)-> local t,j;
                        add(mul(ifelse(j<>t,
                                       ':-sin'(a[j]-b[t])/':-sin'(b[j]-b[t]),
                                       ':-sin'(a[t]-b[t])),j=1..m),t=1..m):

 

P:=proc(n) local i,e,r,u,S;
  e:=sineExpr(n):
  r:=[seq(a[i]=S[i]+b[i],i=1..n)];
  u:=[seq(S[i]=a[i]-b[i],i=1..n)];
  eval(combine(simplify(expand(eval(e,r)))),u);
end proc:

 

seq(CodeTools:-Usage(print(P(i))), i=1..6);

sin(a[1]-b[1])

memory used=24.02MiB, alloc change=38.01MiB, cpu time=229.00ms, real time=229.00ms, gc time=33.99ms

sin(a[1]-b[1]+a[2]-b[2])

memory used=4.63MiB, alloc change=0 bytes, cpu time=54.00ms, real time=54.00ms, gc time=0ns

sin(a[3]-b[3]+a[2]-b[2]+a[1]-b[1])

memory used=62.38MiB, alloc change=70.00MiB, cpu time=680.00ms, real time=649.00ms, gc time=135.74ms

sin(a[4]-b[4]+a[3]-b[3]+a[2]-b[2]+a[1]-b[1])

memory used=21.23MiB, alloc change=0 bytes, cpu time=192.00ms, real time=193.00ms, gc time=0ns

sin(a[3]-b[3]+a[4]-b[4]+a[5]-b[5]+a[1]-b[1]+a[2]-b[2])

memory used=124.24MiB, alloc change=-4.00MiB, cpu time=1.25s, real time=1.14s, gc time=230.99ms

sin(a[6]-b[6]+a[3]-b[3]+a[1]-b[1]+a[4]-b[4]+a[5]-b[5]+a[2]-b[2])

memory used=1.58GiB, alloc change=163.77MiB, cpu time=15.36s, real time=13.51s, gc time=3.41s

Download sinId_accc.mw

And further words of caution. Some similar substitutions only work (here, with these particular intermediate steps) only for limited n values, eg.

restart;

sineExpr:=(m::posint)-> local t,j;
                        add(mul(ifelse(j<>t,
                                       ':-sin'(a[j]-b[t])/':-sin'(b[j]-b[t]),
                                       ':-sin'(a[t]-b[t])),j=1..m),t=1..m):

 

P2:=proc(n) local i,e,r,T;
  e:=sineExpr(n):
  r:=add(b[i],i=1..n)=T;
  eval(combine(simplify(expand(simplify(e,{r})))),(rhs=lhs)(r));
end proc:

 

seq(CodeTools:-Usage(print(P2(i))), i=1..4);

sin(a[1]-b[1])

memory used=28.61MiB, alloc change=71.01MiB, cpu time=262.00ms, real time=333.00ms, gc time=0ns

sin(-b[1]-b[2]+a[1]+a[2])

memory used=24.48MiB, alloc change=37.00MiB, cpu time=272.00ms, real time=444.00ms, gc time=80.57ms

sin(a[1]+a[3]+a[2]-b[1]-b[2]-b[3])

memory used=120.70MiB, alloc change=28.89MiB, cpu time=1.26s, real time=1.38s, gc time=245.30ms

-(-sin(-4*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[2]+2*b[4])+sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[1]-4*b[4])+sin(-4*b[1]+2*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3])+sin(-4*b[2]-2*b[1]+a[3]+a[4]+a[2]+a[1]+2*b[3])+sin(a[3]+a[4]+a[2]+a[1]-2*b[3]+2*b[1]-4*b[4])-sin(-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[1]+2*b[4])-sin(a[3]+a[4]+a[2]+a[1]-2*b[2]+2*b[1]-4*b[4])-sin(-2*b[3]+a[3]+a[4]+a[2]+a[1]-4*b[1]+2*b[4])-sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-4*b[1]-2*b[4])-sin(-4*b[1]-2*b[2]+a[3]+a[4]+a[2]+a[1]+2*b[3])+sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[2]-4*b[4])+sin(-2*b[2]+a[3]+a[4]+a[2]+a[1]-4*b[1]+2*b[4])+sin(-4*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[1]+2*b[4])-sin(-4*b[3]-2*b[1]+2*b[2]+a[3]+a[4]+a[2]+a[1])-sin(2*b[1]+a[3]+a[4]+a[2]+a[1]-4*b[3]-2*b[4])+sin(2*b[1]-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[4])+sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-4*b[3]-2*b[4])-sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-4*b[2]-2*b[4])+sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-4*b[1]-2*b[4])-sin(-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3]+2*b[1])+sin(-4*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[2]+2*b[1])-sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3]-4*b[4])-sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[1]-4*b[4])+sin(-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3]+2*b[4]))/(2*cos(-b[3]+3*b[2]+b[1]-3*b[4])-2*cos(3*b[3]-b[2]+b[1]-3*b[4])+2*cos(b[1]-3*b[2]+3*b[3]-b[4])-2*cos(3*b[1]-3*b[2]+b[3]-b[4])-2*cos(b[1]+3*b[2]-3*b[3]-b[4])-2*cos(3*b[1]-b[2]-3*b[3]+b[4])-2*cos(-b[3]-3*b[2]+b[1]+3*b[4])+2*cos(3*b[1]+b[2]-3*b[3]-b[4])-2*cos(b[2]-b[3]+3*b[1]-3*b[4])+2*cos(3*b[1]-3*b[2]-b[3]+b[4])+2*cos(-b[2]-3*b[3]+b[1]+3*b[4])+2*cos(b[3]-b[2]+3*b[1]-3*b[4]))

memory used=18.29GiB, alloc change=120.27MiB, cpu time=3.66m, real time=3.64m, gc time=55.68s

Download sinId_acb.mw

With an extra step you can obtain both any custom gridline color as well as the nicer curve (directly using the plot command, as you did) in your Maple 2023, as demonstrated in the following attachment.

restart

with(plots)

k := .9787011+(-10.88627-.9787011)/(1+(x/(0.4490702e-3))^1.792529)^.3004597

.9787011-11.8649711/(1+1001898.702*x^1.792529)^.3004597

plots:-display(plot(k, x = 10 .. 0.1e7, view = [10 .. 0.1e7, .92 .. .99], color = "Blue", background = "Ivory", filled = [color = "Cyan", transparency = .9], axis = [mode = log], size = [600, 300]), axis = [gridlines = [color = gray]])

Download gridlines_change_plot_ac.mw

Unfortunately your color adjustment to gridlines in the axis option does not work directly with plot's default of adaptive=geometric in Maple 2023.

That makes it fall back to adaptive=true, which produces that suboptimal curve portion that you've shown.

That's been fixed in Maple 2024.0, and your example works ok there.

ps. Supplying only gridlines=true produces a slightly darker shade than your forced color=gray.

You could import the whole thing as a Matrix, and then convert the second column to a list.

Eg,

   M:=ImportMatrix("example.txt",source=delimited,delimiter=" ");
   convert(M[..,2],list);

 

ps. I suspect that you could also do that first step as,
   ImportMatrix("dat_ex.txt",source=Matlab)

for n from 1 to 10 do
add(add(add(1/(i*j*k),i=1..n-j-k),j=1..n-2),k=1..n-2);
end do;

0

0

1

5/2

17/4

49/8

967/120

801/80

4523/378

84095/6048

Download add_exex.mw

And here is some timing comparison. I've used Maple 2023.2.1 here instead, because in my Linux 2024.0 the Iterator's internal fails to Compile (to faster code) and without compilation that Iterator approach takes very much longer.

I've changed the upper ends of the ranges from n down to n-2 in Ronan's approach using piecewise (since i,j,k are each at least 1). That improves the timing to compute all values n=1..30 from 1.872sec down to 1.422sec.

I've also included a further revision to that (end-point) modification of Ronan's approach, in which `if` is used instead of piecewise. Using piecewise here is a poor idea, in terms of performance.

kernelopts(version);

`Maple 2023.2, X86 64 LINUX, Nov 24 2023, Build ID 1762575`

restart;
str:=time[real]():
for n from 1 to 30 do
add(add(add(1/(i*j*k),i=1..n-j-k),j=1..n-2),k=1..n-2);
end do:
time[real]()-str;

0.31e-1

restart;
str:=time[real]():
for n from 1 to 30 do
add(add(add(`if`(i+j+k<=n, 1/(i*j*k),0),i=1..n-2),j=1..n-2),k=1..n-2);
end do:
time[real]()-str;

0.87e-1

restart;
s:=(n::posint)->add(add(1/~mul~(ListTools:-FlattenOnce(combinat:-permute~(combstruct['allstructs']('Partition'(l),'size'=3))))),l=3..n):
str:=time[real]():
seq(s(n), n = 1 .. 30):
time[real]()-str;

Warning, (in s) `l` is implicitly declared local

.381

restart;
str:=time[real]():
for n from 1 to 30 do
add(add(add(piecewise(i+j+k<=n, 1/(i*j*k),0),i=1..n-2),j=1..n-2),k=1..n-2);
end do:
time[real]()-str;

1.422

restart;
str:=time[real]():
s := 0:
for n to 30 do
    comps := Iterator:-Composition(n, parts = 3);
    s := s + add(1/mul(comp), comp in comps);
    #print(s);
end do:
time[real]()-str;

54.126

Download nested_cond_sum_ex_comp.mw

This site has been having several (new) issues in the past month or so.

1) It is slow to access, and ofter very slow
2) sometimes submissions are very slow (and if previewed, sometimes so slow that it seems stuck)
3) the response counter is much more broken than before

Several people have made posts about all this. I don't know whether anyone's fixing it.

expr:=(10*(5+sqrt(41)))/(sqrt(70+10*sqrt(41))*sqrt(130+10*sqrt(41))):

 

simplify(factor(expr))

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

Download rad_exx.mw

[edit] I see now that Thomas had already mentioned evala@factor. which is great. Also possible is radnormal@factor here.

The following variants involve three calls, without using factor.

radnormal(evala( combine(expr) ));
simplify(evala( combine(expr) ));
evala(radnormal( combine(expr) ));
simplify(radnormal( combine(expr) ));

That leads to noticing that the following expression (obtained from combine(expr) in M2024.0 at least) does not produce the same result (or normal form) under repeated calls to either evala or radnormal. This deserves a separate bug report, which I shall make.

restart;

foo := (5+41^(1/2))*(1/(7+41^(1/2))/(13+41^(1/2)))^(1/2);

(5+41^(1/2))*(1/((7+41^(1/2))*(13+41^(1/2))))^(1/2)

radnormal(foo);

(1/16)*(33-5*41^(1/2))^(1/2)*41^(1/2)+(5/16)*(33-5*41^(1/2))^(1/2)

radnormal(radnormal(foo));

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

evala(foo);

(1/16)*(33-5*41^(1/2))^(1/2)*41^(1/2)+(5/16)*(33-5*41^(1/2))^(1/2)

evala(evala(foo));

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

Download rad_exxx.mw

I wouldn't prefer the LinearAlgebra:-Column command for any example for which Matrix-indexing is convenient and terse. That's just a personal preference.

Eg,

M := LinearAlgebra:-RandomMatrix(5);

Matrix(5, 5, {(1, 1) = -81, (1, 2) = -98, (1, 3) = -76, (1, 4) = -4, (1, 5) = 29, (2, 1) = -38, (2, 2) = -77, (2, 3) = -72, (2, 4) = 27, (2, 5) = 44, (3, 1) = -18, (3, 2) = 57, (3, 3) = -2, (3, 4) = 8, (3, 5) = 92, (4, 1) = 87, (4, 2) = 27, (4, 3) = -32, (4, 4) = 69, (4, 5) = -31, (5, 1) = 33, (5, 2) = -93, (5, 3) = -74, (5, 4) = 99, (5, 5) = 67})

seq(M[..,i],i=1..5);

Vector(5, {(1) = -81, (2) = -38, (3) = -18, (4) = 87, (5) = 33}), Vector(5, {(1) = -98, (2) = -77, (3) = 57, (4) = 27, (5) = -93}), Vector(5, {(1) = -76, (2) = -72, (3) = -2, (4) = -32, (5) = -74}), Vector(5, {(1) = -4, (2) = 27, (3) = 8, (4) = 69, (5) = 99}), Vector(5, {(1) = 29, (2) = 44, (3) = 92, (4) = -31, (5) = 67})

Download Matrix_Cols.mw

Your code has several invalid calls to int, and several missing commas in the code of the plot calls.

Please compare worksheets.

ode_Plots_error_ac.mw

Do you mean something like the following? We can get similar effects using a loop, or using seq.

M := Matrix(4,4):

for i from 1 to 4 do
  for j from 1 to i do
    M[i,j] := [i,j];
  end do;
end do:

M;

Matrix(4, 4, {(1, 1) = [1, 1], (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = [2, 1], (2, 2) = [2, 2], (2, 3) = 0, (2, 4) = 0, (3, 1) = [3, 1], (3, 2) = [3, 2], (3, 3) = [3, 3], (3, 4) = 0, (4, 1) = [4, 1], (4, 2) = [4, 2], (4, 3) = [4, 3], (4, 4) = [4, 4]})

seq( seq( [i,j], j=1..i ), i=1..4);

[1, 1], [2, 1], [2, 2], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [4, 4]

 

Download loop_ex1.mw

First 26 27 28 29 30 31 32 Last Page 28 of 336