Dr. David Harrington

5931 Reputation

21 Badges

19 years, 272 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 professor of chemistry at the University of Victoria, BC, Canada, where 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

@Carl Love But from the user's (OP's?) point of view, if they have row and column vectors already, and want to make the rank 1 matrix, then c.r is the natural way to do it, which is consistent with the mathematical use of the `.` operation for vectors and matrices. The fact that it might also be an outer product and Maple has programmed it that way should be hidden when using `.`. 

@dharr Since the ModuleLoad: in the message may not be what you want, you can rename it to something useful, e.g.,

pkg := module() export squareme; option package, load = `Default global settings`; local `Default global settings`;
  `Default global settings` := proc() userinfo(2,pkg, "All things are blue"); end proc;
  squareme:=proc(x) x^2 end proc;
end module; 


@dharr It turns out if you set the initial conditions to be arbitrary functions of beta__c that reduce to the classical values at beta__c = 0, then you can find what is probably the most general solution.


ode1 := diff(c(T),T)=-2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2);
ode2 := diff(p__c(T),T)=2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T);
sys := {ode1,ode2}:

diff(c(T), T) = -2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2)

diff(p__c(T), T) = 2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T)

We want a solution that tends to the following solution as beta__c tends to zero.

ans0:=dsolve(sys0 union {p__c(0)=pc0,c(0)=c0});

{diff(c(T), T) = -2*c(T), diff(p__c(T), T) = 2*p__c(T)}

{c(T) = c0*exp(-2*T), p__c(T) = pc0*exp(2*T)}

Let's define f(beta__c) as any function that has f(0) =c0 and g(beta__c) as any function that has g(0) = pc0.

f(0):=c0; g(0):= pc0; # remember this




Solve - there are many solutions depending on signs of various things. Probably could work through the correct case(s),

but here I just use the first solution and make assumptions that make it look nice.

ans1:=dsolve(sys union {p__c(0)=g(beta__c),c(0)=f(beta__c)},[p__c(T),c(T)]):
ans11:=simplify(ans1[1]) assuming beta__c>0, f(beta__c)>0, g(beta__c)>0, T>0;
simplify(eval(normal(%),beta__c=0)) assuming f(beta__c)>0, g(beta__c)>0, T>0, pc0>0:
ans11beta0:=simplify(%) assuming pc0>0;


{c(T) = f(beta__c)*g(beta__c)^(1/2)/((beta__c*f(beta__c)^2+g(beta__c)^2)*exp(8*T)-beta__c*f(beta__c)^2)^(1/4), p__c(T) = ((beta__c*f(beta__c)^2+g(beta__c)^2)*exp(8*T)-beta__c*f(beta__c)^2)^(1/4)*g(beta__c)^(1/2)}

{c(T) = c0*exp(-2*T), p__c(T) = pc0*exp(2*T)}



Try the other solving order - solution 8 is the same

ans2:=dsolve(sys union {p__c(0)=g(beta__c),c(0)=f(beta__c)},[c(T),p__c(T)]):
ans28:=simplify(ans2[8]) assuming beta__c>0, f(beta__c)>0, g(beta__c)>0, T>0;
simplify(eval(normal(%),beta__c=0)) assuming beta__c>0, f(beta__c)>0, g(beta__c)>0, T>0:
simplify(%) assuming pc0>0


{c(T) = f(beta__c)*g(beta__c)^(1/2)/((beta__c*f(beta__c)^2+g(beta__c)^2)*exp(8*T)-beta__c*f(beta__c)^2)^(1/4), p__c(T) = ((beta__c*f(beta__c)^2+g(beta__c)^2)*exp(8*T)-beta__c*f(beta__c)^2)^(1/4)*g(beta__c)^(1/2)}

{c(T) = c0*exp(-2*T), p__c(T) = pc0*exp(2*T)}




Download dsolve_simple.mw


@srmaple I agree that it seems Maple should have found a solutiion that changed smoothly as beta__c tended to zero. On the other hand it seems that you were unlucky in some ways that might not happen with other examples. When Maple eliminated the first variable (second in order given) it gave an equation without beta_c for the second variable, and that happened for both solving orders. Then the solution it did find had a beta__c in the denominator which meant dealing with a 0/0 form.

@srmaple Actually, I was comparing with the beta__c=0 solution, not Mathematica's, and suggested c2 = c2*beta__c as a simple function that went to zero. I even suggested c2*beta__c^2 was OK. But perhaps this is a better justification?



ode1 := diff(c(T),T)=-2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2);
ode2 := diff(p__c(T),T)=2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T);
sys := [ode1,ode2]:

diff(c(T), T) = -2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2)

diff(p__c(T), T) = 2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T)

First solve the system with beta__c = 0.
We want the solution for non-zero beta__c to reduce to this in the limit of beta__c -> 0.


[diff(c(T), T) = -2*c(T), diff(p__c(T), T) = 2*p__c(T)]

{c(T) = c__2*exp(-2*T), p__c(T) = c__1*exp(2*T)}

sol2:=simplify([eval(dsolve(sys,[c(T),p__c(T)],explicit),c__2=f(beta__c))]) assuming beta__c>0;

[{c(T) = -2*2^(1/2)*(f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = -((1/2)*I)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = 2*2^(1/2)*(f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = -((1/2)*I)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = -2*2^(1/2)*(f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = ((1/2)*I)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = 2*2^(1/2)*(f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = ((1/2)*I)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = -2*2^(1/2)*(-f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = -(1/2)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = 2*2^(1/2)*(-f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = -(1/2)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = -2*2^(1/2)*(-f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = (1/2)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}, {c(T) = 2*2^(1/2)*(-f(beta__c)/(2*c__1*exp(8*T)+16*f(beta__c))^(1/2))^(1/2)/beta__c^(1/2), p__c(T) = (1/2)*2^(1/2)*(2*c__1*exp(8*T)+16*f(beta__c))^(1/4)}]

So p__c(T) already tends to the right solution for f(beta__c) -> 0.

What other condition on f(beta) is required for c(T)? Take the first solution for example



Take a Taylor series for f(beta__c) with f(0)=0




series(eval(cT1,f(beta__c)=ff),beta__c,2) assuming beta__c::positive;
eval(convert(%,polynom),beta__c=0); #first term



Above agrees with the beta__c=0 solution for any function of beta__c that goes to zero and whose first derivative is non-zero at beta__c=0, e.g., const*beta__c


Download dsolve.mw

@Ronan A couple of comments

1. I wasn't using makehelp, but see here for how to do subfolders with that method

Creating Help - An Exploration Of Makehelp The browser entries have 3 items. But notice that he did not succeed in altering the order.

2. I was supposing that you might just replace the TOC with a new one, by making the appropriate Record structure. In my case I wanted my Orbitals package under Physics, so that the the top level Record is for Physics, and it has a child Record of Orbitals, which has child Records for the individual help pages. Here's what the final TOC looks like, from lprint(eval(TOC)):

Record('entry' = Physics,'topic' = (NULL),'priority' = (NULL),'language' = "en"
,'product' = "Maple",'category' = "Help Page",'children' = [Record('entry' = 
Orbitals,'topic' = (NULL),'priority' = (NULL),'language' = "en",'product' = 
"Maple",'category' = "Help Page",'children' = [Record('entry' = "Overview",'
topic' = "Orbitals,Overview",'priority' = 100,'language' = "en",'product' = 
"Maple",'category' = "Help Page",'children' = (NULL)), Record('entry' = 
"(atom4e, atomJ, atomK) - atomic exchange, coulomb and four-electron integrals"
,'topic' = "Orbitals,atom4e",'priority' = 70,'language' = "en",'product' = 
"Maple",'category' = "Help Page",'children' = (NULL)), Record('entry' = 
"(cartesian, fullcartesian) - convert to cartesian coordinates",'topic' = 
"Orbitals,cartesian",'priority' = 65,'language' = "en",'product' = "Maple",'
category' = "Help Page",'children' = (NULL)), Record('entry' = 
"(HYD) - hydrogenic orbital",'topic' = "Orbitals,HYD",'priority' = 60,'language
' = "en",'product' = "Maple",'category' = "Help Page",'children' = (NULL)), 
Record('entry' = "(HYDr) - radial part of hydrogenic orbital",'topic' = 
"Orbitals,HYDr",'priority' = 55,'language' = "en",'product' = "Maple",'category
' = "Help Page",'children' = (NULL)), Record('entry' = 
"(overlap) - overlap integral",'topic' = "Orbitals,overlap",'priority' = 50,'
language' = "en",'product' = "Maple",'category' = "Help Page",'children' = (
NULL)), Record('entry' = "Plotting orbitals examples",'topic' = 
"Orbitals,plots",'priority' = 5,'language' = "en",'product' = "Maple",'category
' = "Help Page",'children' = (NULL)), Record('entry' = 
"(realY) - real combinations of spherical harmonics",'topic' = "Orbitals,realY"
,'priority' = 45,'language' = "en",'product' = "Maple",'category' = "Help Page"
,'children' = (NULL)), Record('entry' = "Orbital package references",'topic' =
"Orbitals,references",'priority' = 2,'language' = "en",'product' = "Maple",'
category' = "Help Page",'children' = (NULL)), Record('entry' = 
"(STO) - Slater type orbital",'topic' = "Orbitals,STO",'priority' = 35,'
language' = "en",'product' = "Maple",'category' = "Help Page",'children' = (
NULL)), Record('entry' = "(STOr) - radial part of Slater type orbital",'topic'
= "Orbitals,STOr",'priority' = 30,'language' = "en",'product' = "Maple",'
category' = "Help Page",'children' = (NULL)), Record('entry' = 
"(Y) - spherical harmonic",'topic' = "Orbitals,Y",'priority' = 25,'language' =
"en",'product' = "Maple",'category' = "Help Page",'children' = (NULL)), Record(
'entry' = "Orbitals package examples",'topic' = "Orbitals,examples",'priority'
= 10,'language' = "en",'product' = "Maple",'category' = "Help Page",'children'
= (NULL))])])

If you think it's useful, I could send the help files themselves, so you could try converting them to the help database.

@MaPal93 Your treatment neglects the fact that the relationship between your new Sigma_v and sigma__v1 and sigma__v2 is lost if you only proceed with p3 and don't add the new auxilliary equation to the analysis. I fixed this and the scale factor up.

For two equations convert each to polynomials by removing the radicals. Then each polynomial is normalized so the first terms is 1 and then all the remaining terms for the two polynomials and the auxilliary equation(s)  are collected (even if there is a lot of redundancy, the matrix procedure will take care of it.)



1. It doesn't matter because const*p(x) has the same roots as p(x). If simplify didn't simplify to that form, then the old variables wouldn't be removed. I suppose checking for removal of the old variables could be automated, but I was just looking at it to check all the old ones were gone and did that manually to get a form where they are all gone.

2. Hubert's theory only works for polynomials where the monomials have integer exponents, or rational functions with the same condition. You could make new variables for the quantities with square roots, and then apply the theory to the system of equations, e.g. defining s= sqrt(a^2+b^2) will add terms a^2/s^2 and b^2/s^2 and then use the original eqn with s in. 

@sursumCorda I usually don't like to use undocumented commands, but that does work nicely for both rectangular and sparse matrices (by sparse I mean storage=sparse vs storage=rectangular).

Is the list l always the sequence of positive integers? Surely it must go to 10 if there are 10 twins and 10 is in your final list? If both these are true, I get 7 in the final list, so I'm not sure I understand. See attached.


@MaPal93 Since plot will evaluate the expressions numerically anyway, you don't want to simplify. If you plot [allvalues(Lambda)] it does plot, but it is hard to see which surface is which. You can plot them 1 at a time (I updated the above to Maple 2023 with a plot of the first one). If they are mostly complex, there won't be much to see.

The warning is because of the 5x51 matrix K output, but it is fast to rerun the worksheet so you can answer yes or no to "save these results", or just put a colon to not display the K matrix.

I'm guessing that since p3_complex has the same (by eye) number of real variables as p3, the new Lambda probably depends also on two nondim parameters. For p3_mostcomplex there is one more real variable, so maybe one more non-dim, but you might be lucky.

@Ronan My survey of the various filetypes used (.off, .ply, .stl etc) is that they are all for 3D objects and do not contain other information, with the possible exception of polygon face "textures" and "materials", which are for gaming applications and 3D printing respectively. So I think this is not a Maple issue. The face coloring I am less certain about, and the ability to support color is different for different files. But Maple doesn't seem to attempt to export color for any of them, which may be just that most 3D objects have a single color and not separate colors for individual faces. That can be fixed by messing with the PLOT3D structure, but that is significant effort.  

@dharr @acer's routine is brilliant for a single sum, but does not take advantage of efficiencies if you need a sequence of sums. @sursumCorda's approach can be adapted to give an efficient way to generate a sequence.

Download ijknew.mw

[Edit: faster routine now added:]


Modification of @sursumCorda's routine that works out a term for each permutation of a partition.

This version  (i) accumulates the sums and partitions as we go (`combstruct/allstructs/Partition/allpartk` uses option remember), and

                      (ii) does not work out all the permutations, just takes one term for each partition and multiplies by the number of permutations

sums := proc(m::posint)
  local n, s, parts, part, ss;
  s := 0:
  for n to m do
    parts := `combstruct/allstructs/Partition/allpartk`(n,3); # partitions of n with 3 parts
    s := s + add(combinat:-numbperm(part)/mul(part), part in parts);
    ss[n] := s;
  end do;
end proc:


memory used=357.30MiB, alloc change=72.00MiB, cpu time=406.25ms, real time=3.39s, gc time=23.44ms

Further efficiencies are possible by generating information for each partition iteratively only once..
The partitions themselves do not have to be generated.
If p(n, k) are the partitions of p with k parts, then these may be found by

(i) appending 1 to each of the p(n-1, k-1)

    The product of the parts is unchanged.
    The number of 1's increases by 1
    The number of permutations is multiplied by (np+1)/(m1+1), where m1 is the number of 1's in the old partition,
       and np is the number of parts in the old partition.
     For k = 3 quantityp2 = a*b+a*c+b*c can be calculated as prod+sum for [a, b]


(ii) adding 1 to each part in each of the p(n-k, k)

    The new product is prod+p2+sum+1, with p2 = 0 for k = 2 and p2 = a*b+a*c+b*c for [a, b, c] k = 3
     The new p2 is p2+2*sum+3
    The number of 1's is now zero.

    The number of permutations is unchanged.

        description "outputs length m Vector with V[n] = sum(1/(i*j*k), 1 <= (i,j,k) <= n)";
        local prods, m1, nperms, p2, n, s, ss, key, nn, nm1, nm2, nm3;
        if m = 1 then return Vector([0]) end if;
        if m = 2 then return Vector([0, 0]) end if;
        if m = 3 then return Vector([0, 0, 1]) end if;
        # initialize Array
        # prods = products of partition parts, e.g. (2,2) for 2 in 2 parts = [1,1]; prod =1
        prods := Array(1..4, 2..3, {
                (1,2) = Vector(),    (1,3) = Vector(),
                (2,2) = Vector([1]), (2,3) = Vector(),
                (3,2) = Vector([2]), (3,3) = Vector([1])});
        # multiplicity of 1's, e.g., (2,2) has 2 1's
        m1 := Array(1..4, 2..3, {
                (1,2) = Vector(),    (1,3) = Vector(),
                (2,2) = Vector([2]), (2,3) = Vector(),
                (3,2) = Vector([1]), (3,3) = Vector([3])});
        # number of permutations, e.g. 2 ways for (3,2) = [1,2] or [2,1]
        nperms := Array(1..4, 2..3, {
                (1,2) = Vector(),    (1,3) = Vector(),
                (2,2) = Vector([1]), (2,3) = Vector(),
                (3,2) = Vector([2]), (3,3) = Vector([1])});
        # for partitions with 3 parts only, p2 is sum of (products of two parts)
        # for [a,b,c], p2 = a*b + b*c +a*c        
        p2 := Array(1..4, {(1) =  Vector(), (2) =  Vector(), (3) =Vector([3])});
        s := 1;
        ss := Vector(m, {1 = 0, 2 = 0, 3 = s});
        # key has pointers to Array rows; reindexing allows reuse of rows in rotationg fashion
        key := [1, 2, 3, 4];        
        for n from 4 to m do
                nm3, nm2, nm1, nn := key[]; # mn3 = n-3 etc
                # update Array for this row
                # first part of Vector is for appending 1 to p(n-1,k-1)
                # second part of Vector is for adding 1's to p(n-k,k)
                # k = 2;
                        # (n-1,1) = [n-1] -> [n-1,1]; adding 1's -> no 1's
                        m1[nn, 2] := Vector(numelems(m1[nm2, 2])+1, {1=1});         # [1, 0, 0, ...]
                        # [n-1,1] has 2 perms; adding 1's leaves nperms unchanged             
                        nperms[nn, 2] := Vector([2, nperms[nm2, 2]]);
                        # [n-1,1] has prod n-1; adding 1's gives prodnew = (prod + sum + 1) of p(n-2,2)
                        prods[nn, 2] := Vector([n-1, prods[nm2, 2] +~ (n-1)]);                        
                # k = 3;
                        # appending 1 increases m1 by 1; adding 1's -> no 1's
                        m1[nn, 3] := Vector([ m1[nm1, 2] +~ 1, Vector(numelems(m1[nm3, 3])) ]);        
                        # appending 1: new nperms = (old nperms)*k/(m1+1); adding 1's leaves nperms unchanged                          
                        nperms[nn, 3] := Vector([ zip((x,y) -> x*3/(y+1), nperms[nm1, 2], m1[nm1, 2]), nperms[nm3, 3]]);
                        # [a,b] -> [a,b,1], p2 = (a*b) + (a+b); [a+1,b+1,c+1] has p2 = (a*b + b*c + a*c) + 2*(a+b+c) + 3
                        p2[nn] := Vector([ prods[nm1, 2] +~ (n-1), p2[nm3] +~ (2*n-3) ]);
                        # [a,b,1] has same prod as [a,b]; adding 1's gives prodnew = prod + p2 + sum + 1
                        prods[nn, 3] := Vector([ prods[nm1, 2], prods[nm3, 3] +~ p2[nm3] +~ (n-2) ]);
                # calculate and store sum
                s := s + add(nperms[nn, 3] /~ prods[nn, 3]);
                ss[n] := s;
                # reindex Array rows for next iteration
                key := ListTools:-Rotate(key, 1);
        end do;
end proc:


memory used=85.29MiB, alloc change=12.27MiB, cpu time=78.25ms, real time=452.50ms, gc time=3.91ms





Download ijknew2.mw

@raj2018 There are two pieces becouse there are two solutions for each kc and deltah, e.g., for kc=2.3, deltah = 0.8, M can be 0.0007832833567 or 1.134283416. If you don't want to see the bottom piece on the plot, just adjust the M range accordingly.

To get data out, it is best just to solve the equation for the values you want. An example is given in the attached 


@sursumCorda If you know the answer, you can cheat. Both convert(z*hypergeom([1/4, 1/2], [5/4], z**4), FormalPOwerSeries) and convert(EllipticF(z, I), FormalPowerSeries) give the same power series, verifying they are the same.

They are converted to apparently different expressions with integrals with convert(..., Int), so interconverting might be possible by rearranging, but it wasn't obvious to me.

2 3 4 5 6 7 8 Last Page 4 of 61