Solved–Homework 1 –Solution

$30.00 $19.00

Explain what the following Matlab code does x= -10:10; x= 0:0.01:1; x= 10:-1:-10; 2. Find the function value of y = 3×2 using 101 equally spaced points in [ 1; 1]. Plot the all the isolated points in x y plane using the \plot” command. Be sure to give your graph a title, label the…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

5/5 – (2 votes)
  1. Explain what the following Matlab code does

    1. x= -10:10;

    1. x= 0:0.01:1;

    1. x= 10:-1:-10;

2.

Find the function value of y = 3x2 using 101 equally spaced points in [ 1; 1]. Plot the all the isolated

points in x y plane using the \plot” command. Be sure to give your graph a title, label the x and

y axis, and display a legend. You only need to submit your graph.

3.

Write a Matlab code using for loop to de ne the following sequence.

2xn

1; if xn > 1=2:

x0 = 1=3; xn+1 =

2xn;

if xn 1=2;

  1. The golden ratio shows up in many places in the nature. This ratio gets its name from the golden rectangle shown below. This rectangle has the property that removing a square leaves a smaller rectangle of the same proportions as the original.

Taking the ratio of corresponding sides gives

1

=

1

. Rearranging, we have the quadratic equation

1

21=0.

    1. Find the two roots of this quadratic by hand. The positive root is the golden ratio.

    1. Find its zeros via the \fzero” command.

  1. The Fibonacci Sequence is de ned recursively as

fn = fn 1 + fn 2; f1 = 1; f2 = 2:

(a) Write a Matlab function f = fibonacci(n) which returns a vector containing the rst n terms of Fibonacci numbers.

(b) Estimate the term-by-term growth rate of the Fibonacci sequence. To do this, compute the rst

40 Fibonacci numbers via the function in part (a), then compute ratios n = fn+1 . What does fn

the value of n seem to approach? Explain your thought on the connection between the Fibonacci sequence and the golden ratio.

1

(c) Consider the matrices

1 1

A =

1 0

i. Computer An for n =1:5, or more if necessary. Compare your nding with the Fibonacci number. Explain why.

      1. Use Matlab to compute the eigenvalues of matrix A. What is the result? How is your nding connected to the Fibonacci sequence thus the golden ratio?

  1. In Matlab construct the following sequence.

Start with a random positive integer If an = 1, terminate;

If an is even an+1 = an=2 If an is odd an+1 = 3an + 1

    1. Write a Matlab function y = threenplus1(n) returning a vector y which is the entire sequence generated by positive integer n. (Hint: Use a while loop and if statements.)

    1. Write a Matlab script to compute the sequences generated by integers 2 through 10. Plot them all in the same graph.

    1. The 3n + 1 sequence has a particular shape for n starting at 5; 10; 20; 40; 80; : : : Why?

    1. The graphs of 3n + 1 sequences are all quite similar for n = 108; 109; 110. Why?

    1. (Challenge) Does the sequence always terminate? Can you nd a value of a1 such that the sequence has in nitely many terms? (That is, the sequence never terminates.)

  1. (Challenge) Consider organizing the positive integers in an n n array in a spiral fashion as illustrated in the below picture. Note the prime numbers are highlighted in red. The location of these primes forms what is called an Ulam prime spiral. By plotting points, this spiral is hilighted in the next image for the 200 200 case. Write a Matlab script which replicates the second image. Generate your own image for the 400 400 and 800 800 cases. For more on Ulam prime spirals, see http: //blogs.mathworks.com/cleve/2015/01/05/prime-spiral/.

2