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

Assignment 5

Uploaded by

cks108823
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

Assignment 5

Uploaded by

cks108823
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/ 14

Week 5.

Linear Algebra

Mathematics for Economics and Business


Python programming Class

Chaeyeon Ahn
[email protected]
1. Linear Algebra

We are going to learn how to solve linear algebra problems using a Python program.

Before we begin, as we learned last week, we need to import a library for utilizing complex mathematical functions
in Python.

For this week, we will be using the 'sympy' library, which is a Python library designed for symbolic mathematics.
2. What is list in Python?

List
Lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types in Python use
d to store collections of data, and lists are created using square brackets.

List items are ordered, changeable, and allow duplicate values.


Its items are indexed, the first item has index [0], the second item has index [1] etc.

Be careful because [3] means the


4th (Python numbering begins with 0)
2. What is array in Python?

An array
An array is a data structure that lets us hold multiple values of the same data type.
An array is used to store more than one value at a time. It can hold multiple values in a single variable, and
helps
you reduce the overall size of the code.
Here are the key distinctions between an Array and a List:

1. Uniform Data Type: All elements must be of the same data type.

2. Fixed Size: You can't change the number of elements.

Python does not provide its own array data types. Therefore, another library must be imported. The standard package forusing
arrays in Python is NumPy.

It is also called as ‘one – dimensional array’ If there are different types of data, it converts it into characters
3. How to make a multi-dimension array?

A multidimensional array refers to an array with two or more dimensions, where each dimension is
essentially an array itself.

In the case of a two-dimensional array, it's often referred to as a matrix.

In a matrix, the horizontal elements are referred to as rows, and the vertical elements are referred to as
columns.

To create a two-dimensional array, you can use a list of lists, where the inner lists represent the rows of the
matrix.

The length of each inner list corresponds to the number of columns in the matrix, and the length of
the outer list
indicates the number of rows in the matrix.
3. How to make a multi-dimension array?

For example, a 3 x 4 array with 3 rows and 4 columns is made as follows.


Each inner list has 4 values, which means
that the n of column would be 4.

The outer list has 3 values, which means


that the n of row would be 3.

However, instead of using array function, we will be using the Matrix function to create
muti-dimensional array under Sympy library.
3. How to make a multi-dimension array?

Matrix and array functions serve similar purposes, but the key difference lies in their coding syntax.

The use of matrix functions is often favored because they provide a more visually intuitive
representation for working with multidimensional data, especially in mathematical and linear
algebra contexts.

Using array function Using Matrix function


4. How to make a matrix?

Step 1.
For any equation with characters, declare
the symbols

Step 2.
Create the matrix using the Matrix
function

Step 3.
Flip the matrix (horizontal vertical) using
the transpose() function
4. How to make a matrix?

The length of Outer list: 2

The length of Inner list: 2


The length of inner list: 4

The length of outer list: 1


4. How to make a matrix?

You need to exercise caution when creating a Matrix


because even a slight difference in the code can lead to significant variations in the outcome.
5. How is a matrix calculated?

Step 1.
Declare the 2x2 matrices A and B
5. How is a matrix calculated?
5. How is a matrix calculated?

Example
Try the examples using variables

Use the “+Text” button and


write your explanation on
which one works and why
the other equation leads to
an error
6. Assignment

Given the following matrices,

(1) Calculate A+B


(2) Calculate A*B
(3) Calculate B*A
(4) Calculate the transpose of A

1 3 9 8
A= 5 7 ,B= 6 7

* If you use click the code button, you can create your own code.
-> There should be 4 codes to complete the assignment

You might also like