#include #include /****************************************************************************/ struct PaymentInfo { double Payment; double Principal; double Interest; double Balance; }; /****************************************************************************/ class Mortgage { public: enum { SOLVEPAYMENT, SOLVETIME, SOLVERATE }; int LONGESTPERIOD;


This diagram describes the operation of the bisection root finding algorithm. This method is similar to the binary search algorithm in its searching method and assumptions. The general idea of this algorithm is simple, however in order for it too work the following assumption must be true: The function must either be in increasing or decreasing order. Here is the general algorithm is listed order.
  1. First, choose a midpoint value of the list and evaluate this value for a possible match for the root of the function.
  2. If the function given the midpoint value evaluates to a value greater than zero, it means that the midpoint value is too high. In this case, we choose another midpoint value by averaging the current midpoint value with the lower bound value of the function. (If the function is in decreasing order than then we average the current midpoint with the upper bound value instead)
  3. If the function given the midpoint value evaluates to a value less than zero, it means that the midpoint value is too low. In this case, we choose another midpoint value by averaging the current midpoint value with the upper bound value of the function. (If the function is in decreasing order than then we average the current midpoint with the lower bound value instead)
  4. Repeat step 1 to evaluate the new midpoint value and step 2 and 3 as necessary until a matching value for the root of the function is found.
int CheckArguments(int Flag_); void Display(); }; /****************************************************************************/ Mortgage::~Mortgage() { int i; for (i = 0; i < _ArrSz; ++i) delete _PayInfo[i]; delete[] _PayInfo; } /****************************************************************************/ Mortgage::Mortgage() { _ArrSz = 0; _PayInfo = MakePaymentArray(50); LONGESTPERIOD = 6000; EPSILON = .001; _SolveFor = SOLVEPAYMENT; LoopIter = 0; TotalTime = 0; Payment = 0; PayPeriod = 0; Price = 0; Rate = 0; Compounding = 0; Equivalent = 0; Effective = 0; Min = 0; Max = 0; LowerBound = 0; MinPayment = 0; } /****************************************************************************/ PaymentInfo** Mortgage::MakeArray(int Sz_) { PaymentInfo** Ptr_ = new PaymentInfo*[Sz_]; _ArrSz = Sz_; return Ptr_; } /****************************************************************************/ PaymentInfo** Mortgage::IncreaseArray(int Sz_, PaymentInfo** Ptr_) { int i; int OldSz_ = _ArrSz; Sz_ += _ArrSz; PaymentInfo** OldArr_ = Ptr_; Ptr_ = MakeArray(Sz_); for (i = 0; i < OldSz_; ++i) Ptr_[i] = OldArr_[i]; delete[] OldArr_; return Ptr_; } /****************************************************************************/ PaymentInfo** Mortgage::MakePaymentArray(int Sz_) { _PayInfo = MakeArray(Sz_); int i; for (i = 0; i < Sz_; ++i) _PayInfo[i] = new PaymentInfo; return _PayInfo; } /****************************************************************************/ PaymentInfo** Mortgage::IncreasePaymentArray(int Sz_) { int i; int OldSz_ = _ArrSz; _PayInfo = IncreaseArray(Sz_, _PayInfo); Sz_ += OldSz_; for (i = OldSz_; i < Sz_; ++i) _PayInfo[i] = new PaymentInfo; _ArrSz = Sz_; return _PayInfo; } /****************************************************************************/ void Mortgage::SetupData() { double Exp_ = double(Compounding) / PayPeriod; Effective = 1 + (Rate / Compounding); Effective = pow(Effective, Exp_); Equivalent = (Effective - 1) * PayPeriod; TotalPeriods = int(floor(TotalTime * PayPeriod)); LowerBound = Price * (Effective - 1); Min = LowerBound + .01; Max = Price * (Effective - 1) + Price / floor(TotalTime * PayPeriod); MinPayment = Price / TotalPeriods; } /****************************************************************************/ double Mortgage::FindMaxRate() { double Exp_ = double(Compounding) / PayPeriod; Rate = Compounding * (exp(log(Min / Price + 1) / Exp_) - 1); Effective = 1 + (Rate / Compounding); Effective = pow(Effective, Exp_); Equivalent = (Effective - 1) * PayPeriod; TotalPeriods = int(floor(TotalTime * PayPeriod)); return Rate; } /****************************************************************************/ double Mortgage::FindMinRate() { double Exp_ = double(Compounding) / PayPeriod; Rate = Compounding * (exp(log((Payment - Price / floor(TotalTime * PayPeriod)) / Price + 1) / Exp_) - 1); Effective = 1 + (Rate / Compounding); Effective = pow(Effective, Exp_); Equivalent = (Effective - 1) * PayPeriod; TotalPeriods = int(floor(TotalTime * PayPeriod)); return Rate; } /****************************************************************************/ double Mortgage::Amortize(double Pay_) { int i; double Result_ = Price; double Interest_, Principal_, OldBalance_; int Limit_ = (_SolveFor == SOLVEPAYMENT || _SolveFor == SOLVERATE) ? TotalPeriods:LONGESTPERIOD; _PayInfo[0]->Payment = _PayInfo[0]->Principal = _PayInfo[0]->Interest = 0; _PayInfo[0]->Balance = Price; for (i = 0; i < Limit_ && Result_ > 0; ++i) { if ((i + 1) >= _ArrSz) _PayInfo = IncreasePaymentArray(50); OldBalance_ = Result_; Result_ *= Effective; Interest_ = Result_ - OldBalance_; _PayInfo[i + 1]->Interest = Interest_; Principal_ = Pay_ - Interest_; _PayInfo[i + 1]->Principal = Principal_; Result_ -= Pay_; _PayInfo[i + 1]->Payment = Pay_; _PayInfo[i + 1]->Balance = Result_; } LoopIter = i; return Result_; } /****************************************************************************/ double Mortgage::FindTime() { double Result_ = Amortize(Payment); TotalPeriods = LoopIter; TotalTime = TotalPeriods / PayPeriod; if (Result_ < 0) { _PayInfo[LoopIter]->Payment = Payment + Result_; _PayInfo[LoopIter]->Balance = 0; } return Result_; } /****************************************************************************/ double Mortgage::FindPayment(double Min_, double Max_) { double Midpoint_; double Result_; while (1) { if (Rate <= 0) Midpoint_ = Min; else Midpoint_ = (Min_ + Max_) / 2; Result_ = Amortize(Midpoint_); if (Result_ < 0 - EPSILON || LoopIter < TotalPeriods) Max_ = Midpoint_; else if (Result_ > 0 + EPSILON) Min_ = Midpoint_; else break; } _PayInfo[TotalPeriods]->Balance = 0; return Midpoint_; } /****************************************************************************/ double Mortgage::FindRate() { double Min_ = FindMinRate(); double Max_ = FindMaxRate(); double Midpoint_; double Result_; while (1) { if (Payment < MinPayment + .01) Midpoint_ = Min_; else Midpoint_ = (Min_ + Max_) / 2; Rate = Midpoint_; SetupData(); Result_ = Amortize(Payment); if (Payment < MinPayment + .01) break; if (Result_ < 0 - EPSILON || LoopIter < TotalPeriods) Min_ = Midpoint_; else if (Result_ > 0 + EPSILON) Max_ = Midpoint_; else break; } _PayInfo[TotalPeriods]->Balance = 0; return Rate; } /****************************************************************************/ int Mortgage::CheckArguments(int Flag_) { if (Flag_ == SOLVEPAYMENT) { if (Price < .01) { cerr <<"Error: Price must be at least $0.01" <Payment <<", " <<"Principal: " <<_PayInfo[i]->Principal <<", " <<"Interest: " <<_PayInfo[i]->Interest <<", " <<"Balance: " <<_PayInfo[i]->Balance < #include #if defined(__TURBOC__) | defined(__DJGPP__) #include #endif void main() { // t = time to pay = 25 yrs // // pay = payment ? // j = equivalent ? // eff = effective ? // pe = pay period: (month, quarter, semi, annaul) // // b = price: // i = interest rate: // com = compounding: // // (1 + i / com)^com == (1 + j / pe)^pe // eff = (1 + j / pe) // // tol = EPSILON // min = b * eff + tol // max = b * eff + b / (t * pe) // // use newton's method to narrow from min to max #if defined(__TURBOC__) | defined(__DJGPP__) clrscr(); #endif Mortgage mobj; char Buffer[32]; cout <<"Solve For: (P)ayment Value, Interest (R)ate, Total (T)ime "; cin.getline(Buffer, 32); if (toupper(*Buffer) == 'P') mobj.SolveFor(Mortgage::SOLVEPAYMENT); else if (toupper(*Buffer) == 'R') mobj.SolveFor(Mortgage::SOLVERATE); else mobj.SolveFor(Mortgage::SOLVETIME); if (mobj._SolveFor != Mortgage::SOLVETIME) { cout <<"Enter Total Time (In Years): "; cin.getline(Buffer, 32); mobj.SetTotalTime(atof(Buffer)); } if (mobj._SolveFor != Mortgage::SOLVEPAYMENT) { cout <<"Enter Payment Value: "; cin.getline(Buffer, 32); mobj.SetPayment(atof(Buffer)); } cout <<"Enter Payment Period (12=Monthly, 4=Quarterly, 2=SemiAnnually, 1=Annually): "; cin.getline(Buffer, 32); mobj.SetPayPeriod(atoi(Buffer)); cout <<"Enter Price: "; cin.getline(Buffer, 32); mobj.SetPrice(atof(Buffer)); if (mobj._SolveFor != Mortgage::SOLVERATE) { cout <<"Enter Interest Rate: "; cin.getline(Buffer, 32); mobj.SetRate(atof(Buffer)); } cout <<"Enter Compounding Period (12=Monthly, 4=Quarterly, 2=SemiAnnually, 1=Annually): "; cin.getline(Buffer, 32); mobj.SetCompounding(atoi(Buffer)); mobj.SetupData(); if (mobj.FindResults()) mobj.Display(); else cout <<"Error In Calculating Results" <Sitemap
Top Line Computer Consulting Resources

it becomes easier for the best SEO company to plan out an SEO campaign that is useful for a successful online promotion. the best SEO company looks for relevancy and reputation of the sites, anchor text of the links and PageRank of the linking page for inbound links to their clients’ websites.