dharr

Dr. David Harrington

8235 Reputation

22 Badges

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

S := sum(cos(i*x)/cos(x)^i, i = 0 .. n);

cos(x)*sin((n+1)*x)/(sin(x)*cos(x)^(n+1))

``

Download sum.mw

If you export as .rtf, you should be able to open it in Word, in a form that allows it to be modified.

Select all the font files (ctrl-A), and then the right-click menu has install or install for all users. (Double-clicking a single font file will install it.)

Not sure exactly what shape and size you want, but easiest to just declare b as an upper triangular matrix before generating the b[i,j] which go into it.You then get an error because you assigned a non zero entry for the lower triangular part. (Edit: I removed b[j,i]:=b[i,j] to fix that.) Probably you can fix this up to do what you want. (You should avoid using b for more than one purpose.)

bmatrix.mw

Yes, if typesetting is standard then you get the 2D output close to the version you see.

`Methods for first order ODEs:``--- Trying classification methods ---``trying a quadrature``<- quadrature successful`                         sol := y(x) = -cos(x) + _C1

Note that for the lprinted lines, each line is delimited with backquotes, so you could use this to insert linebreaks.

Well, I would just use view not to see the others, since you end up making another list otherwise. But I fixed your `if`; you want NULL to remove the list element (and there was something strange about the first "abs")

Download plotting.mw

II:=int(q*(ln((-(w+t)^2+(q+p)^2-I*n)/(-(w+t)^2+(q-p)^2-I*n))
    +ln((-(-w+t)^2+(q+p)^2-I*n)/(-(-w+t)^2+(q-p)^2-I*n))), q,'CauchyPrincipalValue'):
simplify(II) assuming positive;

The answer is very long and probably not useful. But don't you want some integration limits?

I modified my earlier version to include the resistances as the edge weights and modified it also to accept non-integer vertex labelling (as often used in SpecialGraphs).

Resistance:=proc(G::Graph,Vin,Vout)
  local dG,VertexIn,VertexOut,nV,nE,currents,voltages,VertexLabels,
    currInOut,nodeeqns,deviceeqns,arcs,k,i,v,x,ans,R,wG;
  uses GraphTheory;
  if IsDirected(G) then error "Must be an undirected graph" end if;
  nV:=NumberOfVertices(G);
  nE:=NumberOfEdges(G);
  # convert unweighted Graph to weighted Graph with unit weights
  if IsWeighted(G) then wG:=CopyGraph(G) else wG:=MakeWeighted(G) end if;
  R:=WeightMatrix(wG);
  # convert to graph with integer vertex names
  VertexLabels:=Vertices(wG);
  wG:=RelabelVertices(wG,[$(1..nV)]);
  if not member(Vin,VertexLabels,'VertexIn') then error "Vin is not a vertex of the Graph" end if;
  if not member(Vout,VertexLabels,'VertexOut') then error "Vout is not a vertex of the Graph" end if;
  if VertexIn=VertexOut then return 0 end if;
  VertexIn,VertexOut:={VertexIn,VertexOut}[]; # want VertexIn<VertexOut
  arcs:=map(convert,Edges(wG),list);
  dG:=Graph(Vertices(wG),arcs); # directed version required for signed incidence matrix
  # Define voltages per node. Current arrow direction for edge {j,k} is j->k (j<k)
  currents:=[seq(i[j],j=1..nE)];
  voltages:=[seq(v[j],j=1..nV)];
  # unit current in and out through VertexIn and VertexOut 
  currInOut:=Vector(nV,0);
  currInOut[VertexIn]:=1;
  currInOut[VertexOut]:=-1;
  # Node equations from incidence matrix - rows are vertices, columns are edges.
  # One of these equations is redundant, but solve can handle that
  nodeeqns:={LinearAlgebra:-GenerateEquations(IncidenceMatrix(dG,reverse),currents,currInOut)[]};
  # Device equations - Ohm's law
  deviceeqns:=table();
  for k to nops(arcs) do
    x:=arcs[k];
    deviceeqns[k]:=v[x[1]]-v[x[2]]=i[k]*R[x[]]
  end do;
  deviceeqns:=convert(deviceeqns,set);
  # Solve the equations
  ans:=solve(nodeeqns union deviceeqns,{currents[],voltages[]});
  eval(v[VertexIn]-v[VertexOut],ans)
end proc:

 

with(GraphTheory):

G:=Graph({[{"000","400"},4],[{"400","450"},5],[{"450","050"},4],[{"050","000"},5],
          [{"003","403"},4],[{"403","453"},5],[{"453","053"},4],[{"053","003"},5],
          [{"000","003"},3],[{"400","403"},3],[{"450","453"},3],[{"050","053"},3]}):

Resistance(G,"000","453"); # body diagonal

156/47

``

 

Download GraphResistance.mw

ODEPlotParams.mw

For each point on the grid it solves the ode, so increasing the grid resolution slows the plot down.

First 43 44 45 46 47 48 49 Last Page 45 of 81