MatLab Loops Adapted from httpmathboisestateeduwrightcourses

MatLab Loops (Adapted from: http://math.boisestate.edu/-wright/courses/matlab/programmingintro.html) Part 1: Approximating e Write a program that approximates e by computing the sum n. The more terms you keep in the summation, the more accurate your answer will be. (In fact, the series converges to e as n goes to infinity.) Determine how many terms you need to approximate e to 5 decimal places. (Note: This is by no means the most efficient way to approximate e, but the formula is quite spectacular considering it only involves rational numbers...) Provide a sample output with n-1, n=100, n= 1,000 n= 10.000 n 100.000 and n=1,000,000 Part 2: A Tale of Two Banks Two banks are competing for customers on the basis of their respective services, locations and community involvement. However. Bank A pays 3% simple annual interest and Bank B pays 3.5% simple annual interest. Joe Smith is trying to decide which bank is better for him, and favors Bank A for its services, even though they pay less interest than Bank B. However, he wants to know how much less monev he would have at the end of five vears if he chose Bank A over Bank B Help Joe to make this decision by writing a MatLab program to calculate how much less money he would have after 5 vears at Bank A than he would at Bank B. Assume that he would open an account at either bank with S500 and would also deposit an additional S500 at the end of each year. Use fprintf output statements to indicate your answer clearly

Solution

%estimating e
N =[1 100 1000 10000 100000 1000000 ];
for i=1:6
    fprintf(\'For n=%d, e = %f\ \',N(1,i), (1+ (1.0/N(1,i)))^N(1,i) );
end

%Banks
Interests = [0.03,0.035];
years = 5;
for bank=1:2
    amountInBank = 500.0;
    Interest = Interests(1,bank);
    for yr=1:years
        amountInBank = amountInBank*( 1.0 + Interest);   %interest
        amountInBank = amountInBank + 500;   %deposit
    end
    fprintf(\'Amount in bank %d at end of %d years = %f\ \',bank,years,amountInBank);
end
  

 MatLab Loops (Adapted from: http://math.boisestate.edu/-wright/courses/matlab/programmingintro.html) Part 1: Approximating e Write a program that approximates

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site