Write a script le that evaluates the product of the rst 10


EXERCISE 1

Enter the following matrices and vectors in MATLAB

(a)Perform the following operations: AB, BA, cB and Ad (use standard linear algebra multiplica- tion).

(b) Construct a 3 × 6 matrix C = [A B ] and a 4 × 3 matrix D = [B].c
(c) Use the "backslash" command to solve the system Ax = b.
(d) Replace A(2; 3) with 0.
(e) Extract the 3rd row of the matrix A.
(f) A row or a column of a matrix can be deleted by assigning the empty vector [] to the row or the column. For instance A(2,:)=[] deletes the second row of the matrix A.

Delete the third row of the matrix B.

EXERCISE 2

Recall that a geometric sum is a sum of the form a + ar + ar2 + ar3 + : : :.

(a)Write a function ?le that accepts the values of r, a and n as arguments and uses a for loop to return the sum of the ?rst n terms of the geometric series. Test your function for a = 3, r = 1=2 and n = 10.

(b)Write a function ?le that accepts the values of r, a and n as arguments and uses the built in command sum to ?nd the sum of the ?rst n terms of the geometric series. Test your function for a = 3, r = 1=2 and n = 10.

Hint: Start by de?ning the vector e=0:n-1 and then evaluate the vector R = r.^e. It should be easy to ?gure out how to ?nd the sum from there.

EXERCISE 3

The counter in a for or while loop can be given explicit increment: for i =m:k:n to advance the counter i by k each time. In this problem we will evaluate the product of the ?rst 10 odd numbers 1 · 3 · 5 · : : : · 19 in two ways:

(a) Write a script ?le that evaluates the product of the ?rst 10 odd numbers using a for loop.

(b) Evaluate the product of the ?rst 10 odd numbers using a single MATLAB command. Use the MATLAB command prod.

EXERCISE 4

Write a script ?le that creates a row vector v containing all the powers of 2 below 1000. The output vector should have the form: v = [ 2; 4; 8; 16 : : : ]. Use a while loop.

EXERCISE 5

Write a function ?le that creates the following piecewise function:

Assume x is a scalar. The function ?le should contain an if statement to distinguish between the di?erent cases. The function should also display "the function is undefined at x = 10" if the input is x = 10. Test your function by evaluating f(1), f(4), f(7) and f(10).

Solution Preview :

Prepared by a verified Expert
Accounting Basics: Write a script le that evaluates the product of the rst 10
Reference No:- TGS01124661

Now Priced at $70 (50% Discount)

Recommended (99%)

Rated (4.3/5)