dharr

Dr. David Harrington

6626 Reputation

21 Badges

20 years, 76 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are replies submitted by dharr


restart;

p:= 2233433222;

2233433222

What is the fastest way to get the digits of an integer (encoded in any form) into an Array

p1:=proc(p); StringTools:-ToByteArray(sprintf("%d",p)) end proc:

a1:=CodeTools:-Usage(p1(p),iterations=10^6);

memory used=0.98KiB, alloc change=45.00MiB, cpu time=8.75us, real time=8.32us, gc time=8.3e+02ns

Vector[row](10, {(1) = 50, (2) = 50, (3) = 51, (4) = 51, (5) = 52, (6) = 51, (7) = 51, (8) = 50, (9) = 50, (10) = 50})

p2:=proc(p); Array(StringTools:-Explode(sprintf("%d",p))) end proc:

a2:=CodeTools:-Usage(p2(p),iterations=10^6);

memory used=496 bytes, alloc change=-4.00MiB, cpu time=4.11us, real time=3.87us, gc time=5.2e+02ns

Vector[row](10, {(1) = "2", (2) = "2", (3) = "3", (4) = "3", (5) = "4", (6) = "3", (7) = "3", (8) = "2", (9) = "2", (10) = "2"})

p3:=proc(p); Array(convert(p,base,10)) end proc: #shockingly slow

a3:=CodeTools:-Usage(p3(p),iterations=10^6);

memory used=10.04KiB, alloc change=0 bytes, cpu time=64.62us, real time=59.91us, gc time=10.34us

Vector[row](10, {(1) = 2, (2) = 2, (3) = 2, (4) = 3, (5) = 3, (6) = 4, (7) = 3, (8) = 3, (9) = 2, (10) = 2})

p4:=proc(p) local i,s:=sprintf("%d",p); Array([seq(s[i],i=1..length(s))]) end proc:

a4:=CodeTools:-Usage(p4(p),iterations=10^6);

memory used=0.79KiB, alloc change=0 bytes, cpu time=5.88us, real time=5.53us, gc time=7.0e+02ns

Vector[row](10, {(1) = "2", (2) = "2", (3) = "3", (4) = "3", (5) = "4", (6) = "3", (7) = "3", (8) = "2", (9) = "2", (10) = "2"})

p5:=proc(p) local i,s:=sprintf("%d",p); Array(1..length(s),i->s[i]) end proc:

a5:=CodeTools:-Usage(p5(p),iterations=10^6);

memory used=0.90KiB, alloc change=0 bytes, cpu time=7.48us, real time=7.04us, gc time=9.2e+02ns

Vector[row](10, {(1) = "2", (2) = "2", (3) = "3", (4) = "3", (5) = "4", (6) = "3", (7) = "3", (8) = "2", (9) = "2", (10) = "2"})

p6:=proc(p) Array(convert(sprintf("%d",p),'bytes')) end proc:

a6:=CodeTools:-Usage(p6(p),iterations=10^6);

memory used=504 bytes, alloc change=0 bytes, cpu time=3.52us, real time=3.26us, gc time=5.3e+02ns

Vector[row](10, {(1) = 50, (2) = 50, (3) = 51, (4) = 51, (5) = 52, (6) = 51, (7) = 51, (8) = 50, (9) = 50, (10) = 50})

p7:=proc(p); kernelopts(opaquemodules=false); Array([`convert/base`:-MakeSplit(length(p), 1, 10)(p)]) end proc:

a7:=CodeTools:-Usage(p7(p),iterations=10^6);

memory used=0.83KiB, alloc change=0 bytes, cpu time=7.95us, real time=7.16us, gc time=1.67us

Vector[row](10, {(1) = 2, (2) = 2, (3) = 2, (4) = 3, (5) = 3, (6) = 4, (7) = 3, (8) = 3, (9) = 2, (10) = 2})

NULL

 

Download DigitsToArray.mw

@2cUniverse You cannot export a plot structure to a .tiff file. But you can convert it to an Image and then use ImageTools:-Write to write the file - see the code I provided above.

@Scot Gould I used the term "copy contents". The Vector has to be pre-existing; in your example z was not predined as a vector, and by default was a table. copy(v) does copy the vector and is fine at the top level, but within the OPs procedure prev:=copy(curr) still has the problem of assigning to a formal parameter.

@2cUniverse You can convert a plot directly to an Image without writing it to a file, so I think the following does what you want. I made the white background in the plot structure but if you prefer you can add it with PadImage after converting.

restart;

Make some square plot structure with white frame

sq:=plottools:-rectangle([-1,-1],[1,1],color=red):
lbl:=plots:-textplot([0,0,"HELLO"]):
whitebg:=plottools:-rectangle([-1.1,-1.1],[1.1,1.1],color=white):
plt:=plots:-display([sq,whitebg,lbl],axes=none,scaling=constrained,size=[500,500]):

Convert plot structure to image and output as .tiff

img:=convert(plt,Image):

ImageTools:-Write("C:/Users/dharr/Desktop/plt.tiff",img);

9510

NULL

Download maketiff.mw

@2cUniverse You can output plots to .gif or .jpeg or .png or  some other image formats (not .tiff). You can set the directory to anything you like for example

path:="C:/Users/dharr/Desktop";
filnam:=cat(path,"/plt",i,".gif");

and omit the base=option if using Export.

@2cUniverse I didn't understand your resolution comments. You could add the white frame as a rectangle behind all elements before exporting the plot in whatever format you want at whatever resolution you want (or as svg or eps vector graphics to later convert to tiff)

Edit: Following makes a square SVG with a white frame.

restart;

Make some square svg files with white frame

for i to 3 do
  sq:=plottools:-rectangle([-1,-1],[1,1],color=red);
  lbl:=plots:-textplot([0,0,convert(i,string)]);
  whitebg:=plottools:-rectangle([-1.1,-1.1],[1.1,1.1],color=white);
  plt:=plots:-display([sq,whitebg,lbl],axes=none,scaling=constrained,size=[0.5,"square"]);
  Export(cat("plt",i,".svg"),plt,base=worksheetdir,format="SVG");
  #print(plt);
end do:

NULL

Download makesvg.mw

@2cUniverse I can't access your zip file. But here is how to make square format .png files (I used Export) - note the size option to give the number of pixels.

restart;

Make some png files

for i to 3 do
  sq:=plottools:-rectangle([-1,-1],[1,1],color=red);
  lbl:=plots:-textplot([0,0,convert(i,string)]);
  Export(cat("plt",i,".png"),plots:-display(sq,lbl,axes=none,scaling=constrained,size=[500,500]),base=worksheetdir);
end do:

NULL

Download makepng.mw

Infolevel can be used to show the methods used, though the output is not always easy to understand. In this case further information about the homogeneous methods is given in the odeadvisor help pages.

restart;

Equation := int(diff(u(x), x)*v(x), x) = int(u(x)^(1/2)*v(x), x)^(-2/3);

int((diff(u(x), x))*v(x), x) = 1/(int(u(x)^(1/2)*v(x), x))^(2/3)

infolevel[dsolve]:=3;

3

Solution1:=dsolve(Equation);

Methods for first order ODEs:

--- Trying classification methods ---

trying homogeneous types:

differential order: 1; looking for linear symmetries

trying exact

-> Calling odsolve with the ODE (2*G(x)^(1/2)*v(x)+Intat(v(_a)*(diff(G(x) x))/G(x)^(1/2) _a = x))/Intat(G(x)^(1/2)*v(_a) _a = x)^(8/3) G(x) explicit [quadrature separable linear Bernoulli homogeneous]

   *** Sublevel 2 ***

   Classification methods on request

   Methods to be used are: [quadrature, separable, linear, Bernoulli, homogeneous]

   ----------------------------

   * Tackling ODE using method: quadrature

   --- Trying classification methods ---

   ----------------------------

   * Tackling ODE using method: separable

   --- Trying classification methods ---

   ----------------------------

   * Tackling ODE using method: linear

   --- Trying classification methods ---

   ----------------------------

   * Tackling ODE using method: Bernoulli

   --- Trying classification methods ---

   ----------------------------

   * Tackling ODE using method: homogeneous

   --- Trying classification methods ---

   trying homogeneous types:

<- exact successful

(3/4)*u(x)^(4/3)+Intat((2/3)*u(x)^(5/6)/(Int(u(x)^(1/2)*v(_b), _b))^(5/3), _b = x)+c__1 = 0

Odetest cannot verify this solution

odetest(Solution1,Equation);

-2*Intat(v(_b)/(Intat(v(_a), _a = _b)*(u(x)^(1/2)*Intat(v(_a), _a = _b))^(2/3)), _b = x)*(u(x)^(1/2)*(Int(v(x), x)))^(2/3)-3

NULL

Download dsolve.mw

 

@AlexShura OK, so you only entered the sequence to 512. Maple's listtoalgeq still returns fail, so I agree that the oeis result is unexpected and hard to interpret.

@AlexShura Email response (below) does not contain the polynomial in a(n). Please advise how you got that.

Greetings from The On-Line Encyclopedia of Integer Sequences! https://oeis.org/

 

> lookup 1 2 4 5 8 12 14 16 28 32 37 64 94 106 128 144 232 256 289 320

> 512 560 704 760 838 1024 1328 1536 1944 2048 2329 3104 3328 4096 4864

> 6266 6802 7168 8192 11952 15360 16384 16428 19149 28928 32768

 

a(n) = 1, 2, 4, 5, 8, 12, 14, 16, 28, 32, 37, 64, 94, 106, 128, 144, 232, 256, 289, 320, 512, 560, 704, 760, 838, 1024, 1328, 1536, 1944, 2048, 2329, 3104, 3328, 4096, 4864, 6266, 6802

 

# Direct matches

 

These sequences match the query directly.

oeis.org/search?q=1,2,4,5,8,12,14,16,28,32,37,64,94,106,128,144,232,256,289,320,512,560,704,760,838,1024,1328,1536,1944,2048,2329,3104,3328,4096,4864,6266,6802

 

oeis.org/A035001 Sorted elements of table (A035002) of a(m,n) =

                 sum(a(m-k,n), k=1..m-1)+sum(a(m,n-k), k=1..n-1).

 

    <1, 2, 4, 5, 8, 12, 14, 16, 28, 32, 37, 64, 94, 106, 128, 144, 232,

    256, 289, 320, 512, 560, 704, 760, 838, 1024, 1328, 1536, 1944, 2048,

    2329, 3104, 3328, 4096, 4864, 6266, 6802>, 7168, 8192, 11952, 15360,

    16384, 16428, 19149, 28928, 32768, 37120, 42168

 

 

# Transformations

 

These sequences match transformations of the original query.

 

T001 a(n) itself

 = 1, 2, 4, 5, 8, 12, 14, 16, 28, 32, 37, 64, 94, 106, 128, 144, 232, 256, 289, 320, 512, 560, 704, 760, 838, 1024, 1328, 1536, 1944, 2048, 2329, 3104, 3328, 4096, 4864, 6266, 6802

 

oeis.org/A035001 Sorted elements of table (A035002) of a(m,n) =

                 sum(a(m-k,n), k=1..m-1)+sum(a(m,n-k), k=1..n-1).

 

    <1, 2, 4, 5, 8, 12, 14, 16, 28, 32, 37, 64, 94, 106, 128, 144, 232,

    256, 289, 320, 512, 560, 704, 760, 838, 1024, 1328, 1536, 1944, 2048,

    2329, 3104, 3328, 4096, 4864, 6266, 6802>, 7168, 8192, 11952, 15360,

    16384, 16428, 19149, 28928, 32768, 37120, 42168

 

 

# Transformations as Deltas

 

The deltas of these sequences match transformations of the original query.

 

T018 a(n+1) - a(n)

 = 1, 2, 1, 3, 4, 2, 2, 12, 4, 5, 27, 30, 12, 22, 16, 88, 24, 33, 31, 192, 48, 144, 56, 78, 186, 304, 208, 408, 104, 281, 775, 224, 768, 768, 1402, 536 (as deltas)

 

oeis.org/A035001 Sorted elements of table (A035002) of a(m,n) =

                 sum(a(m-k,n), k=1..m-1)+sum(a(m,n-k), k=1..n-1).

 

    <1, 2, 4, 5, 8, 12, 14, 16, 28, 32, 37, 64, 94, 106, 128, 144, 232,

    256, 289, 320, 512, 560, 704, 760, 838, 1024, 1328, 1536, 1944, 2048,

    2329, 3104, 3328, 4096, 4864, 6266, 6802>, 7168, 8192, 11952, 15360,

    16384, 16428, 19149, 28928, 32768, 37120, 42168

 

 

In transformation descriptions,

Sn(z) denotes the ordinary generating function with coefficients a(n), and

En(z) denotes the exponential generating function with coefficients a(n).

 

___________________________________________________________________________

 

o  You can look up sequences online at the OEIS web site https://oeis.org/ o  For an explanation of the format used in the OEIS,

     see https://oeis.org/wiki/Style_Sheet o  If your sequence was not in the OEIS and is of general interest,

     please submit it using the submission form https://oeis.org/Submit.html o  The email address <sequences@oeis.org> does a simple lookup in the

   On-Line Encyclopedia of Integer Sequences, a limited form of the search

   available on the web site.

o  If you send an empty message, you will be sent the help file.

 

    Sequentially yours,

    The On-Line Encyclopedia of Integer Sequences.

    Maintained by The OEIS Foundation Inc., https://oeisf.org.

    Please donate!

 

P.S. This content is made available under the terms of The OEIS End-User License Agreement: https://oeis.org/LICENSE

Perhaps I'm not understanding what you did, but I can't reproduce this.

A035001.mw

 

So you know that the line

printf("After iterations %d, A = %f and B = %f\n",i,b(1),b(2));

was the problem because only the i was printed out as 1, and not the b(1). So you can try print(b(1)) and see what the value was that wasn't a number.

b and c are 2x1 Matrices since you generated then differently (extra inner <>) than for Vector P and t. So b should really be indexed  b[1,1] or b[2,1]. Or just make them Vectors.

Use square brackets for indexing Matrices, just as you did with the Vectors, i.e. use b[2,1] not b(1) and J[r,2] not J(r,2). The round brackets are for advanced users.

Since your calculation is all in floating point, you can initialize b and c and t in floating point, e.g, 1.0 not 1. Then calculations that have some floating point numbers will give floating point results - you don't then need the evalfs in the for loop or the while condition.

@abdulganiy I understand from your question and clarification that you want the exact same plot as the following line of code produces

Error_plot_y1 := pointplot3d(time_t, exy1_lst, err1, style = point, symbol = box, color = orange,labels = [`h=1/4`,`Exact`, typeset((`Absolute Errors`))]);

except that you want to use the plot3d command and not pointplot3d. If so, that is not possible because pointplot3d allows for specifying 3 vectors, but plot3d does not. If this is not what you want then you need to be more specific.

The link in your post works, but I agree that clicking on the author of that post leads to the front page. Presumably, the author has deleted their account.

@philroe For run to run consistency you can use sort on the list. It's not always clear what order you get, but for the same list elements your should get the same order each time.

First 21 22 23 24 25 26 27 Last Page 23 of 68