0% found this document useful (0 votes)
17 views2 pages

Note Ans

The document provides examples of matrix operations using NumPy, including addition, subtraction, multiplication, and transposition. It also demonstrates solving systems of linear equations and finding the inverse of matrices. Additionally, it covers non-linear algebraic equations using the Brent's method and the fsolve function from SciPy.

Uploaded by

yekeentaiwo107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Note Ans

The document provides examples of matrix operations using NumPy, including addition, subtraction, multiplication, and transposition. It also demonstrates solving systems of linear equations and finding the inverse of matrices. Additionally, it covers non-linear algebraic equations using the Brent's method and the fsolve function from SciPy.

Uploaded by

yekeentaiwo107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Matrices

A = [[2,3,4], [5,6,7], [8,9,-1]]


print(A)

#import numpy as array


from numpy import array
A = array ([[2,3,4], [5,6,7], [8,9,-1]])
print (A)

c = array([[2,1],[3,4]])
b = array([[-1,3],[4,5]])
print (c+b)

print (c-b)

print (c*b)

print (c.transpose())

p=b.transpose()

from numpy.linalg import det


print (det(c))

from numpy import array


A = array([[2,3,5],[4,7,9],[2,-1,9]])

print(A[0,:])
print(A[2,:])

print(A[:,0])
print(A[:,1])

from numpy.linalg import det, inv


c = array([[2,1],[3,4]])
print (inv(c))

A = array([[2,3,4], [5,6,7], [8,9,-1]])


print (inv(A))

2 sys of linear equation

from numpy.linalg import solve


import numpy as np
A= [[2,3],[-4,9]]
b= [5,7]
x= np.dot(np.linalg.inv(A),b)
print('The value of x and y = ',x).

A= [[2,3],[-4,9]]
b= [5,7]
x = solve(A,b)
print (x[0])
print (x[1]).

3 solution

# A= [[-1,3,4,5],[0,3,0,-5],[4,0.5,0,3],[9,-3,4,0]]
b= [4,7,5,-3]
x= solve(A,b)
print('X=', x[0])
print('Y=', x[1])
print('Z=', x[2])
print('P=', x[3]).

4 Non Linear Algebraic equations

from scipy.optimize import brentq


import matplotlib.pyplot as plt
from numpy import linspace

def f(x):
return x**3 - x**2 - 1

x = linspace(-10, 2, 50)
plt.plot(x, f(x))
plt.axhline(color= 'b').

root, info =brentq(f,0.5,2, full_output= True)


print(root)
print(info)

#plt,axyline(x=root, color='k').

from scipy.optimize import brentq, fsolve


import matplotlib.pyplot as plt
from numpy import linspace

def f(x):
return x**3 - x**2 - 1
x= fsolve(f,2)
print (x).

You might also like