![]() ![]() While loops - Taylor series expansion The Taylor series expansion for the exponential function e x is given by: e x = 1 + x + 2 ! x 2 + 3 ! x 3 + 4 ! x 4 + ⋯ Using a while loop, create a function called taylorExp () that takes a value for x as an argument, and returns two values: (a) the Taylor series approximation of e x that is within a tolerance limit of 1 e − 10 (that is, such that successive terms in the expansion are equal to or below this limit), and (b) the number of terms that were required to yield this approximation. As with the previous problem, your function must work for any size input arrays. The easiest way to do this is by implementing the vector multiplication step from Problem 1 using an additional loop. In other words, where Problem 1 allowed you to multiply entire rows and columns of the matrices together, here you may only multiple scalar values. For loops - matrix multiplication using scalar operations Add a new matrixmult2 () function to your m-file that performs manual matrix multiplication as in Problem 1, but this time using nested for loops and scalar multiplication. ![]() the inner dimensions are equal), and return a null (empty) array if this criterion is not met. Your function must also check whether the matrix dimensions are appropriate to allow for their multiplication (i.e. ![]() Once your basic code is working, use it to create a custom function called matrixmult () that accepts 2 matrices as input arguments, and returns the product of those matrices. Your code must work with any size matrices. For example: given A = and B = then we can represent A as a column vector of row vectors, and B as a row vector of column vectors, i.e.: A = and B =, where A i are row vectors and B i are column vectors, such that: AB = Using your knowledge of Matlab for loops, develop code that performs matrix multiplication manually (without simply multiplying the full A and B matrices together!) using a pair of nested for loops and 1-D vector multiplication. Recall that for two matrices A and B, element (m,n) of AB is given by the dot product of the m th row of A and the n th column of B. For loops - matrix multiplication using vector operations Matrix multiplication is handled elegantly by Matlab, but it is a useful exercise to implement matrix multiplication "by hand" using your own custom Matlab code. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |