dharr

Dr. David Harrington

6411 Reputation

21 Badges

20 years, 21 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

@Majmaj If you really want Maple to do exact arithmetic, you want to just avoid floating point numbers (with a ".") and Digits altogether, and use rationals. So you could convert to rationals, do all your calculations and then convert back. The answers above effectively do that, but it seems simpler to use convert( ,rational,exact) and then evalf to the appropriate number of digits at the end. In the case of multiplication we can get the appropriate number of digits from the log of the denominator of the rationals, but as the others have pointed out, the general case is far from simple.

a:=convert(0.123456789,rational,exact);

123456789/1000000000

(1)

b:=a^2;

15241578750190521/1000000000000000000

(2)

evalf[18](b);

0.152415787501905210e-1

(3)

evalf[ilog10(denom(b))](b);

0.152415787501905210e-1

(4)

tofloat:=x->evalf[ilog10(denom(x))](x);

proc (x) options operator, arrow; evalf[ilog10(denom(x))](x) end proc

(5)

tofloat(b);

0.152415787501905210e-1

(6)

 


 

 

 

@Carl Love Good point. I always used to use just indets with a single argument, which would not consider Pi an indeterminate, then changed to indets( ,name) so I missed things like exp(a*d). (My recollection may be faulty, but I think very early Maple versions wouldn't have considered exp(a*d) an indeterminant.) If one has to give a very specific type specification, one wonders about the usefulness of indets, which is probably mainly used just for what the OP wanted.

Regards,
David.

@acer Interesting that the original answer with signum(t)^6 covers the t=0 case but the AllSolutions option does not.

@tomleslie I had in mind here that some integrals with infinite integrands are nonetheless finite, e.g., int(ln(x),x=0..1) = -1.

Regards,

David.

Well if you want phiB on the x axis and qB on the y axis then use

plot([phiB1,qB,qB=0..20]);

You still specify the range for qB, not phiB1, because you have phiB1 in terms of qB. If you want to know what value of qB corresponds to a value of phiB1, then you can look at the plot or use fsolve. Your intention for phi is still unclear.

@PatD 

I typically solve this problem by never assigning numerical values to variables, but using eval on a set of numerical parameters, as in the following:

Model 1

params:={a=1,b=2,c=1,d=3};
q:=a*b+c;
r:=b+d;
eval(q,params);
eval(r,params);

{a = 1, b = 2, c = 1, d = 3}

 

a*b+c

 

b+d

 

3

 

5

(1)

Model 2

params:={a=1,b=3,c=2,d=1};
q:=a*b^2+c;
r:=b+2*d;
eval(q,params);
eval(r,params);

{a = 1, b = 3, c = 2, d = 1}

 

a*b^2+c

 

b+2*d

 

11

 

5

(2)

I often put all the parameter sets at the top of the worksheet (but with different names: params1, params2 etc), so I can redo with different parameters by just changing the sets and then running the worksheet.

@Carl Love Possibly. I was going by his sketch.

@Carl Love The dynamic vector method of building lists is fastest,followed by the remember table method, but the other methods given do not give ordered lists. "entries" requires the 'indexorder' option to be ordered, but that slows it down, and there is a similar problem with the extracted remember table method.


restart:
#List building using regular table - result is not ordered
P:= proc(n)
local T,k;
for k to n do T[k]:= k end do;
[entries(T, 'nolist')]
end proc:
CodeTools:-Usage(P(2^22)):
P(5);


memory used=196.15MiB, alloc change=476.01MiB, cpu time=3.98s, real time=3.67s, gc time=624.00ms
[1, 2, 3, 5, 4]


restart:
#List building using regular table - use of indexoder option to order slows things down
P:= proc(n)
local T,k;
for k to n do T[k]:= k end do;
[entries(T, 'nolist','indexorder')]
end proc:
CodeTools:-Usage(P(2^22)):
P(5);


memory used=308.15MiB, alloc change=0.53GiB, cpu time=10.75s, real time=10.47s, gc time=670.80ms
[1, 2, 3, 4, 5]


restart:
#List building using regular table - convert to list slows things down more
P:= proc(n)
local T,k;
for k to n do T[k]:= k end do;
convert(T,list)
end proc:
CodeTools:-Usage(P(2^22)):
P(5);


memory used=388.16MiB, alloc change=0.67GiB, cpu time=17.46s, real time=12.08s, gc time=7.64s
[1, 2, 3, 4, 5]


restart:
#List building using remember table
P:= proc(n)
local R,k;
for k to n do R(k):= k end do;
[seq(R(k),k=1..n)];
end proc:
CodeTools:-Usage(P(2^22)):
P(5);


memory used=243.97MiB, alloc change=508.01MiB, cpu time=6.19s, real time=5.82s, gc time=826.81ms
[1, 2, 3, 4, 5]


restart:
#List building using extracted remember table - not ordered
P:= proc(n)
local R,k;
for k to n do R(k):= k end do;
[seq(k,k=op(4,eval(R)))];
end proc:
CodeTools:-Usage(P(2^22)):
P(5);


memory used=211.96MiB, alloc change=492.02MiB, cpu time=4.48s, real time=4.07s, gc time=873.61ms
[1, 2, 3, 5, 4]


restart:
#List building using dynamic vector
P:= proc(n)
local R:=Vector(),k;
for k to n do R(k):= k end do;
[seq(k, k= R)]
end proc:
CodeTools:-Usage(P(2^22)):
P(5);


memory used=174.03MiB, alloc change=82.03MiB, cpu time=3.34s, real time=3.21s, gc time=421.20ms
[1, 2, 3, 4, 5]

 Download List_Building.mw

I have had success in the past with providing an approximate solution. Something like 'approxsoln' = [F(eta) = 1+eta-(1/6)*eta^2, G(eta) = 0, H(eta) = 1-(1/3)*eta]. Presumably you know something about what the solution looks like roughly. Particularly there is not much information about G, only that it is zero at both boundaries.

It's not really an answer, but I do this with a coloured 3-D contour plot where I specify the exact contours I want and then colour the plot according to height using shading =zhue. For example

plot3d(S(X, Y), X = 0 .. X3, Y = 0 .. 1, axes = boxed, orientation = [-90, 0], scaling = constrained, style = surfacecontour, contours = [seq(i/(10.)+0.5e-1, i = 0 .. 9)], shading = zhue, thickness = 3, tickmarks = [6, 4, 3], labels = ["", "", ""], grid = [150, 50]);

You can then have a colour key using

plot3d(X, X = 0 .. 1, Y = 0 .. .2, axes = boxed, orientation = [-90, 0], scaling = constrained, thickness = 2, font = [Times, normal, 20], style = surfacecontour, shading = zhue,thickness=2, tickmarks = [0, 0, 0], labels = [" ", " ", " "],contours=[seq(0.1*i+0.05,i=0..9)]);

 

I can't see the right-hand side of your screen, but two problems come to mind. To define a1 as a function, you need a1:=(r,theta)->sum( etc And for plotting a function you need either plot(a1,0..infinity,0..Pi/2) or plot(a1(r,theta),r=0..infinity,theta=0..Pi/2)

I didn't save yesterday, but did it again, with a smaller number of solutions this time (263), though I believe I entered the equations identically. Many of the solutions have many variables zero, so there is a lot of structure here.

View 127_eqns.mw on MapleNet or Download 127_eqns.mw
View file details

I didn't save yesterday, but did it again, with a smaller number of solutions this time (263), though I believe I entered the equations identically. Many of the solutions have many variables zero, so there is a lot of structure here.

View 127_eqns.mw on MapleNet or Download 127_eqns.mw
View file details

I found this also. Specifically after entering with the maple button, the code previewed with an image (but not well). When I made the post, the image wasn't there. Looking at the source showed the text had been moved out of the maple tags and put after the closing one. I moved it back in source mode, but it ended up outside again. This behavior was different I think from a few days earlier. Definitely strange.

David

I see the half plane for x less than 1/2 as red, which is as it should be, since the function is -1 there. For x greater than 1/2 and y negative the function is x*y which is negative and again red. For x greater than 1/2 and y positive, the function is x*y which is now positive and shows yellow. This all seems right to me, and is a little clearer if you try contourplot3d(f(x,y),x=0..1,y=-1..1,contours=[0],filled=true,axes=boxed); and rotate around until you see the 2-D view. As for your first question, I am not so sure... David.
First 60 61 62 63 64 65 66 Page 62 of 66