0% found this document useful (0 votes)
8 views

Untitled6.ipynb - Colab

The document contains Python code snippets using NumPy and SciPy for linear algebra operations, including solving systems of equations, calculating the transpose, determinant, and inverse of matrices. It also utilizes SymPy to analyze matrix properties such as rank and nullspace. The results of these operations are printed to the console, demonstrating various linear algebra concepts.

Uploaded by

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

Untitled6.ipynb - Colab

The document contains Python code snippets using NumPy and SciPy for linear algebra operations, including solving systems of equations, calculating the transpose, determinant, and inverse of matrices. It also utilizes SymPy to analyze matrix properties such as rank and nullspace. The results of these operations are printed to the console, demonstrating various linear algebra concepts.

Uploaded by

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

9/23/24, 3:24 PM Untitled6.

ipynb - Colab

#1.linearsolve
import numpy as np
import scipy.linalg as la
A=np.array([[1,1,2],[-1,-2,3],[3,-7,6]])
print("A:\n",A)
B=np.array([7,5,1])
print("B:\n",B)
x=la.solve(A,B)
print("x:\n",x)

A:
[[ 1 1 2]
[-1 -2 3]
[ 3 -7 6]]
B:
[7 5 1]
x:
[-0.6 2. 2.8]

#2 a)
D=np.array([[10,2,3],[12,-7,15],[-15,10,-11]])
a=(D.T)
print("transpose of D:\n",a)

transpose of D:
[[ 10 12 -15]
[ 2 -7 10]
[ 3 15 -11]]

#b)
b=np.linalg.det(D)
print(b)

-871.0000000000001

#c
c=np.linalg.inv(D)
print("inverse is :\n",c)

inverse is :
[[ 0.08381171 -0.05970149 -0.05855339]
[ 0.10677382 0.07462687 0.13088404]
[-0.01722158 0.14925373 0.10792193]]

#3 a)

from sympy import *


D=Matrix([[6,18,3],[2,12,1],[4,15,3]])
print(D)

Matrix([[6, 18, 3], [2, 12, 1], [4, 15, 3]])

#b
print("\n Rank",D.rank())

Rank 3

#c
print("\n nullspace",D.nullspace())

nullspace []

#d
print("columnspace is",D.columnspace())

columnspace is [Matrix([
[6],
[2],
[4]]), Matrix([
[18],

https://colab.research.google.com/drive/1Sp6NRSjUgGzGY6szmtDpCjqos7ZoYHBY#scrollTo=h2_mlj02Cfn0&printMode=true 2/3
9/23/24, 3:24 PM Untitled6.ipynb - Colab
[12],
[15]]), Matrix([
[3],
[1],
[3]])]

#4
import scipy.linalg as la
A=np.array([[2,1],[1,2]])
print("A:\n",A)
B=np.array([5,7])
print("B:\n",B)
x=la.solve(A,B)
print("x:\n",x)

A:
[[2 1]
[1 2]]
B:
[5 7]
x:
[1. 3.]

#5
A=np.array([[1,2,3],[4,5,6],[7,8,10]])
print("A\n",A)
B=np.array([3,6,9])
print("B\n",B)
x=la.solve(A,B)
print(x)

A
[[ 1 2 3]
[ 4 5 6]
[ 7 8 10]]
B
[3 6 9]
[-1.00000000e+00 2.00000000e+00 -2.22044605e-16]

Start coding or generate with AI.

https://colab.research.google.com/drive/1Sp6NRSjUgGzGY6szmtDpCjqos7ZoYHBY#scrollTo=h2_mlj02Cfn0&printMode=true 3/3

You might also like