0

i'm trying to write function called plotting which takes i/p parameters Z, p and q and plots the function

f(y) = det(Z − yI) on the interval [p, q]

(Note: I is the identity matrix.) det() is the determinant.

For finding det(), numpy.linalg.det() can be used and for indentity matrix , np.matlib.identity(n)

Is there a way to write such functions in python? and plot them?

import numpy as np

def f(y):
    I2 = np.matlib.identity(y)
    x = Z-yI2
    numpy.linalg.det(x)
    ....

Is what i am tryin correct? any alternative?

2
  • So, what values does the variables Z, p, q, y take? Commented Mar 24, 2017 at 6:49
  • @kmario23 any integer values , can be specified as variable., for eg, 1,2,3... Commented Mar 24, 2017 at 6:51

1 Answer 1

2

You could use the following implementation.

import numpy as np
import matplotlib.pyplot as plt

def f(y, Z):  
    n, m = Z.shape
    assert(n==m)
    I = np.identity(n)
    x = Z-y*I
    return np.linalg.det(x)

Z = np.matrix('1 2; 3 4')
p = -15
q = 15
y = np.linspace(p, q)
w = np.zeros(y.shape)

for i in range(len(y)):
    w[i] = f(y[i], Z)

plt.plot(y, w)
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.