In this chapter, new functions that are used in the examples are first defined. Following that, simple and compound interest, percentage change, and cost, revenue, and profit topics are examined in different sections. Before the examples are presented, necessary formulas used in the solutions are explained in each section.
Preliminaries
Here, using matlabFunction(y), the equation for y is converted to a MATLAB function. After that y(2), and y(3) are evaluated with the MyFunc function.
Simple and Compound Interest
Interest is the fee paid to borrow money. In most cases, interest is paid when people put their money in bank accounts (i.e., into savings accounts), depending on the contract. In general, two types of interest are calculated, simple and compound interest.
Simple Interest
where I is the interest, P is the principal, R is the annual interest rate, and T if the time measured in years.
Example 3-1. Write code to calculate payment amount for a certain principal loan, annual rate, and time in months for a bank. The code should ask the user these values, and should print the total payment and interest paid on the screen.
Solution 3-1. The following code can be used to accomplish the given task.
Example 3-2. Omar put $80,000 into a bank with a 35% annual interest rate. He plans to withdraw his money at the end of 19 months after depositing it. The bank allows customers to withdraw their funds monthly as well. Write code to calculate the amount of money he will ger at the end of 19 months.
Solution 3-2. The following code can be used to accomplish the given task.
Compound Interest
An Illustration
Period | Interest | Balance |
---|---|---|
Starting | $100.00 | |
4 months | $100.00*5%=$5.00 | $105.00 |
8 months | $105.00*5%=$5.25 | $110.25 |
12 months | $110.25*5%=$5.51 | $115.76 |
16 months | $115.76*5%=$5.79 | $121.55 |
Example 3-3. Write code to calculate the total balance with a compound interest rate for the information given in Table 3-1.
Solution 3-3. The following code can be used to accomplish the given task.
Example 3-4. Jennifer puts $150,000 into a bank account that pays a compound interest rate annually of 12%. If she gets her money from the bank after 5 years, how much interest does she get?
Solution 3-4. The following code can be used to accomplish the given task.
Percentage Change
More than x% of A =
Less than x% of A =
% change = percent
Example 3-5. Martin’s annual salary is $50,000 this year. He will get a 20% raise for the next year. What will Martin’s annual salary be for the next year?
Solution 3-5. The following code can be used to calculate the salary.
Example 3-6. Martin’s market sells melon with a 40% markup at $28 per kilogram. If he wants to sell it with a 20% discount from the original cost, how much does the melon cost Martin per kilogram? Write code that shows the cost and price after discount.
Solution 3-6. The following code can be used to calculate the cost and discounted price.
Example 3-7. A bookstore sells a book at $50 and the price was reduced to $35. What is the percentage change on the price of the book?
Solution 3-7. The following code can be used to calculate the percentage change.
As shown in the output, there is a negative (-) sign in front of 30.00. That indicates that the price has decreased. If it is positive (+), then it indicates that there is an increase.
Cost, Revenue, and Profit
In all businesses, keeping a clear and proper financial account is extremely important. Calculation of cost, revenue, and profit plays an important role in this regard. In this section, we deal with these three important concepts.
Cost
The marginal cost is represented by m, and b represents the fixed costs.
Example 3-8. Alexander’s biking company produces bike to sell. Production of each bike costs the company $50 and other fixed costs of the company are $35. Write code to calculate the total cost of produced bikes. The code should ask the for number of bikes produced to complete the calculation.
Solution 3-8. The following code can be used to accomplish the given task.
Revenue
In this equation, R represents revenue, Q represents the number of items sold, and P represents the price of each item sold. Finding the total revenue by using the given formula is not that difficult. There are questions that require the user to find the maximum revenue in different cases. The next example is such a question.
Example 3-9. Alexander’s cinema company sells tickets for a film showing. The cinema has 1,000 seats. One ticket costs $8 currently. Alexander wants to increase the price. From past experience, he thinks that if he increases the price $0.50 for each ticket, then 50 fewer people will attend the showing. Find the price of a ticket that maximizes revenue.
Solution 3-9. Let x be the number of $0.50 increases. Therefore, $8.00 + $0.50x represents the price of one ticket and 1,000 - 50x represents the number of tickets sold. Then the revenue can be calculated as R = (1000 − 50x) ∗ (8.00 + 0.50x). From here, we can write R = − 25x2 + 100x + 8000. The following code can be used to accomplish the given task. Then we need to find an x value that maximizes the R value. This is the part where we need to enter into the code and solve for x to make R the maximum value. The following code can be used to achieve this.
In this code, the R function is entered as a symbolic function. Then its derivative is found by using the diff function. The obtained linear equation is solved by using the solve function. The obtained Number value shown is a symbolic data value. To convert it to a floating number, the double function is used. In the meantime, the R symbolic function is converted to a MATLAB function to evaluate R at x=Number value. Finally, the maximum value is shown with the disp function.
Remark 3-1. For quadratic equations (i.e., f(x) = ax2 + bx + c, a ≠ 0 and a, b, c ∈ R), maximum value or minimum value can be calculated depending on the sign of a. If the sign is negative (-), then the maximum value can be derived from the equation. If the sign is positive (+), then the minimum value of the equation can be found. This can be done in two ways. In the first way, gives us the maximum or minimum value. In the second case, the derivative of f(x) is calculated, and the f′(x) = 0 equation is solved. The root of f(x) gives us the maximum or minimum value depending on the sign of a as well.
In the preceding problem, the second method is preferred for finding the maximum value.
Profit
where Pr stands for profit, R stands for revenue, and C stands for cost.
Example 3-10. A company sells t-shirts with cost function C(x) = 3 + 2x, and the revenue function is R(x) = − x2 + 4x + 12 where x indicates the number of t-shirts. For the maximum revenue value R, find x. Then by using the same x, calculate cost (C) and profit (Pr).
Solution 3-10. The following code can be used for the solution.
Problems
3.1. Bushra put her $180,000 into a bank with a 25% annual interest rate (simple). She plans to withdraw her money at the end of 34 months after depositing. The bank allows customers to withdraw their funds monthly as well. Write code to calculate the amount of money Bushra gets at the end of 34 months.
3.2. Alexander puts $240,000 into a bank account that pays a compound interest rate of 20% annually. If he gets his money from the bank after 8 years, how much interest does he get?
3.3. David’s market sells watermelon with a 30% markup at $39 per kilogram. If he wants to sell it with a 10% discount from of the original cost, how much does the watermelon cost David per kilogram? Write code that shows the cost and price after discount.
3.4. A coffee shop sells a mug for $20 and then changes the price to $25. What is the percentage change on the price?
3.5. Benjamin’s biking company produces bikes to sell. The production of each bike costs the company $40 and other fixed costs to the company are $25. Write code to calculate the total cost of the bikes produced. The code should also calculate the cost of producing seven bikes.
3.6. Lily’s cinema company sells tickets for a film showing. The cinema has 1,200 seats. One ticket currently costs $10. Lily wants to increase the price. From past experience, Lily thinks that if she increases the price $0.50 for each ticket, then 20 fewer people will attend the showing. Find the price of the ticket that maximizes revenue.
3.7. For a given function R(x) = 2x2 − 4x + 2 find the minimum value of R(x). Explain the possibility of finding the maximum value of R(x).