- Details
- Parent Category: Programming Assignments' Solutions

# We Helped With This MATLAB Programming Homework: Have A Similar One?

Category | Programming |
---|---|

Subject | MATLAB |

Difficulty | Undergraduate |

Status | Solved |

More Info | Pay For Matlab Homework |

## Assignment Description

**MAE 8 -
Fall 2017 Homework 6**

**Instructions: **Follow
the homework solution template. Put all answers in a MATLAB script named **hw6.m**.
For this homework, you will need to submit multiple files. Create a zip archive
named **hw6.zip**. The zip archive should include the following files: **hw6.m**, **f.mat**, and **testpi.m**. Submit **hw6.zip **through TritonED
before 9 PM on 11/17/2017. Use

double precision unless otherwise stated.

**Problem 1: **Italian mathematician
Fibonacci is famous for introducing the 'Fibonacci
series' to modern
mathematics. Any term in the Fibonacci series is the sum of the previous two
terms. For example, the first 5 terms of the series are

1*,*1*,*2*,*3*,*5

Use **for **loops
(nested with **if - break / continue **statement when needed) in the
following exercises.

(a) Compute the
first 50 terms of the series and put the answer in vector **p1a**.

(b) In a single **for **loop,
find the combined sum of the first 10 terms and the last 15 terms of the series
in part (a). Put the answer in **p1b**.

(c) Find the sum of
the first 50 terms of the Fibonacci series excluding every fifth terms.Put the
answer in **p1c**.

(d) How many terms of the
Fibonacci series are needed such that the sum of the termsis at least 90,000?
Put the answer in **p1d**.

(e) How many terms of the Fibonacci series are needed such that the
product of theterms is at least 90,000? Put the answer in **p1e**.

**Problem 2: **Use
function **inv **to solve for values of x’s in the following linear system
of equations: A x = b. Note that the coefficient matrix A is tridiagonal. Put
the answer in the 30-element vector **p2**. Hint: use **for **loop nested
with **if **statement or function **diag **to construct the matrix.

3 | − | − |

− | − | − |

− | − | − |

− | − | − |

− | − | − |

− | − | − |

− | − | − |

− | − | − |

− | − | − |

− | − | − |

**Problem 3: **Download
the file **f.mat **and load it into MATLAB. The file contains vector **f**.
Without writing any loops or conditional statements, perform the following
exercises.

(a) Replicate each
element in **f **3 times and put the answer in **p3a**. For example, if f
= [2 4 6], p3a should be [ 2 2 2 4 4 4 6 6 6]. Explore function **repelem **or
the following statement: **f(ceil((1:n*end)/n)) **with n = 3.

(b) Shift the elements in **f **3 indices to the right and put the answer in **p3b**. For example,
if f = [2 4 6 8], p3b should be [4 6 8 2]. Explore function **circshift **or
the following statement: **f(mod((1:length(f))-k-1,length(f))+1) **with k =
3.

(c) Find any values
in **f **that are greater than 1 and less than 2, and replace them with 0.
Put the answer in **p3c**. Vector **p3c **should have the same dimension
as **f**.

(d) Extract all values in **f **that are greater than 1 and less
than 2 and put them in **p3d **in the same order as they appear in **f**.

**Problem 4: **Leibniz found that *π *can
be approximated by the following series:

*.*

Madhava (with Leibniz) later suggested an alternative series:

*.*

In this exercise,
you are asked to write a function **testpi.m **to compare how fast the two
series can approximate the value of *π *for a given tolerance. The
function should have the following declaration: **function [api, nterm] =
testpi(tol, method) **where **tol **is the input tolerance defined as the
absolute difference between the approximated *π *and the default value of *π *in MATLAB divided by the default value. **Method **is a string input
being either '**Leibniz**' or '**Madhava**'.
The function outputs are the approximated value of *π ***api **and the
number of terms **nterm **in the series needed to compute the approximate
value.

In the function, you may want to consider the relationship
between **abs(api-pi)/pi **and **tol **as a condition to truncate n in
the two series above. Give the function a description. In the following
exercises, set the tolerance to 10^{−7}.

(a) Set **p4a=evalc(**'**help
testpi**'**)**.

(b,c) For the Leibniz series,
what is the approximated value of *π *and how many terms of the series are
needed to compute that value? Put the answers in **p4b **and **p4c**,
respectively.

(d,e) For the Madhava series,
what is the approximated value of *π *and how many terms of the series are
needed to compute that value? Put the answers in **p4d **and **p4e**,
respectively. (f) Which method converges faster? Give answer in **p4f = **'**... series converges faster**'.