IC152 - Matrices Norms and Probability Assessment

Download Solution Order New Solution

Assignment Task

You must keep filenames as mentioned in the assignment since the assignments will be auto evaluated via a script. There are 5 problems , each for 10 marks. and 10 marks are for viva.

Problem fi: Matrices Write a python script to generate two random matrices and create text files txt and MatB.txt to save two different matrices.

Take the number of rows and number of columns as command line arguments: r1 c1 r2 c2. r1 and c1 are rows and columns of the first matrix, r2 and c2 of second.

Each line of the files should have space separated row elements, and line number should represent row So, the format of the files will be (a(i,j) means value at ith row and jth column)

rows, columns

a(1,1) a(1,2) a(1,3) . . . a(1,c)

a(2,1) a(2,2) a(2,3) . . . a(2,c)

a(r,1) a(r,2) a(r,3) . . . a(r,c)

Save the python filename as problem1a.py.

  1. Create two files using previous code (try different inputs for this question). Take two input files via command line arguments, perform matrix operations. Using numpy, perform addition and multiplication of the two matrices and save them in files with name “addOp.txt” and “multOp.txt” in same format as in previous part (a). Give an appropriate error message if the matrices are not compatible and handle corner

Save the python filename as problem1b.py.

Problem 2: Search the file ‘datafile.dat’ for the numbers 100831, 24, 43479 and 70125. Estimate the time taken to search through the entire data using:

  1. A Python list
  2. A Python dictionary
  3. A Numpy array (ndarray)

Extend the script to repeat the search for 10 times and find mean time taken for each of the processes.

Note: Time can be estimated by importing time library as follows: import time

start = time.time() #execution of the function end = time.time()

total_time = (start-end)

Save the python filename as problem2.py, and save the times in a file with name problem2Op.txt with mean time using list in line 1, mean time using dictionary in line 2, and mean time using Numpy array in line 3.

Problem 3: Write a Python script to solve system of Linear Equations Ax=B, where A is a N X N matrix with N <=3 and B is N X 1, as follows (use gaussian elimination or numpy.linalg library)

Take input matrices A and B from the user in the form of files, with their names as two command line arguments similar to inputs in problem 1b.

  1. Check for the nature of the solution (No solution, Unique solution, Infinite solutions). Save the nature of the solution in the first line of file “problem3aOp.txt”. Save the python filename as py.
  2. Solve the System of Linear Equations with Numpy. In case of unique solutions or infinite solutions, save one of the valid solutions in “problem3bOp.txt” in the same format as of problem Save the python filename as problem3b.py.

Problem 4: Norms

  1. Vector Norm

If vector x = [x1, x2, … , xn],

Then, nth norm of vector x = ||x||n = (|x1|n + |x2|n + … + |xn|n)(1/n) Interestingly,

  • norm 0 of x represents the number of non-zero values in
  • norm 1 of x represents the sum of absolute values of the elements in x.
  • norm 2 of x represents the square root of the sum of squared values of the elements in
  • norm infinity represents the largest magnitude among absolute values of the elements in x.

Take a matrix in the form of a file, with its name as two command line arguments similar to one of the inputs in problem 1b. Find the norm 0, norm 1,norm 2, norm 3, and ‘infinity norm’ of each row and save it in file “problem4aOp.txt” with a line of space separated values. (line number should represent row number of matrix. Leftmost value in each line should represent norm 0, and the right most value should represent the infinity norm). Handle corner cases (if any).

Save the python filename as problem4a.py.

  1. Matrix Norm
    • Norm 1 of the matrix is the maximum column sum after absolute values are taken.
    • Norm 2 of a matrix is equal to the norm 2 of a vector created by concatenating all its rows
    • Norm infinity of matrix is maximum row sum after absolute values are taken.

(you do not need to find norm 0 for the matrix)

Take a matrix in the form of a file, with its name as two command line arguments similar to one of the inputs in problem 1b. Find the norm 1,norm 2, and infinity norm of the input matrix and save it in file “problem4bOp.txt” with a line of space separated values. (leftmost value should represent norm 0, and right most value should represent infinity norm).

Handle corner cases (if any).

Save the python filename as problem4b.py.

Problem 5: Statistical Regularity and Central Limit Theorem

  • Consider an experiment where you pick up a ball at random out of four balls having numbers 0, 1, 2, and 3. Simulate the experiment of 50 trials using a random package (random.randint(0,3)) and plot the relative frequency of each observed value vs number of trials. Then repeat the experiment 500 times. Then repeat the experiment 5000 times and 50000 times. Save the three plots as problem5a_50.png, problem5a_500.png, problem5a_5000.png, and problem5a_50000.png. Share your observations with the lab TAs or lab Instructor.Save the python filename as problem5a.py.
  • Central Limit Theorem states that the distribution of sample means approximate the normal distribution as sample size gets Plot the histograms of sample means (observed values) of 5 trials in the previous experiment, by repeating it 50000 times and verify. Save the plot as problem5b_5_50000.png.

Run the code with 50 trials instead of 5 in each repetition of 50000. Save the plot as problem5b_50_50000.png.

Share your observations with the lab TAs or lab Instructor. Save the python filename as problem5b.py.

Create the folder having your python files and inputs/outputs, with name having your roll number followed by “_assignment7” (don’t use inverted commas in folder name), compress the folder with .zip extension and submit it on moodle. Important: If you copy the assignment or any of its parts from others or share with others, our plagiarism softwares will catch it and you will be awarded 0 marks for the whole assignment or F grade for the course.

This It Computer Science have been solved by our PhD Experts at My Uni Paper. Our Assignment Writing Experts are efficient in providing a fresh solution to this question. We are serving more than 10000+ Students in Australia, the UK, and the US by helping them to score HD in their academics. Our Experts are well-trained to follow all marking rubrics and referencing styles.

Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.