janhardo

935 Reputation

13 Badges

12 years, 25 days
B. Ed math

MaplePrimes Activity


These are replies submitted by janhardo

How do I evaluate a simplified expression and determine the dimension matrix from module code?

kroneckerproducts_module_with_dimensioncheckDEF_5-5-2026_.mw

Examine the mixed Kronecker expression ?
kroneckerproducts_module_with_dimensioncheck__4-5-2026.mw

Module has dimensioncheck for numeric use and symbolic use a dimension warning

Check this in Linear Algebra 
Your example is correct , because  X and Y do have the right dimensions

Experiment with dimensions  

restart;
with(LinearAlgebra):

# =========================================================
# Kies afmetingen zodat de regel geldt:
#   X is een kolomvector (n×1)
#   Y is een rijvector   (1×m)
# =========================================================
# A : p × n          (p willekeurig)
# X : n × 1          (kolomvector)
# Y : 1 × m          (rijvector)
# B : m × q          (q willekeurig)
p := 3;
n := 2;
m := 4;
q := 2;

A := Matrix(p, n, symbol = a);
X := Matrix(n, 1, symbol = x);
Y := Matrix(1, m, symbol = y);
B := Matrix(m, q, symbol = b);

# Linker- en rechterlid van de identiteit
L := A . (KroneckerProduct(X, Y)) . B;
R := KroneckerProduct(A . X, Y . B);

# Verschil (moet een nulmatrix zijn)
Verschil := simplify(L - R);
print(Verschil);

@Harry Garst 

This mixed Kronecker expression is a special case; the same seems to apply to the module code
The module code does not yet check the dimensions of the simplified expressions, but it could.(i  add this later)

The question you’re asking is a tricky one, but hopefully this answer will be helpful
You can use the procedure to check the input for dimensions, and with this knowledge, you can also check this in a linear algebra package.

gemixed_produkt_expressie_voorwaarden_dimensie_controle_en_uitleg_3-5-2026.mw

@Harry Garst 

You try to check rule 7 ...
I used the Kron notation, easier to read

Download vraag-_Is_this_correct_mprimes_3-5-2026.mw


 

 

restart;
with(plots): with(plottools):

# ------------------------------------------------------------
# 1. PRINT THE MATHEMATICAL DERIVATION
# ------------------------------------------------------------
print("Why does stacking these triangles produce a logarithmic spiral?");
print("Definition: Z(0) = 8, Z(1) = 8*(1/4 + I*sqrt(3)/4) = 2+2*I*sqrt(3)");
print("Recurrence: Z(n) = Z(n-1) * (1/4 + I*sqrt(3)/4)");
print("Modulus of the factor = 1/2, argument = Pi/3 (60°)");
print("So |Z(n)| = 8*(1/2)^n, arg(Z(n)) = n*Pi/3");
print("In polar coordinates: r = 8*(1/2)^n, theta = n*Pi/3");
print("Eliminate n: n = 3*theta/Pi -> r = 8*exp(-(3*ln(2)/Pi)*theta)");
print("This is a logarithmic spiral. The vertices Z(n) lie exactly on this spiral.\n");

# ------------------------------------------------------------
# 2. DEFINE THE COMPLEX VERTICES Z(n)
# ------------------------------------------------------------
Z := n -> evalf(8 * (1/4 + I*sqrt(3)/4)^n):   # numeric values for plotting

# ------------------------------------------------------------
# 3. PLOT THE LOGARITHMIC SPIRAL (red, thick) through the vertices
# ------------------------------------------------------------
r0 := 8: b := -3*ln(2)/Pi:
spiral := polarplot(r0*exp(b*theta), theta=0..8*Pi,
                    color="Red", thickness=3, scaling=constrained,
                    axes=boxed, labels=["Re(z)", "Im(z)"]):
# ------------------------------------------------------------
# 4. PREPARE THE TRIANGLES (original definition, animated)
# ------------------------------------------------------------
Triangle := i -> polygon([[0,0], [Re(Z(i-1)), Im(Z(i-1))], [Re(Z(i)), Im(Z(i))]]):

frame := proc(n::posint)
    local i, colors;
    colors := ["Red","Green","Blue","Yellow","Magenta","Cyan"];
    display(seq(Triangle(i), i=1..n),
            color=[seq(colors[(i-1 mod 6)+1], i=1..n)],
            transparency=0.5);   # semi-transparent to see the spiral
end proc:

# Create the animation (first 6 frames)
animation := display(seq(frame(i), i=1..6), insequence, scaling=constrained):

# ------------------------------------------------------------
# 5. PLOT THE VERTICES AS BLACK DOTS (to show they lie on the spiral)
# ------------------------------------------------------------
vertices := [seq([Re(Z(n)), Im(Z(n))], n=0..6)]:
vertex_plot := pointplot(vertices, symbol=solidcircle, symbolsize=7, color="Green"):

# ------------------------------------------------------------
# 6. COMBINE EVERYTHING IN A LARGE DISPLAY
# ------------------------------------------------------------
final_plot := display(animation, spiral, vertex_plot,
                      scaling=constrained, size=[1800,900],
                      title="Logarithmic spiral through the vertices of stacked triangles",
                      titlefont=[Times,16]):

# Show the final plot
final_plot;

"Why does stacking these triangles produce a logarithmic spiral?"

 

"Definition: Z(0) = 8, Z(1) = 8*(1/4 + I*sqrt(3)/4) = 2+2*I*sqrt(3)"

 

"Recurrence: Z(n) = Z(n-1) * (1/4 + I*sqrt(3)/4)"

 

"Modulus of the factor = 1/2, argument = Pi/3 (60°)"

 

"So |Z(n)| = 8*(1/2)^n, arg(Z(n)) = n*Pi/3"

 

"In polar coordinates: r = 8*(1/2)^n, theta = n*Pi/3"

 

"Eliminate n: n = 3*theta/Pi -> r = 8*exp(-(3*ln(2)/Pi)*theta)"

 

"This is a logarithmic spiral. The vertices Z(n) lie exactly on this spiral.
"

 

 

 

 


 

Download logaritmic_spiral_in_complex_planeDEF_3-5-2026.mw

@C_R 

Interesting, thanks for  geodesics_AI.mw

@Harry Garst 
Ja , en hopelijk kan je er iets mee met de module code :-)
Nog wat verder uitbreiden met nieuwe regels 
groet Jan

@janhardo 
Testing commando's 
Performance test.comparison, seems to be quick with the module

with(LinearAlgebra):

# matrix size (adjust as needed!)
n := 40:

# random matrices
A := RandomMatrix(n,n, generator=-5..5):
B := RandomMatrix(n,n, generator=-5..5):
C := RandomMatrix(n,n, generator=-5..5):
d := RandomMatrix(n,n, generator=-5..5):

# ---------- 1. Naive method ----------
t1 := time():

K1 := KroneckerProduct(A,B):
K2 := KroneckerProduct(C,d):
R1 := K1 . K2:

t_naive := time() - t1:

# ---------- 2. Smart method (KRON7) ----------
t2 := time():

R2 := KroneckerProduct(A . C, B . d):

t_smart := time() - t2:

# ---------- Results ----------
printf("Naive time  = %.4f sec\n", t_naive);
printf("Smart time  = %.4f sec\n", t_smart);
printf("Speedup(faster)     = %.2f x\n", t_naive / t_smart);

# ---------- Verification ----------
printf("Equal? %a\n", Equal(R1, R2));
Naive time  = 244.7970 sec
Smart time  = 1.2500 sec
Speedup(faster)     = 195.84 x
Equal? true

restart;
with(LinearAlgebra):
ZehfussReplace := proc(expr::uneval)
    uses LinearAlgebra:
    local replace;
    replace := proc(det)
        local kr_args, A, B;
        kr_args := op(1, det);
        if not type(kr_args, specfunc(KroneckerProduct)) then return eval(det) end if;
        A := op(1, kr_args);
        B := op(2, kr_args);
        'Determinant'(A)^(RowDimension(B)) * 'Determinant'(B)^(RowDimension(A));
    end proc;
    subsindets(expr, specfunc(specfunc(KroneckerProduct), Determinant), replace);
end proc:

A := Matrix(2,2,symbol=a);
B := Matrix(3,3,symbol=b);

# Important: call the procedure directly with the unevaluated form
result := ZehfussReplace( Determinant(KroneckerProduct(A,B)) + 2*Determinant(KroneckerProduct(A,A)) );
# print(result);
  eval(result);

Matrix(2, 2, {(1, 1) = a[1, 1], (1, 2) = a[1, 2], (2, 1) = a[2, 1], (2, 2) = a[2, 2]})

 

Matrix(%id = 36893490552170632124)

 

LinearAlgebra:-Determinant(A)^3*LinearAlgebra:-Determinant(B)^2+2*LinearAlgebra:-Determinant(A)^4

 

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

(1)
 

 

Download Zehfuss_-kronecker_determinant__mprimes_22-4-2026.mw

@Harry Garst 

It doesn't seem necessary to use two variables.

These are two ways of describing the same variable..

Apparently, the expression hold for all n =1.. 2
proof by induction further

1 2 3 4 5 6 7 Last Page 3 of 88