Question: loan_amount = input('1. Enter initial loan amount: '); interest_rate = input('2. Enter the annual interest rate as a decimal: '); numCompound = input('3. Enter the

loan_amount = input('"1". Enter initial loan amount: '); interest_rate = input('"2". Enter the annual interest rate as a decimal: '); numCompound = input('"3". Enter the number of compounding per year: '); payment = input('"4". Enter payment size: '); years = input('"5". Enter number of years until payoff: '); choice = input('Enter which one do you want to calculate (1-5)? '); if choice == 1 fprintf('The initial amount for this loan is: %f ', loan_amount) elseif choice == 2 fprintf('The annual interest rate for this loan is: %f ', interest_rate) elseif choice == 3 fprintf('The number of compoundings per year for this loan is: %f ', numCompound) elseif choice == 4 fprintf('The payment needed for this loan is: %f ', payment) else fprintf('The number of years until payoff for this loan is: %f ', years) end % %%% if (2) might use this code
t=input('Enter time in years to pay off loan: '); L=input('Enter loan size: '); n=input('Enter compoundings/payments per year: '); P=input('Enter payment amount: '); [interest,flag]=bisectint(t,n,P,L)%this will be in a future finance script to call on the following function function[interest,flag]=bisectint(t,n,P,L) fncn=@(r)P*(1-(1+r)^(-n*t))-(r)*L; %this equation is from Kymbol tol=0.5e-6; %tol level provided a=.00001; b=0.3; flag=1; %default flag to 1 if fncn(a)*fncn(b)>0 %% (if a a&b are same sign, they may never bisect to 0) interest=NaN; flag=0; %here flag is changed only if no interest rate exist %to satisfy equation else while ((b-a)/2)>tol %will tol only, not maxits in the while loop, %given the range in which to look for the interest rate, %no maxits is necessary, the function will fail before %the while loop if there is no interest rate that will work. interest=(a+b)/2; %dividing range in half each iteration to close in on root. if fncn(interest)==0 break % program should quit because we found our root elseif fncn(a)*fncn(interest)
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
