Show work. Using MATLAB when using guesses if prefered but not required. 6. We a
ID: 3871411 • Letter: S
Question
Show work. Using MATLAB when using guesses if prefered but not required.
6. We already tried the following type of problem using a while loop to search for the answer. Now we have the tools to do it right! Avery can afford to save $80 per month during college. What interest rate will she need in order to have $4,500 when she graduates in 4 years? We finally have the tools to get it right! Remember, with an interest rate of r, in order to save S dollars over N years, we will need to make a monthly deposit M of (1 +/12)12N1 (a) (1 point) Why might we prefer the secant method over Newton's method to solve this equation for r'? (b) (1 point) Use the secant method with Po = 0 and P1-1. It doesn't work. Thinking about our initial guesses and their financial meaning, why might it not work? (c) (3 points) Use better guesses, and find the root. Write the interest rate to 6 decimal places, and write the initial guesses that worked.Explanation / Answer
Part (a)
Newton's method required to compute the derivative of the function to find the root. In this problem it is very deficult to compute the derivative. Secant method does not requir the derivative.
In Newton's method we have to evaluate two function in each loop iteration (function and its derivative) that increase the computational cost. While in Secant method it is required to evaluate only one function per iteration.
Part (b)
The interest rate r can varry from 0 to 1, Po = 0 indicates the depositor will not get anything more after the payment periods (She get back only that she deposited). P1 = 1 indicates the depositor will get twice the amount she deposited.
The output by using the given p0 and p1
>> N = 4; % number of years
>> M = 80; % monthly deposit
>> S = 4500; % amount saved after N years
>> P0 = 0;P1 =1; %initial guess
>> f = @(r) M-S*((r/12)/((1+r/12)^(12*N)-1)); % The function
>> tol = 10^-6; % error tolerence
>> n = 1000; % Maximum number of iterations
>> Secant_method(f,P0,P1,tol,n)
iter f(r) r e(n+1)/(e(n)e(n-1))
___________________________________________________
0 NaN 0.000000
1 71.780092 1.000000
It is clear that at r = 0, f(r) is NAN that means devision by zero occurs and can not be proced further
Part (c)
>> P0 = 0.001; % Updated value of P0
>> Secant_method(f,P0,P1,tol,n) % Call the function again with updated P0
iter f(r) r e(n+1)/(e(n)e(n-1))
___________________________________________________
0 -13.566531 0.001000
1 71.780092 1.000000
2 12.439691 0.159799 0.209843
3 -16.782281 -0.016335 0.683531
4 0.928308 0.084820 0.297589
5 0.062813 0.079518 0.717465
6 -0.000268 0.079133 0.800841
7 0.000000 0.079134 0.743785
>>
The Matlab function Secant_method.m
function Secant_method(f,x0,x1,tol,n) % secant method for finding root of f(x)
iter=1;% intial iteration value
u=f(x0);% function value at x0
v=f(x1);% function value at x1
err(iter)=abs(x1-x0);% error
% displaying the result in tabular form
disp(' iter f(r) r e(n+1)/(e(n)e(n-1))')
disp('___________________________________________________')
fprintf('%2.0f %12.6f %12.6f ',iter-1,u,x0); %result to the screen
while (err(iter)>tol)&&(iter<=n)&&((v-u)~=0) % loop to until converg or reach N iter
iter=iter+1;% increase number of iteration
x=x1-v*(x1-x0)/(v-u);% new approximation of root
x0=x1; % replace the old value in x0 with x1
u=v; % replace the old functional value f(x0) with f(x1)
x1=x;% replace the old value in x1 with new value
v=f(x1);% function value at new x1
err(iter)=abs(x1-x0);% error
if iter < 3
fprintf('%2.0f %12.6f %12.6f ',iter-1,u,x0); %result to the screen
else
fprintf('%2.0f %12.6f %12.6f %12.6f ',iter-1,u,x0,err(iter)/(err(iter-1)*err(iter-2))); %result to the screen
end
end
if ((v-u)==0)% Checking devision by zero occured or not
error(' Division by zero')% if yes display error message
elseif (iter>n)% checking method diverge or not
error(' Method failed to converge')% if yes display message
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.