# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .jl
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Julia 1.5.3
#     language: julia
#     name: julia-1.5
# ---

# # Eigenvalue Decomposition

# +
using LinearAlgebra

function test1(N)
    A = rand(N,N)
    S = eigen(A)
    R = zeros(N)
    for n=1:N
        R[n] = norm(A*S.vectors[:,n] - S.values[n]*S.vectors[:,n])
    end
    if norm(R)<1e-10
        return 0
    end
    return 1
end

test1(3)

# +
function test2(N)
    A = rand(N,N)
    S = eigen(A)
    R = zeros(N)
    for n=1:N
        R[n] = cond(A - S.values[n]*I)
    end
    if norm(R)>1e10
        return "Singular"
    end
    return "Not Singular"
end

test2(3)

# +
function test3(N)
    A = rand(N,N)
    S = eigen(A)
    R = zeros(N)
    for n=1:N
        α = S.vectors[:,n]'*A*S.vectors[:,n]
        β = S.vectors[:,n]'*S.vectors[:,n]
        R[n] = S.values[n] - α/β
    end
    if norm(R)<1e-10
        return "Yes"
    end
    return "No"
end

test3(3)
# -

# ## Adjourn

using Dates
println("mahdiar")
Dates.format(now(), "Y/U/d HH:MM")  

StarcoderdataJupyterScriptsDedupFiltered