(Taken from Engineering Computations. An introduction using MATLAB and Excel). W
ID: 3814106 • Letter: #
Question
(Taken from Engineering Computations. An introduction using MATLAB and Excel). When an amount of money P in invested at an annual interest rate of I (expressed as a decimal value, not as a percentage), the total value of the investment A after n years can be computed as follows: A = P(1 + i)^n We wish to find how many years until the investment reaches a desired amount. Test your code for an initial investment of $10,000, a target value of $100,000 and an interest rate of .10. a. Write MATLAB code to find n to the nearest year using a loop. Prompt the user to enter P, the target amount A, and i. Then, loop until the desired amount is reached. b. Write MATLAB code to find the exact number of years using a root-finding technique (either bisection method coded earlier, or (zero). You could use the years found in part a as your initial guess, if you wish. c. Check your answer to part b using Excel Goal Seek.Explanation / Answer
p=input('Enter the initial investment:');
i=input('Enter the rate of interest:');
amt=input('Enter the amount:');
for a=2:100 // looped till 100 to find the year
x=(1+i)^a;
amt1=p*x; // calculating the amount
if(amt1>amt) // if calculated amount is greater than the amount,then the previous year is displayed
disp('Number of years:');
j=a-1;
j
break;
end
end
Output
Enter the initial investment:10000
Enter the rate of interest:10
Enter the amount:100000
Number of years:
j =
1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.