Harry Garst

174 Reputation

5 Badges

13 years, 257 days

MaplePrimes Activity


These are questions asked by Harry Garst

 

Did someone already made a Pointplot3d for a Principal Components Analysis with projections for some data points on the eigenvectors?

I like this example very much:

http://www.joyofdata.de/public/pca-3d/

but I want to add projections on the three eigenvectors for some data points. I think it has to do something with the dot product, but I do not know how to do it in Maple. 

Hopefully someone already did this and is willing to share it.

kind regards,

Harry

 

For a statistical course I will give next year, I would like to demonstrate the calculation of tetrachoric and polychoric correlations. Furthermore, it would be nice to show the students how the expectation-maximization algorithm works.

Has anyone already programmed this in Maple?

best regards,

Harry

 

This works fine, but I was wondering whether it could be done in a simple way.
 

``

restart; kernelopts(version); interface(version)

`Maple 2018.2, X86 64 WINDOWS, Nov 16 2018, Build ID 1362973`

 

`Standard Worksheet Interface, Maple 2018.2, Windows 10, November 16 2018 Build ID 1362973`

(1)

kollect := proc (p::`+`, y) local x; subs(x = y, collect(subs(y = x, p), x)) end proc

kollect(kollect(kollect(kollect(expand(add(mul(k)*add(k), `in`(k, combinat:-choose([i1, i2, i3, i4], 3)))), i1^2), i2^2), i3^2), i4^2)

(i1*i2+i1*i3+i2*i3)*i4^2+(i1*i2+i1*i4+i2*i4)*i3^2+(i1*i3+i1*i4+i3*i4)*i2^2+(i2*i3+i2*i4+i3*i4)*i1^2

(2)

``


thanks in advance,

Harry

Download nested_comb.mw

Two lines that look the same, produce different results. The first lines gives an error message, but the next line that looks the same, does not.

copying and pasting both lines in Notepad reveals the difference:

Determinant*(R1 . B+R2 . B+R3 . B+R4 . A)

Determinant(R1 . B+R2 . B+R3 . B+R4 . A)

It seems that there is a hidden character (the asterisk) in the first line that produces the error.

In the worksheet itself you cannot see the asterisk, but using the arrow keys you can notice that there is another character.

It's hard to debug your code if there are hidden characters.

``

restart; with(LinearAlgebra)

kernelopts(version)*interface(version)

`Maple 2018.2, X86 64 WINDOWS, Nov 16 2018, Build ID 1362973`*`Standard Worksheet Interface, Maple 2018.2, Windows 10, November 16 2018 Build ID 1362973`

(1)

A := Matrix(4, 4, symbol = a, shape = symmetric)

B := Matrix(4, 4, symbol = b, shape = symmetric)

R1 := Matrix(4, 4); R1[1, 1] := 1; R2 := Matrix(4, 4); R2[2, 2] := 1; R3 := Matrix(4, 4); R3[3, 3] := 1; R4 := Matrix(4, 4); R4[4, 4] := 1

Determinant*(R1.B+R2.B+R3.B+R4.A)

Error, (in LinearAlgebra:-Multiply) invalid arguments

 

Determinant(R1.B+R2.B+R3.B+R4.A)

-a[1, 4]*b[1, 2]*b[2, 3]*b[3, 4]+a[1, 4]*b[1, 2]*b[2, 4]*b[3, 3]+a[1, 4]*b[1, 3]*b[2, 2]*b[3, 4]-a[1, 4]*b[1, 3]*b[2, 3]*b[2, 4]-a[1, 4]*b[1, 4]*b[2, 2]*b[3, 3]+a[1, 4]*b[1, 4]*b[2, 3]^2+a[2, 4]*b[1, 1]*b[2, 3]*b[3, 4]-a[2, 4]*b[1, 1]*b[2, 4]*b[3, 3]-a[2, 4]*b[1, 2]*b[1, 3]*b[3, 4]+a[2, 4]*b[1, 2]*b[1, 4]*b[3, 3]+a[2, 4]*b[1, 3]^2*b[2, 4]-a[2, 4]*b[1, 3]*b[1, 4]*b[2, 3]-a[3, 4]*b[1, 1]*b[2, 2]*b[3, 4]+a[3, 4]*b[1, 1]*b[2, 3]*b[2, 4]+a[3, 4]*b[1, 2]^2*b[3, 4]-a[3, 4]*b[1, 2]*b[1, 3]*b[2, 4]-a[3, 4]*b[1, 2]*b[1, 4]*b[2, 3]+a[3, 4]*b[1, 3]*b[1, 4]*b[2, 2]+a[4, 4]*b[1, 1]*b[2, 2]*b[3, 3]-a[4, 4]*b[1, 1]*b[2, 3]^2-a[4, 4]*b[1, 2]^2*b[3, 3]+2*a[4, 4]*b[1, 2]*b[1, 3]*b[2, 3]-a[4, 4]*b[1, 3]^2*b[2, 2]

(2)

``


 

Download weird.mw

I could not find a command that splits a polynomial in parts based on leading integer coefficients, so I wrote a procedure. It works well, but I still wonder if there is no simpler way of doing this?
My aim is to investigate whether there is some way of factoring this and other polynomials.
 

kind regards,
Harry Garst
 

``

restart; with(ListTools); with(LinearAlgebra)

p := 2*x^3*y+2*x^3*z+4*x^2*y^2+24*x^2*y*z+4*x^2*z^2+2*x*y^3+24*x*y^2*z+24*x*y*z^2+2*x*z^3+2*y^3*z+4*y^2*z^2+2*y*z^3-40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2+108*x*y+108*x*z+108*y*z-9*x-9*y-9*z+36

2*x^3*y+2*x^3*z+4*x^2*y^2+24*x^2*y*z+4*x^2*z^2+2*x*y^3+24*x*y^2*z+24*x*y*z^2+2*x*z^3+2*y^3*z+4*y^2*z^2+2*y*z^3-40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2+108*x*y+108*x*z+108*y*z-9*x-9*y-9*z+36

(1)

p1 := 2*x^3*y+2*x^3*z+2*x*y^3+2*x*z^3+2*y^3*z+2*y*z^3

2*x^3*y+2*x^3*z+2*x*y^3+2*x*z^3+2*y^3*z+2*y*z^3

(2)

p2 := 24*x^2*y*z+24*x*y^2*z+24*x*y*z^2

24*x^2*y*z+24*x*y^2*z+24*x*y*z^2

(3)

p3 := 4*x^2*y^2+4*x^2*z^2+4*y^2*z^2

4*x^2*y^2+4*x^2*z^2+4*y^2*z^2

(4)

p4 := -40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2

-40*x^2*y-40*x^2*z-40*x*y^2-40*x*z^2-40*y^2*z-40*y*z^2

(5)

p5 := 108*x*y+108*x*z+108*y*z

108*x*y+108*x*z+108*y*z

(6)

p6 := -9*x-9*y-9*z

-9*x-9*y-9*z

(7)

p7 := 36

36

(8)

simplify(p-p1-p2-p3-p4-p5-p6-p7)

0

(9)

Knip := proc (p) local g, h, i, j, N, X, Q; g := sort(ListTools:-MakeUnique([seq(lcoeff([op(p)][j]), j = 1 .. nops([op(p)]))])); h := 0; N := Matrix(nops([op(p)]), 1); X := Matrix(nops([op(g)]), 1); Q := convert([op(p)], Matrix); for j in g do h := h+1; N[h, 1] := convert([seq(ifelse(has(lcoeff([op(p)][i]), j), 1, 0), i = 1 .. nops([op(p)]))], Matrix); X[h, 1] := LinearAlgebra:-Trace(Q.N[h, 1]^%T) end do; return X end proc

proc (p) local g, h, i, j, N, X, Q; g := sort(ListTools:-MakeUnique([seq(lcoeff([op(p)][j]), j = 1 .. nops([op(p)]))])); h := 0; N := Matrix(nops([op(p)]), 1); X := Matrix(nops([op(g)]), 1); Q := convert([op(p)], Matrix); for j in g do h := h+1; N[h, 1] := convert([seq(ifelse(has(lcoeff([op(p)][i]), j), 1, 0), i = 1 .. nops([op(p)]))], Matrix); X[h, 1] := LinearAlgebra:-Trace(Typesetting:-delayDotProduct(Q, N[h, 1]^%T)) end do; return X end proc

(10)

Knip(p)

Matrix(%id = 18446747088530918086)

(11)

simplify(p-Trace(Matrix(1, 7, 1).Knip(p)))

0

(12)

``


 

Download knip.mw

 

1 2 3 4 5 6 7 Page 1 of 8