dharr

Dr. David Harrington

8330 Reputation

22 Badges

21 years, 3 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
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

If I paste the optimalisatie code into a code edit region I get the message that maplemint got about "These local variables were assigned a value, but otherwise unused:   int__sim_min", which is correct: You calculate this quantity (which looks like int with subscript sim_min) but then do not use it.

In the code edit region there is no message "invalid left hand side of assignment", so that seems to be spurious. [Edit; as @mmcdara points out this is assigning to Gamma__i_min and Gamma__i_max]

Note that the printed code for the procedure has many things such as int__sim_min looking like int[sim_min] as though you entered them as indexed variables. But pasting the 2-D code into a 1-D region or converting it to 1-D with the context menu shows that actually they are single variables displaying with subscripts, as you presumably intended. I've never seen that before.

In a code edit region it looks like

optimalisatie := proc(t__ex, c__ex, C__0, Q, V__r, m__b, rho, R, Gamma__i_min, Gamma__i_max)
	local Gamma__i, t__sim, C__i, int__sim, int__ex, C__i_min, C__i_max, C__i0_min, C__i0_max, C__i0, int__sim_min, int__sim_max, i;
	Gamma__i := 1/2*Gamma__i_min + 1/2*Gamma__i_max;
	t__sim, C__i := CC(C__0, Q, V__r, m__b, rho, R, Gamma__i);
	int__sim := integraal(t__sim, C__i);
	int__ex := integraal(t__ex, c__ex);
	for i while i < 10 and 1/10 < abs(int__sim - int__ex) do
		Gamma__i := 1/2*Gamma__i_min + 1/2*Gamma__i_max;
		t__sim, C__i_min := CC(C__0, Q, V__r, m__b, rho, R, Gamma__i_min);
		t__sim, C__i_max := CC(C__0, Q, V__r, m__b, rho, R, Gamma__i_max);
		t__sim, C__i := CC(C__0, Q, V__r, m__b, rho, R, Gamma__i);
		C__i0_min := normalisatie(C__i_min, C__0);
		C__i0_max := normalisatie(C__i_max, C__0);
		C__i0 := normalisatie(C__i, C__0);
		int__sim_min := integraal(t__sim, C__i0_min);
		int__sim_max := integraal(t__sim, C__i0_max);
		int__sim := integraal(t__sim, C__i0);
		if 0 < (int__sim - int__ex)*(int__sim_max - int__ex) then
			Gamma__i_max := Gamma__i;
		else
			Gamma__i_min := Gamma__i;
		end if;
	end do;
	return Gamma__i;
end proc;

Since none of the variables are now indexed, you need to check that was what you intended - was C or C__i intended to be an Array or Vector, for example?

@Scot Gould In @acer's detailed explanation its clear that it isn't just the plot form. The operator call form is robust and is my first go-to solution for plot difficulties, especially not needing to think about where and how many uneval quotes are needed. It has been around for as long as I can remember, and the plot help page refers to it as "The commonly used operator form of the calling sequence," even if it might not be "traditional" :)  

@acer Thanks for the detailed explanation. (I realised later that just entering the GAMMA equivalent didn't give the same result, and so the real situation was more complicated.)

@SHIVAS There is an attempt to do an inverse transformation at the end of my worksheet, which shows how to do it. It does not succeed but Eq 22 was different, Perhaps if it agreed with Eq 22 it would work. You will need to find the error in the eqns or conditions (assuming there is an error) to proceed.

@SHIVAS Yes, I did not get the same answer in eqn 22. I do not know what is wrong. If you think an assumption needs to be changed you will need to say which assumption it is and what it needs to be changed to, or change it yourself.

@SHIVAS I get a different transformed answer, which probably can't be inverse-transformed. Please check I didn't make any mistakes.

Download laplace.mw

@dharr If your objective is to follow the derivation in the paper, I can mostly derive the laplace transformed quantities, but I have to guess at the initial conditions - what are they? And why do x and y suddenly appear in the solution? Perhaps you can provide a link to the paper.

@Traruh Synred Somehow Export is being interpreted as ExportMatrix. I can't reproduce this in Maple 2023. @acer suggests you are using 2018, which had Export, but Maple 18 did not (use interface(version) to check your version). You can convert to a 4x1 Matrix and export it as you said, but saving to a .m file will save any Maple object and might be better for your application.

@Traruh Synred I can't figure out what is happening (not a version error) - please upload your worksheet using the green up-arrow in the Mapleprimes editor - choose the file, upload then choose insert link or insert contents.

@sursumCorda I added the timing test for the undocumented Makesplit, and it is not so different from some of the others, I guess there is a lot of overhead for some of these, so it might have been fairer to test with a case that had many more digits.

As for ithprime, according to ?GMP, it makes extensive use of the GMP library isprime, though that is for more digits that your test case here. Actually, processing nextprime a million times in 30 seconds seems pretty good to me!


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.

First 39 40 41 42 43 44 45 Last Page 41 of 87