Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


MACM 203 Assignment 1

Spring 2022


Write your solutions as a single Matlab Live Script and export the script to PDF. Write the course number and assignment number as the title of the Matlab Live Script, followed by the table of contents, and then create a section for each part of the question.

Keep in mind that your assignment, including the source code, is a document that will be read in order to be marked. It has to be very clear and properly formatted.

Assignments should be written individually. You can discuss in groups, but you have to write your assignment yourself. In case of plagiarism SFU policies will be applied.


Preamble

This week’s assignment has two focuses:  writing efficient code, and handling numerical approximations.


Question 1 (15 marks)

Part (a)

Let log(x) denote the natural logarithm of x. Create three arrays A, B , C each of which is a row vector with 107  entries such that

for 1 ≤ k ≤ 107 , as follows:

● The array A is created using a for loop without a pre-initialization of the array.

● The array B is created using a for loop and it is first pre-initialized using the ze¥Оs command.

● The array C is created without using a loop.

For each of the three arrays use the functions ic and Оc to measure the time needed to create it (this includes the pre-initialization for array B). Determine which method is most efficient, and which method is least efficient.



Part (b)

Use Matlab’s function cОs and the built-in constant pi to create the vector

Next, create the vector W containing the exact values of these three expressions as you know them from Calculus. Do not use the cОs function when creating vector W .


Part (c)

Apply Matlab’s equality test == to vectors V and W . Explain the results in words.


Part (d)

Because Matlab generally uses numerical approximations in all computations, testing equality of two vectors (or matrices, or numbers) has to be done in a more robust way. Use the function 〕О¥4 to check that V and W are equal up to a small numerical error. Explain your solution.