dharr

Dr. David Harrington

9596 Reputation

22 Badges

22 years, 89 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

> 

restart

Need specific N value to make progress.

> 

N := 5

5

> 

eq := add(alpha[n]*kappa^n*n, n = 0 .. N)^2+add(beta[n]*kappa^n*n, n = 0 .. N)^2

(5*kappa^5*alpha[5]+4*kappa^4*alpha[4]+3*kappa^3*alpha[3]+2*kappa^2*alpha[2]+kappa*alpha[1])^2+(5*kappa^5*beta[5]+4*kappa^4*beta[4]+3*kappa^3*beta[3]+2*kappa^2*beta[2]+kappa*beta[1])^2

Symbolically can find the zero root, but will need specific values of alpha and beta to get more

> 

solve(eq, kappa);

0, 0, RootOf((25*alpha[5]^2+25*beta[5]^2)*_Z^8+(40*alpha[4]*alpha[5]+40*beta[4]*beta[5])*_Z^7+(30*alpha[3]*alpha[5]+16*alpha[4]^2+30*beta[3]*beta[5]+16*beta[4]^2)*_Z^6+(20*alpha[2]*alpha[5]+24*alpha[3]*alpha[4]+20*beta[2]*beta[5]+24*beta[3]*beta[4])*_Z^5+(10*alpha[1]*alpha[5]+16*alpha[2]*alpha[4]+9*alpha[3]^2+10*beta[1]*beta[5]+16*beta[2]*beta[4]+9*beta[3]^2)*_Z^4+(8*alpha[1]*alpha[4]+12*alpha[2]*alpha[3]+8*beta[1]*beta[4]+12*beta[2]*beta[3])*_Z^3+(6*alpha[1]*alpha[3]+4*alpha[2]^2+6*beta[1]*beta[3]+4*beta[2]^2)*_Z^2+(4*alpha[1]*alpha[2]+4*beta[1]*beta[2])*_Z+alpha[1]^2+beta[1]^2)

Choose some specific values

> 

vals := zip(`=`, [seq(alpha[n], n = 0 .. N), seq(beta[n], n = 0 .. N)], [seq((rand(-3 .. 3))(), i = 1 .. 2*N+2)])

[alpha[0] = -1, alpha[1] = 2, alpha[2] = 2, alpha[3] = 0, alpha[4] = 2, alpha[5] = 2, beta[0] = 2, beta[1] = -3, beta[2] = 0, beta[3] = -2, beta[4] = -3, beta[5] = 1]

> 

eq2 := eval(eq, vals)

(10*kappa^5+8*kappa^4+4*kappa^2+2*kappa)^2+(5*kappa^5-12*kappa^4-6*kappa^3-3*kappa)^2

> 

ans := solve(eq2, kappa);

0, 0, RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 1), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 2), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 3), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 4), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 5), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 6), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 7), RootOf(125*_Z^8+40*_Z^7+148*_Z^6+224*_Z^5+110*_Z^4+104*_Z^3+52*_Z^2+16*_Z+13, index = 8)

> 

evalf([ans]);

[0., 0., .2359930256+.5296052631*I, .4481955872+1.141969704*I, -.1028659271+.6003394077*I, -.7413226857+0.6729615150e-1*I, -.7413226857-0.6729615150e-1*I, -.1028659271-.6003394077*I, .4481955872-1.141969704*I, .2359930256-.5296052631*I]

> 

fsolve(eq2, complex);

-.741322685659808-0.672961515020724e-1*I, -.741322685659808+0.672961515020724e-1*I, -.102865927127570-.600339407715825*I, -.102865927127570+.600339407715825*I, 0., 0., .235993025621495-.529605263094995*I, .235993025621495+.529605263094995*I, .448195587165883-1.14196970387710*I, .448195587165883+1.14196970387710*I

> 

``

Download solve.mw

Correct syntax is GroupOrder(ds[2]);

I agree; it's a bug. The coefficients are the same since simplify(c1(n)-c2(n)) assuming n::integer; returns zero. The fhat1 sum isn't evaluated correctly, but if sum is replaced by Sum, then (at least in Maple 2015), evalf(eval(fhat1,x=0.9)); returns 0.451026812 as expected.

Order is important, so use lists, not sets

> 

A:=[seq([a[m],b[m],c[m]],m=0..4)];

[[a[0], b[0], c[0]], [a[1], b[1], c[1]], [a[2], b[2], c[2]], [a[3], b[3], c[3]], [a[4], b[4], c[4]]]

> 

B:=[i,j,k];

[i, j, k]

> 

map(x->add(x*~B),A);

[i*a[0]+j*b[0]+k*c[0], i*a[1]+j*b[1]+k*c[1], i*a[2]+j*b[2]+k*c[2], i*a[3]+j*b[3]+k*c[3], i*a[4]+j*b[4]+k*c[4]]

> 

``

Download vecs.mw

The output of dsolve is an equation. You only want to plot the right-hand side. There may be other solutions.

> 

restart

> 

ODE := u(x)*(diff(u(x), x))-(1/10)*(diff(u(x), `$`(x, 2))) = 0;

u(x)*(diff(u(x), x))-(1/10)*(diff(diff(u(x), x), x)) = 0

> 

Bcs := u(0) = 1, u(1) = 0;

u(0) = 1, u(1) = 0

> 

ans := rhs(dsolve({Bcs, ODE}));

(1/5)*tan((x-1)*RootOf(_Z*tan(_Z)+5))*RootOf(_Z*tan(_Z)+5)

> 

plot(ans, x = 0 .. 1);

NULL

> 

NULL

 

Download solve_ode.mw

I think this is what you want, but perhaps you want a progressive animation, rather than a single point moving? Or something else altogether...

> 

restart;

> 

with(plots):

> 

xcoords:=[$1..100]: #x coordinates
ycoords:=[seq(i^2,i=1..nops(xcoords))]:   #y coordinates

> 

animate(pointplot,[[xcoords[n],ycoords[n]],symbol=solidcircle,color=blue,symbolsize=15],n=[$(1..nops(xcoords))]);

> 

 

 

Download animate.mw

The error message is because you are assigning to kt_poly, which is not allowed, because it is passed into the procedure (and already has a value). The easiest fix is just to have the procedure return the value of Quotient as the last line of the procedure. Now you get an error about Quotient not allowing multivariate polynomials, which is because the X passed into the procedure in cyclo_poly[i] is diiferent from the local X. The simplest fix is to pass the variable you want (X) as a third argument to the procedure.

> 

``

Programm zur Brechnung der Kreisteilungspolynome_2022-04-05 Ki

 

NULL

> 

restart; with(Algebraic); with(NumberTheory)

Error, invalid input: with expects its 1st argument, pname, to be of type {`module`, package}, but received NumberTheory

> 

n := 6;

6

> 

 

> 

cyclo_poly := Vector[row](1 .. n, 0)

cyclo_poly := Vector[row](6, {(1) = X-1, (2) = X+1, (3) = 0, (4) = 0, (5) = 0, (6) = 0})

> 

i := 1;

1

X-1

> 


c_poly := proc (i, kt_poly, X) local j, hz1, hz2; j := i+1; hz1 := X^j-1; hz2 := kt_poly; Algebraic:-Quotient(hz1, hz2, X) end proc:

> 

cyclo_poly[2] := c_poly(i, cyclo_poly[i], X);

X+1

> 

i := 1;

1

X-1

> 

j := i+1;

2

X^2-1

X+1

X-1

> 

Download Programm_zur_Brechnung_der_Kreisteilungspolynome_2022-04-05_Ki.mw

> 

s := series(1/tan(x), x, 9);

series(x^(-1)-(1/3)*x-(1/45)*x^3-(2/945)*x^5+O(x^7),x,7)

> 

s2 := convert(s, polynom)+`...`

1/x-(1/3)*x-(1/45)*x^3-(2/945)*x^5+`...`

> 

``

Download dots.mw

A plot of the indefinite integral shows discontinuities at 0, Pi, 2*Pi. If you take the limits from the left or right as appropriate, and avoid the discontinuities, you can get the right answer.

> 

restart; with(Student[Calculus1])

> 

Ellipse := [3*cos(theta), 2*sin(theta)]:

 

Why do the answers from evaluating EllALintegral differ from those provided by the ArcLength command?

> 

evalf(ArcLength(Ellipse, theta = 0 .. 2*Pi));

15.86543959

> 

evalf(Student:-Calculus1:-ArcLength(Ellipse, theta = 0 .. (1/4)*Pi));

1.734843463

> 

Student:-Calculus1:-ArcLength(Ellipse, theta = 0 .. 2*Pi, output = integral);

Int((9*sin(theta)^2+4*cos(theta)^2)^(1/2), theta = 0 .. 2*Pi)

15.86543959

> 

plot(sqrt(9*sin(theta)^2+4*cos(theta)^2), theta = 0 .. 2*Pi);

> 

EllALintegral := int(sqrt(9*sin(theta)^2+4*cos(theta)^2), theta);

-3*((5*cos(theta)^2-9)*(cos(theta)^2-1))^(1/2)*(1-cos(theta)^2)^(1/2)*EllipticE(cos(theta), (1/3)*5^(1/2))/((5*cos(theta)^4-14*cos(theta)^2+9)^(1/2)*sin(theta))

> 

plot(EllALintegral, theta = 0 .. 2*Pi);

> 

limit(EllALintegral, theta = 2*Pi, left);

3*EllipticE((1/3)*5^(1/2))

3.966359898

-3*EllipticE((1/3)*5^(1/2))

-3.966359898

> 

2*(limit(EllALintegral, theta = Pi, left)-(limit(EllALintegral, theta = 0, right)));

12*EllipticE((1/3)*5^(1/2))

15.86543959

> 

NULL

Download ArcLength_of_Ellipse.mw

I used eval to substitute C1 and C2 into psi, which had square brackets around that I removed. Then the limit works. You should be usung LinearAlgebra rather than linalg.

limit.mw

I usually force the hardware type I want, here integer[8]. Then you get an explicit error about the overflow.

Note that tail recursion gives a massive speedup - as the documentation says: "During compilation, tail-recursive calls are detected and transformed into iteration. This means that tail-recursive procedures compile to very fast code."

Download fibonacci.mw

Eigenvalues are efficiently calculated for floating point matrices, and if you specify shape=symmetric then it will use an algorithm for symmetric matrices that returns real eigenvalues. (Calculating through eigenvalues is better than through the characteristic polynomial).
 

> 

restart;

> 

with(LinearAlgebra):with(GraphTheory):
G2:=Graph({{1,2},{2,3},{3,1},{3,4}}):
A2:=AdjacencyMatrix(G2):
Anum:=Matrix(A2,datatype=float[8],shape=symmetric);
Eigenvalues(Anum);

Typesetting:-mrow(Typesetting:-mi("Anum", italic = "true", mathvariant = "italic"), Typesetting:-mo(":=", mathvariant = "normal", fence = "false", separator = "false", stretchy = "false", symmetric = "false", largeop = "false", movablelimits = "false", accent = "false", lspace = "0.2777778em", rspace = "0.2777778em"), Typesetting:-mverbatim("-I'RTABLEG6"6%"5i?>">uSuY%=-I'MATRIXG6"6#7&7&$""!""!$"""""!$"""""!$""!""!7&$"""""!$""!""!$"""""!$""!""!7&$"""""!$"""""!$""!""!$"""""!7&$""!""!$""!""!$"""""!$""!""!I'MatrixG6$%*protectedGI(_syslibG6""))

Vector[column]([[-1.48119430409202], [-1.00000000000000], [.311107817465982], [2.17008648662603]])

> 

NULL

 

Download evals.mw

Not sure about types of matrices, normal, diagonalizable, large or small etc, but this might be useful. For general M,N there is unlikely to be a solution.

Solve M^i = N for i

> 

restart

> 

with(LinearAlgebra)

Set up one we know (M should be diagonalizable; this one is also normal)

> 

M := Matrix(2, 2, {(1, 1) = 3/2, (1, 2) = 1/2, (2, 1) = 1/2, (2, 2) = 3/2})

M := Matrix(2, 2, {(1, 1) = 3/2, (1, 2) = 1/2, (2, 1) = 1/2, (2, 2) = 3/2})

> 

N := M^7

N := Matrix(2, 2, {(1, 1) = 129/2, (1, 2) = 127/2, (2, 1) = 127/2, (2, 2) = 129/2})

Straightforward method

> 

Z := MatrixFunction(M, x^i, x)-N; solve({entries(Z, 'nolist')}, i)

Z := Matrix(2, 2, {(1, 1) = -64+2^(-1+i), (1, 2) = -64+2^(-1+i), (2, 1) = -64+2^(-1+i), (2, 2) = -64+2^(-1+i)})

{i = 7}

Explicitly through the eigenvalues and eigenvectors

> 

evs, U := Eigenvectors(M)

evs, U := Vector(2, {(1) = 2, (2) = 1}), Matrix(2, 2, {(1, 1) = 1, (1, 2) = -1, (2, 1) = 1, (2, 2) = 1})

So M can be written

> 

Lambda := DiagonalMatrix(evs); U.Lambda.(1/U)

Lambda := Matrix(2, 2, {(1, 1) = 2, (2, 2) = 1}, storage = diagonal, shape = [diagonal])

Matrix([[3/2, 1/2], [1/2, 3/2]])

A function on the matrix is a function on its eigenvalues in this form, so M^i is

> 

U.Lambda^i.(1/U)

(Matrix(2, 2, {(1, 1) = 1, (1, 2) = -1, (2, 1) = 1, (2, 2) = 1})).(Matrix(2, 2, {(1, 1) = 2, (2, 2) = 1}, storage = diagonal, shape = [diagonal]))^i.(Matrix(2, 2, {(1, 1) = 1/2, (1, 2) = 1/2, (2, 1) = -1/2, (2, 2) = 1/2}))

So we can convert M^i to diagonal form by U^(-1).M^i.U, and if we do the same to N then the entries should be the same

> 

P := 1/U.N.U

P := Matrix(2, 2, {(1, 1) = 128, (1, 2) = 0, (2, 1) = 0, (2, 2) = 1})

If it wasn't diagonal, then there wouldn't be a solution. Equating the diagonals

> 

Equate(`~`[`^`](evs, i), Diagonal(P)); solve(%, i)

[2^i = 128, 1 = 1]

{i = 7}

> 

``

 

Download evs.mw

I'm guessing there are further rules to appear?

(I'm a liitle surprised my earlier code https://www.mapleprimes.com/questions/233777-Pythagorean-Puzzle#answer285102 works for these edge cases, since I didn't think about them at the time.)

Building on Joe Riel's solution, here are three solutions with two resistors. In each case one resistor current is 1 A and the other is 0 A. Resistance procedure is in startup code region

> 

restart

> 

with(GraphTheory):

@Joe Riel's solution with the second resistor disconnected

> 

G1 := GraphTheory:-Graph(["gnd", "1", "2", "3"], {[{"1", "gnd"}, 1], [{"2", "3"}, 1]}):

GraphTheory:-SetVertexPositions(G1, [[0, 0], [0, 1], [1, 1], [2, 1]]):

GraphTheory:-DrawGraph(G1);
EquivResistance = Resistance(G1, "1", "gnd")

EquivResistance = 1

If it has to be connected.

> 

G2 := GraphTheory:-Graph(["gnd", "1", "2"], {[{"1", "2"}, 1], [{"1", "gnd"}, 1]}):

GraphTheory:-SetVertexPositions(G2, [[0, 0], [0, 1], [1, 1]]):

GraphTheory:-DrawGraph(G2);
EquivResistance = Resistance(G2, "1", "gnd")

EquivResistance = 1

If it has to be connected both ends

> 

G3 := GraphTheory:-Graph(["gnd", "1", "2", "3"], {[{"1", "2"}, 1], [{"1", "3"}, 0], [{"1", "gnd"}, 1], [{"2", "3"}, 0]}):

GraphTheory:-SetVertexPositions(G3, [[0, 0], [0, 1], [1, 1], [1/2, 1/2]]):

GraphTheory:-DrawGraph(G3);
EquivResistance = Resistance(G3, "1", "gnd")

EquivResistance = 1

> 

NULL

Download OneOhm.mw

Not sure exactly what you want - here is a start.

> 

restart

Use GroupTheory - group is deprecated

> 

with(GroupTheory):

> 

> 

a := Perm([[2, 3, 5], [4, 7, 6]]);

_m486598272

_m486592800

> 

H := Group({a, b});

_m485510144

> 

elems := convert(Elements(H), list);

[_m483701280, _m483705632, _m483706528, _m483707424, _m483708320, _m483709344, _m483710240, _m483711136, _m483712032, _m483712928, _m483713184, _m483714016, _m483714848, _m483715744, _m483716640, _m483718880, _m483719712, _m483720544, _m485479424, _m486592800, _m486598272]

21

Product of all elements of H in the above order

> 

`.`(elems[]);

_m483719712

> 

DrawCayleyTable(H);

> 

NULL

NULL

Download Group.mw

Edit: here some of it in the older group package, if you have Maple earlier than version 17

oldgroup.mw

First 51 52 53 54 55 56 57 Last Page 53 of 90