Programming Assignment: System of Linear Equations C1_W2

can anyone help me withe the C1_W2_Assignment,please?!

asked your problem here .

1 Like

Exercise 3:
I want to create 3 functions

  1. multiply Row by a number
  2. Sum 2 rows and replace it with another row
    3 . Swap between Rows

They give this instruction for example, i tried many times, but, i couldn’t write the correct code​:smiling_face_with_tear:

#def AddRows(M, row_num_1, row_num_2, row_num_1_multiple):
#M_new = M.copy()
# multiply row_num_1 by row_num_1_multiple and add it to the row_num_2,
# exchanging row_num_2 of the matrix M_new with the result
#None = None
#return M_new

OKey The Problem is very Easy

Firstly
First He asks you to multiply row by a number this method is called broadcasting
let’s assume :
matrix A = \begin{bmatrix} 2 && 3 \\ 1 && 2 \end{bmatrix} and you want to multiply it by a number 3 the result is \begin{bmatrix} 6 && 9 \\ 3 && 6 \end{bmatrix}
explain : when you apply this way python (NumPy) make 3 as a matrix like \begin{bmatrix}3 && 3 \\ 3 && 3 \end{bmatrix}
and multiply every number with his parllel number in other matrix
So You can make multiplication in many ways(using np.multiply(), using python “*”)
So here M_{new}[row_1] = row_{num1multiple} * M_{new}[row_2] and return it

Secondly
he asks you how to sum 2 rows and replace it with another row
like the above operation (multiplication) you can use the same way

Thirdly
Swap two rows
swapping is very easy in python

      a = 10
      b = 11 
      # You Can Swap Two Values of a, b by this method 
      # Here we use two variables 
      a, b = b, a 
      print(a) # a = 11
      print(b) # b = 10 
     
      # In lists 
      list1 = [1, 2, 3]
      list2 = [5, 8, 9] 
      list1[0], list2[0] = list2[0], list1[0]
      print(list1)  # result = [5, 2, 3]
      print(list2)  # result = [1, 8, 9] 
    
     """ You Can Do the Same Operation In NumPy """
     # Please Try On It, If You didn't solve it and need solution contact with me

I hope this will help
Your Friend Atef

1 Like

Thanks alot for helping, i understood the concept :bulb:
But i face some difficulties writing the code, i will try again and confirm you :smiley:

Thanks again
joud