Matlab

profilecasey7879
HW22.pdf

MATH 300 HW 2

Chris Kang

Due: July 6, 2020 Mon. (11:59PM)

Compress all the files as a single .zip file and upload to Blackboard. Complete the following tasks in MAT- LAB, and save all the .m files along with all the output .dat files (i.e. save(‘A1.dat’, ‘A1’, ‘-ascii’)). For all open-ended questions, write clear responses in LaTeX.

Problem 1: Practice with Loops and Vectors

(a) Using a for-loop, find all the odd numbers from 1 to 100 and store it as a vector called x. Save x in the file A1.dat.

(b) Using a for-loop, find all the even numbers from −1 to −100 and store it as a vector called y. Save y in the file A2.dat.

The p-norm of a vector v that has n elements is defined as

||v||p = [ n∑

i=1

|vk|p ]1/p

.

You may have seen the Euclidean norm of a vector, often written as ||v|| = √ v21 + ... + v

2 k. This is a short-

hand notation for the 2-norm of a vector.

(c) Use the command sum(x) on the vector x from part (a) to find the sum of the elements of the vector. Then use the command, norm(x, 1), to compute the “1-norm” of vector x. Are the results the same? If so, are the commands sum(x) and norm(x, 1) functionally identical?

(d) Use the command norm(y,Inf) on the vector y from part (b) to find the “∞-norm” of vector y. Then, compare it to the command max(y). Are the results the same? If not, how are they functionally different? Explain what the ∞-norm of a vector is.

(e) Lucas numbers are often referred to as the sister sequence to the Fibonacci numbers. Lucas sequence has the same recursive relationship as the Fibonacci sequence (Ln = Ln−1 + Ln−2), but it has different starting values of L1 = 2 and L2 = 1.

1. Write a for-loop to make a vector that has the first 100 numbers in the Lucas numbers.

2. Modify your Fibonacci sequence, so the first 100 numbers start with the value of zero: F1 = 0, F2 = 1, F3 = 1, F4 = 2, ....

3. Then, find the ratio Ln Fn

and store it as a vector. Save the vector in the file A3.dat.

4. Plot the vector from part (3) with a proper title and x,y-labels. Attach the plot to the LaTeX writeup.

5. Do you think the plot from part (4) converges to a specific number? Explain.

1

6. The closed-formula for the Fibonacci sequence is

Fn = ϕn − (−ϕ)−n

√ 5

= ϕn − (ψ)−n √

5

, where ϕ is the golen ratio and ψ is the conjugate. Google (or Wikipedia) the closed-formula for the Lucas sequence expressed in terms of ϕ (or ϕ and ψ), and solve the limit of the ratio of the two formulas:

lim n→∞

Ln Fn

.

What is this limit? Does this value coincide with your guessed, convergent value from part (5)? Explain and show all the steps.

Problem 2: Bisection Method with a While Loop

In class, we have covered the Bisection method (using a for-loop) that finds the root of the sine function between the values of [1, 5]. Write a Bisection method with a while-loop that finds the root of the function

f(x) = e−x −x2 + 2

between the values of [−5, 5]. Write the function f(x) as a function file (a separate .m file). Use the error tolerance level of “tol = 1e-8.” Save the solved root value in the file A4.dat.

2