dharr

Dr. David Harrington

6416 Reputation

21 Badges

20 years, 23 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 answers submitted by dharr

I changed the rho's in the solution to rho__v's (as in the Eqs) and it worked.
solution_check.mw

I agree with Carl. Perhaps the following helps to illustrate the point.

restart

NULLN := (-t^2-1)*u^2-2*(t^2+1)^2*u+2*tNULL

(-t^2-1)*u^2-2*(t^2+1)^2*u+2*t

A := u^2*a[2]+u*a[1]+a[0]; B := u^2*b[2]+u*b[1]+b[0]

u^2*a[2]+u*a[1]+a[0]

u^2*b[2]+u*b[1]+b[0]

Q := collect(B*(diff(A, u))-A*(diff(B, u)), u)

(-a[1]*b[2]+a[2]*b[1])*u^2+(-2*a[0]*b[2]+2*a[2]*b[0])*u-a[0]*b[1]+b[0]*a[1]

We want to find when Q = N for any u. Since doubling the a's can be compensated for by halving the b's we can fix the scale by arbitrarily choosing a value for b[0], say 1. Or we can just write the solution for the other variables in terms of b[0]. Since we have 3 equations in 6 unknowns, we can extend this logic to another two variables aside from b[0], i.e., as @Carl Love noted we need to choose three variables to solve for in terms of the other three. For example, the following gives a[1], a[2] and b[2] in terms of the other 3. (Solve/identity is just a shortcut for the 3 equations equating the coefficients.

solve(identity(N = Q, u), {a[1], a[2], b[2]})

{a[1] = (a[0]*b[1]+2*t)/b[0], a[2] = -(1/2)*(t^4*a[0]*b[1]+2*t^5-t^2*a[0]*b[0]+2*t^2*a[0]*b[1]+4*t^3-a[0]*b[0]+a[0]*b[1]+2*t)/(t*b[0]), b[2] = -(1/2)*(t^4*b[1]-t^2*b[0]+2*t^2*b[1]-b[0]+b[1])/t}

Suppose we give a 4th variable to solve for - now we see the solution contains b[0] = b[0], meaning we can choose b[0] arbitrarily, the others are as above.

solve(identity(N = Q, u), {a[1], a[2], b[0], b[2]})

{a[1] = (a[0]*b[1]+2*t)/b[0], a[2] = -(1/2)*(t^4*a[0]*b[1]+2*t^5-t^2*a[0]*b[0]+2*t^2*a[0]*b[1]+4*t^3-a[0]*b[0]+a[0]*b[1]+2*t)/(t*b[0]), b[0] = b[0], b[2] = -(1/2)*(t^4*b[1]-t^2*b[0]+2*t^2*b[1]-b[0]+b[1])/t}

In this case, Maple chose to make a[1] arbitrary; we get the same as if we had chosen a[2], b[1] and b[2] to solve for.

solve(identity(N = Q, u), {a[1], a[2], b[1], b[2]})

{a[1] = a[1], a[2] = -(1/2)*(t^4*a[1]-t^2*a[0]+2*t^2*a[1]-a[0]+a[1])/t, b[1] = -(-a[1]*b[0]+2*t)/a[0], b[2] = (1/2)*(-t^4*a[1]*b[0]+2*t^5+t^2*a[0]*b[0]-2*t^2*a[1]*b[0]+4*t^3+a[0]*b[0]-a[1]*b[0]+2*t)/(t*a[0])}

NULL

Download Huang.mw

I made the opposite assumption to @acer (that you started with the equations), and kept implicitplot butdid them all in one, which is simple here despite the inefficiency.

restart

Load the necessary packages

with(plots); with(LinearAlgebra)

Define the equations to solve and plot

eq1 := 2*x-y+z = -5; eq2 := y+3*z = 7; eq3 := z = 2

Convert to the corresponding Matrix of coefficients and Vector (because we shouldn't have to enter equivalent information twice, and less likely to make a mistake)

A, b := GenerateMatrix([eq1, eq2, eq3], [x, y, z])

Matrix(%id = 36893490370101429060), Vector[column](%id = 36893490370101428940)

sol := LinearSolve(A, b)

Vector[column](%id = 36893490370101427364)

We can do all equations in one implicitplot. (I like the brighter colors, so I left the quotes off.)

implicitplot3d([eq1, eq2, eq3], x = -10 .. 10, y = -10 .. 10, z = -10 .. 10, color = [red, blue, green], style = surface, title = "3 D Plot of Linear System")

``

Download linear_systems.mw

Depends a bit on how you want to enter it.

restart

A := m -> int(xi*(1 - xi^2)*BesselJ(0, BesselJZeros(0, m)*xi), xi = 0 .. 1, numeric)/
          int(xi*BesselJ(0, BesselJZeros(0, m)*xi)^2, xi = 0 .. 1, numeric);

proc (m) options operator, arrow; (int(xi*(-xi^2+1)*BesselJ(0, BesselJZeros(0, m)*xi), xi = 0 .. 1, numeric))/(int(xi*BesselJ(0, BesselJZeros(0, m)*xi)^2, xi = 0 .. 1, numeric)) end proc

A(3)

0.4547647069e-1

A := proc (m) options operator, arrow; evalf((Int(xi*(-xi^2+1)*BesselJ(0, BesselJZeros(0, m)*xi), xi = 0 .. 1))/(Int(xi*BesselJ(0, BesselJZeros(0, m)*xi)^2, xi = 0 .. 1))) end proc

proc (m) options operator, arrow; evalf((Int(xi*(-xi^2+1)*BesselJ(0, BesselJZeros(0, m)*xi), xi = 0 .. 1))/(Int(xi*BesselJ(0, BesselJZeros(0, m)*xi)^2, xi = 0 .. 1))) end proc

A(3)

0.4547647069e-1

Save an integral - see DLMF

A := m -> 2*int(xi*(1 - xi^2)*BesselJ(0, BesselJZeros(0, m)*xi), xi = 0 .. 1, numeric)/
          evalf(BesselJ(1, BesselJZeros(0, m))^2);

proc (m) options operator, arrow; 2*(int(xi*(-xi^2+1)*BesselJ(0, BesselJZeros(0, m)*xi), xi = 0 .. 1, numeric))/evalf(BesselJ(1, BesselJZeros(0, m))^2) end proc

A(3)

0.4547647070e-1

NULL

Download Bessel.mw

evalf(BesselJZeros(0, 1..5));

gives: 2.404825558, 5.520078110, 8.653727913, 11.79153444, 14.93091771

Here's how I would do it. Not sure why I get the two different answers.

restart

interface(version)

`Standard Worksheet Interface, Maple 2024.0, Windows 11, March 01 2024 Build ID 1794891`

Digits := 40

40

use alpha=1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345,index=2)-1/2)**2) in
        expr:=(1+alpha)*sqrt(1-alpha**2)+(3+4*alpha)/12*sqrt(3-4*alpha**2)+2*(1+alpha)/3*sqrt(2*(1+alpha)*(1-2*alpha))+(1+2*alpha)/6*sqrt(2*((1-alpha)**2-3*alpha**2))
end:

evalf(expr)

2.912910414540209166042800910083320363837

Looks correct

PolynomialTools:-MinimalPolynomial(expr); fsolve(%)[2]

847155746562*_X^2-2718665563253*_X+731072836523

2.912910414540209166042800910083320363822

alias(r__2 = RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2))

r__2

expr2 := factor(evala(expr))

-(1/427776)*(-4*r__2^2+4*r__2+2)^(1/2)*(6307840*r__2^9+25065472*r__2^8-115353024*r__2^7+132632192*r__2^6-64357200*r__2^5+10339760*r__2^4+18097724*r__2^3-8262480*r__2^2-4524419*r__2-370681)

Square roots problematic, so convert to RootOf

expr3 := convert(expr2, RootOf)

-(1/427776)*RootOf(_Z^2+4*r__2^2-4*r__2-2, index = 1)*(6307840*r__2^9+25065472*r__2^8-115353024*r__2^7+132632192*r__2^6-64357200*r__2^5+10339760*r__2^4+18097724*r__2^3-8262480*r__2^2-4524419*r__2-370681)

We want the minimum polynomial. Over the rationals - not sure why this is not the same as above

evala(Minpoly(expr3, x)); fsolve(%)[-1]

x^20-(1099/72)*x^18+(1575661/20736)*x^16-(22165835/124416)*x^14+(40761112873/214990848)*x^12-(1002499649777/15479341056)*x^10+(11498404615715/1486016741376)*x^8-(3141147731417/17832200896512)*x^6-(86762801956691/184884258895036416)*x^4+(460470261157/164341563462254592)*x^2+33252616609/584325558976905216

2.912910414540209166042800910083320363836

With r__2as a field extension it is a quadratic

evala(Minpoly(expr3, x, r__2)); fsolve(%)[2]

(8159503/855552)*r__2-(236960/1671)*r__2^9+(2085340/5013)*r__2^8-(13276063/40104)*r__2^7+(414451/20052)*r__2^6+(10073755/160416)*r__2^5-(13077487/160416)*r__2^4+(1471997/213888)*r__2^3+(5380211/160416)*r__2^2+1770613/2566656+x^2

2.912910414540209166042800910083320363854

NULL

Download minpoly3.mw

You can assign part of a Matrix to part of another one using the notation for row and column selection, for example

A[6..7, 8..11] := M[3..4, 6..9]

copies rows 3..4 and colums 6..9 of M into rows 5..7, cols 8..11 of A. More complicared variations are possible, in which the rows and columns do not have to be adjacent - see the MVextract help page

Edit: I changed the above so the blocks are the same size. Orignally I had A[5..7, 8..11] := M[3..4, 6..9] - see Joe Riel for what happens in this case.

Here's a variation of @mmcdara's idea for a tetrahedron, since he challenged me :). Would require significantly more work for shapes where the folds aren't all on a flat base.

restart;

with(geom3d): with(GraphTheory):

Example - tetrahedron

solid := tetrahedron(t, point(o, [0,0,0]), 3);
f:=faces(solid);
pts:=vertices(solid);
seq(point(cat(p,i),pts[i]),i=1..nops(pts));

t

[[[3^(1/2), 3^(1/2), 3^(1/2)], [3^(1/2), -3^(1/2), -3^(1/2)], [-3^(1/2), 3^(1/2), -3^(1/2)]], [[3^(1/2), 3^(1/2), 3^(1/2)], [-3^(1/2), -3^(1/2), 3^(1/2)], [3^(1/2), -3^(1/2), -3^(1/2)]], [[3^(1/2), 3^(1/2), 3^(1/2)], [-3^(1/2), 3^(1/2), -3^(1/2)], [-3^(1/2), -3^(1/2), 3^(1/2)]], [[3^(1/2), -3^(1/2), -3^(1/2)], [-3^(1/2), -3^(1/2), 3^(1/2)], [-3^(1/2), 3^(1/2), -3^(1/2)]]]

[[3^(1/2), 3^(1/2), 3^(1/2)], [3^(1/2), -3^(1/2), -3^(1/2)], [-3^(1/2), 3^(1/2), -3^(1/2)], [-3^(1/2), -3^(1/2), 3^(1/2)]]

p1, p2, p3, p4

Code the faces with the indices of the points.

indextable:=table(pts=~[$1..nops(pts)]):
ff:=subsindets(f,[algebraic$3],x->indextable[x]);

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

Make corresponding graph

triangles:=map(CycleGraph,ff):
tetgraph:=Graph([$1..nops(pts)],`union`(map(Edges,triangles)[])):
SetVertexPositions(tetgraph,evalf(pts)):

Try some cuts (red edges on drawing) - spanning tree works for the convex platonic solids

tree:=SpanningTree(tetgraph):
HighlightSubgraph(tetgraph,tree);

DrawGraph(tetgraph, dimension = 3, size = [300, 300],orientation=[50,70]); #red edges are cuts

Uncut edges are the folds, which in this case are all in the same plane.

folds:=Edges(tetgraph) minus Edges(tree);
basevertices:=convert(`union`(%[]),list);
plane(base,map2(cat,p,basevertices)):
triangle(basetriangle,map2(cat,p,basevertices)):

{{2, 3}, {2, 4}, {3, 4}}

[2, 3, 4]

Remove base from the other faces

tofold:=remove(x->{x[]}={basevertices[]},ff);

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

Unfold

for m to nops(folds) do
 fold:=folds[m];
 foldface:=select(x-> fold subset {x[]}, tofold)[]; # find face to fold
 facepts:=map2(cat,p,foldface); # points in face
 angle:=evalf(FindAngle(base,plane(pl,facepts))); # angle between base and face
 ii := select(has,foldface,fold); # fold sorted as in tofold
 line(cat(raxis,m),map2(cat,p,ii)); # fold is rotation axis
 rotation(cat(unfolded,m),triangle(cat(tr,m),facepts),Pi-angle,cat(raxis,m)); # and rotate
end do:
 

Unfolded

draw([base,unfolded1,unfolded2,unfolded3]);

Angles all the same so generate animation

n:=20:
angles:=[seq(0..Pi-angle,numelems=n)]:

for i to nops(angles) do
  ang:=angles[i];
  rotation(rot1,tr1,ang,raxis1);
  rotation(rot2,tr2,ang,raxis2);
  rotation(rot3,tr3,ang,raxis3);
  dr[i]:=draw([solid,rot1,rot2,rot3]);
end do:
 

plots:-display([seq(dr[i],i=1..n)],insequence=true)

NULL

Download tetrahedron.mw

Here's a more matrixy way.

MM:=Matrix(2,[0,1,1,0]);
eq14 := lhs(eq13) = MM% . simplify(eval(MM^(-1) . rhs(eq13), `%.` = `.`));

ras5_v1.mw

Edit: simpler is 

eq14 := lhs(eq13) = MM %. simplify(value(MM^(-1).rhs(eq13)));

 

Try

p := plot(x^2):
im:=convert(p,Image):
ImageTools:-Embed(im);

 

Use dchange for this. I did the equations separately, but you can put them in a list and do it all in one step.

restart

_local(gamma)

de1 := diff(N(T), T) = R*N(T)*(1-N(T)/K)-alpha*N(T)*P(T)/(A+N(T)); de2 := diff(P(T), T) = gamma*N(T)*P(T)/(A+N(T))+C*P(T)/(1+Q*P(T))-M*P(T); ic1 := N(0) = N_0; ic2 := P(0) = P_0

diff(N(T), T) = R*N(T)*(1-N(T)/K)-alpha*N(T)*P(T)/(A+N(T))

diff(P(T), T) = gamma*N(T)*P(T)/(A+N(T))+C*P(T)/(1+Q*P(T))-M*P(T)

N(0) = N_0

P(0) = P_0

Desired new variables and parameters in terms of the old variables

itr := {a = A/K, b = gamma/R, c = C/R, m = M/R, q = Q*R*K/alpha, t = R*T, x(t) = N(T)/K, y(t) = alpha*P(T)/(R*K)}

{a = A/K, b = gamma/R, c = C/R, m = M/R, q = Q*R*K/alpha, t = R*T, x(t) = N(T)/K, y(t) = alpha*P(T)/(R*K)}

Maple needs the old variables in terms of the new variables.

tr := solve(itr, {A, C, M, Q, T, gamma, N(T), P(T)})

{A = a*K, C = c*R, M = m*R, Q = q*alpha/(R*K), T = t/R, gamma = b*R, N(T) = x(t)*K, P(T) = y(t)*R*K/alpha}

Try it directly

PDEtools:-dchange(tr, de1, [t, x, y, a, b, c, q, m])

(diff(x(t), t))*K*R = R*x(t)*K*(1-x(t))-x(t)*K^2*y(t)*R/(a*K+x(t)*K)

We see we have to divide each side by K*R. Adding simplify simplifies the rhs, but could do this as a separate step.

ode1 := PDEtools:-dchange(tr, de1/(K*R), [t, x, y, a, b, c, q, m], simplify)

diff(x(t), t) = x(t)*(1-x(t)-y(t)/(a+x(t)))

ode2 := PDEtools:-dchange(tr, alpha*de2/(R^2*K), [t, x, y, a, b, c, q, m], simplify)

diff(y(t), t) = y(t)*(b*x(t)/(a+x(t))+c/(1+q*y(t))-m)

init1 := PDEtools:-dchange(tr, ic1/K, [t, x, y, a, b, c, q, m], simplify)

x(0) = N_0/K

init2 := PDEtools:-dchange(tr, alpha*ic2/(K*R), [t, x, y, a, b, c, q, m], simplify)

y(0) = alpha*P_0/(R*K)

NULL

Download dchange.mw

y := 2*hypergeom([1/2, -k/2], [1 - k/2], csc(omega*T)^2)

Depending on what you know about k, you may be able to convert it to a nice form. For example, for k=3

convert(eval(y, k = 3), StandardFunctions)

gives

Download hypergeom.mw

implicitplot3d makes use of the ISOSURFACE structure, see ?plot,structure. I believe that this cannot be coloured with a color function, only GRID and MESH structures:

"For specification of multiple colors, the COLOR(t, A) structure, where t is RGB, HSV or HUE, is similar to that for the 2-D case, except that m by n GRID and MESH structures  are also supported. In this situation, A must be an Array with datatype=float[8] and dimensions 1..m, 1..n when t is HUE, or 1..m, 1..n, 1..3 otherwise."

Here's a workaround and how to use a colorfunction of 3 variables (simple in Maple 2016 and after)

restart

Desired function in implicit form

C := 2*x*y*z-x^2-y^2-z^2+1;

2*x*y*z-x^2-y^2-z^2+1

Desired colour function in 3-variable form

colfunc := (x, y, z) -> (x^2 + y^2 + z^2)/3:

Cannot use a colour function for implicit plot
One (ugly) workaround is to cast C in explicit form, handling the two pieces separately.
(Numeric option not required for operator plot calls as here)

z1,z2:=solve(C,z);
f1:=unapply(z1,x,y,numeric):
f2:=unapply(z2,x,y,numeric):

x*y+(x^2*y^2-x^2-y^2+1)^(1/2), x*y-(x^2*y^2-x^2-y^2+1)^(1/2)

Find the two corresponding colorfunctions

colfunc1:=(x,y)->colfunc(x,y,f1(x,y));
colfunc2:=(x,y)->colfunc(x,y,f2(x,y));
NULL

proc (x, y) options operator, arrow; colfunc(x, y, f1(x, y)) end proc

proc (x, y) options operator, arrow; colfunc(x, y, f2(x, y)) end proc

plot3d([f1,f2],-1..1,-1..1,color=[colfunc1,colfunc2]);

For Maple 2016 and later, colorscheme can be used

plot3d([f1,f2],-1..1,-1..1,colorscheme=["xyzcoloring",colfunc]);

NULL

Download 3d_coloring.mw

They are not to any order, but they are what I would expect. If I simplify by choosing specific examples for the initial functions, then play around with the expansion order, I find the total degrees in the residuals range from order-2 to 2*order-1. Since you have terms with a function times a first derivative of a function, you can expect up to (order plus (order-1)). For the low end, differentiation reduces the order and you have some third-order derivatives. So I would say the answer is verified up to order-3.

restart:

with(DETools):

PDE1 := diff(eta(t,x),t) + 1/2*diff(u(t,x),x) + 1/2*eta(t,x)*diff(u(t,x),x) - 1/48*diff(u(t,x),x$3) + diff(eta(t,x),x)*u(t,x);

diff(eta(t, x), t)+(1/2)*(diff(u(t, x), x))+(1/2)*eta(t, x)*(diff(u(t, x), x))-(1/48)*(diff(diff(diff(u(t, x), x), x), x))+(diff(eta(t, x), x))*u(t, x)

PDE2 := diff(u(t,x),t) + u(t,x)*diff(u(t,x),x) + diff(eta(t,x),x,t,t) + diff(eta(t,x),x) - 1/6*diff(u(t,x),x,x,t);

diff(u(t, x), t)+u(t, x)*(diff(u(t, x), x))+diff(diff(diff(eta(t, x), t), t), x)+diff(eta(t, x), x)-(1/6)*(diff(diff(diff(u(t, x), t), x), x))

sys := rifsimp([PDE1, PDE2]);

table( [( Solved ) = [diff(diff(diff(eta(t, x), t), t), x) = -u(t, x)*(diff(u(t, x), x))-(diff(u(t, x), t))+(1/6)*(diff(diff(diff(u(t, x), t), x), x))-(diff(eta(t, x), x)), diff(diff(diff(u(t, x), x), x), x) = 24*eta(t, x)*(diff(u(t, x), x))+48*(diff(eta(t, x), x))*u(t, x)+48*(diff(eta(t, x), t))+24*(diff(u(t, x), x))] ] )

id := initialdata(sys[Solved]);

table( [( Finite ) = [], ( Infinite ) = [eta(t, x[0]) = _F1(t), (D[2](eta))(t[0], x) = _F2(x), (D[1, 2](eta))(t[0], x) = _F3(x), u(t, x[0]) = _F4(t), (D[2](u))(t, x[0]) = _F5(t), (D[2, 2](u))(t, x[0]) = _F6(t)] ] )

Take a specific example

id2:=eval(eval(id),{_F1(t)=t,_F2(x)=0,_F3(x)=1,_F4(t)=1,_F5(t)=0,_F6(t)=0});

table( [( Finite ) = [], ( Infinite ) = [eta(t, x[0]) = t, (D[2](eta))(t[0], x) = 0, (D[1, 2](eta))(t[0], x) = 1, u(t, x[0]) = 1, (D[2](u))(t, x[0]) = 0, (D[2, 2](u))(t, x[0]) = 0] ] )

sols := rtaylor(sys[Solved], id2, point=[t = 0, x = 0], order = 6);

[eta(t, x) = t+t*x-(1/6)*t^3*x+2*t^2*x^2-4*t^2*x^3-(1/3)*t^4*x^2+(1/120)*t^5*x+(2/9)*t^3*x^3+(22/3)*t^2*x^4, u(t, x) = 1+(112/5)*t*x^5+7*t^2*x^4-(4/3)*t^3*x^3+2*x^4+(48/5)*x^5+8*x^3+8*t*x^3+(8/5)*x^6]

Total degrees of terms in residual, and min and max of these

pdetest(sols,PDE1):
map(degree,[op(%)]);
min(%),max(%);

[5, 5, 4, 5, 5, 11, 11, 8, 10, 10, 10, 9, 9, 11, 11, 10, 9, 11, 9, 11, 11, 9, 7, 6, 7, 8, 6, 8, 7, 8, 7, 6, 6, 4, 5, 5]

4, 11

pdetest(sols,PDE2):
map(degree,[op(%)]);
min(%),max(%);

[5, 5, 5, 4, 5, 11, 10, 10, 9, 9, 10, 9, 11, 11, 9, 11, 11, 11, 7, 8, 8, 8, 7, 6, 4, 5, 5, 11, 10, 9, 8, 7, 6]

4, 11

``

Download MinWorkingExa.mw

You could use the userinfo mechanism to do this. For example, 

pkg := module() export squareme; option package; local ModuleLoad;
  ModuleLoad := proc() userinfo(2, pkg, "Hi I'm loading"); end proc;
  squareme := proc(x) x^2 end proc;
end module; 

which leads, with infolevel[pkg] >= 2:

restart;

infolevel[pkg]:=3;

3

libname:=libname,interface(worksheetdir):

 

with(pkg);

ModuleLoad: Hi I'm loading

[squareme]

``

Download pkgload.mw

4 5 6 7 8 9 10 Last Page 6 of 67