Question

In: Mechanical Engineering

Use the switch structure to write a MATLAB program to compute the amount of money that accumulates

Use the switch structure to write a MATLAB program to compute the amount of money that accumulates in a savings account in one year. The program should accept the following input: the initial amount of money deposited in the account; the frequency of interest compounding (monthly, quarterly, semiannually, or annually); and the interest rate. Run your program for a $1000 initial deposit for each case; use a 5 percent interest rate. Compare the amounts of money that accumulate for each case.

Solutions

Expert Solution

It is required to use the switch feature to find the amount accumulated for each frequency of interest gained (monthly, quarterly, semi-annually or annually)

It is needed to take user input for interest rate and the initial amount of money. The user input can be taken by using the command input.

Formula for amount is

A = P(1 + r/100n)n

n = 1, 2, 4, 12

 

The MATLAB code is given below:

Input:

% asking the user for principal amount

P = input('Please input initial amount deposited: ');

% asking the user for coumpounding frequency

n = input(['Please input the frequency of interest \n' ...

'Type 1: For Annually \n' ...

'Type 2: For Semi Annually \n' ...

'Type 4: For quaterly \n' ...

'Type 12: For monthly \n']);

% asking the user for rate of interest

r = input('Please input the interest rate: ');

% taking n as switch

switch n

case (1)

Amount = P*(1 + (0.01*r/n))^(n);

disp(['Yearly: ', num2str(Amount)]);

case (2)

Amount = P*(1 + (0.01*r/n))^(n);

disp(['Semi Annually: ', num2str(Amount)]);

case(4)

Amount = P*(1 + (0.01*r/n))^(n);

disp(['Quaterly: ', num2str(Amount)]);

case(12)

Amount = P*(1 + (0.01*r/n))^(n);

disp(['Monthly: ', num2str(Amount)]);

end

Output:

Please input initial amount deposited: 1000

Please input the frequency of interest

Type 1: For Annually

Type 2: For Semi Annually

Type 4: For quarterly

Type 12: For monthly

12

Please input the interest rate: 5

Monthly: 1051.1619

 

The case was run for monthly compounding. Similarly, it was run for other frequencies also the results are shown below:

Frequency

Amount

Yearly

$ 1,050

Bi-Annually

$ 1,050.625

Quarterly

$ 1,050.9463

Monthly

$ 1,051.16


It is required to use the switch feature to find the amount accumulated for each frequency 

Related Solutions

USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Please use MATLAB. Write a program to plot the piecewise function using IF statements and a...
Please use MATLAB. Write a program to plot the piecewise function using IF statements and a FOR loop in MatLab. Use x as the input vector. Plot from -20<=x<=20, increment of 1.   y =   4 x + 10 ,             ? ≥ 9,                   y =      5? + 5,                   0 ≤ ? < 9,                    y =     ?2 + 6? + 8, ? < 0 Plot each segment of the fn with different shaped points and a different color, for...
Write a program to help a small company calculate the amount of money to pay its...
Write a program to help a small company calculate the amount of money to pay its employees. In this simplistic world, the company has exactly three employees. However, the number of hours per employee may vary. The company will apply the same tax rate to every employee The program must be written in Java. Prompt the user for the inputs and store the values in variables Must include all the inputs and outputs listed here and perform the calculations correctly...
In the space provided below write a C program that computes the total amount of money...
In the space provided below write a C program that computes the total amount of money you have stored in your piggy bank. Your program does this by asking you for number of pennies, nickels, dimes, and quarters in the piggy bank and then displays how much money in total is in the piggy bank.
Write a program (MATLAB) which generates exponential random variables, and use it to test the Central...
Write a program (MATLAB) which generates exponential random variables, and use it to test the Central Limit Theorem as follows. For various values of n (say, 5, 10, 20, 50, 100, 1000), generate samples of the random variable Mn = 1/n \tiny \sum Xi where Xi are iid exponential random variables. A very simple method for generating exponential random variables is given on page 196 of the textbook (read that section). Plot the discretized CDF for Mn (an approximation of...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during...
Python programming c++ Write a program that computes the amount of money the cheerleaders raised during their candy bar fundraiser using the following data: 12 bars per case. The candy was sold for $1.00 per bar. Each case cost $8.00. They are required to give the student government association 10% of their earnings. The program should ask the user how many bars were sold. The program should calculate and display the SGA proceed's, the Cheer team's proceeds, and the appropriate...
Write matlab program to compute ∫f(x)dx lower bound a upper bound b using simpson method and...
Write matlab program to compute ∫f(x)dx lower bound a upper bound b using simpson method and n points. Then, by recomputing with n/2 points and using richardson method, display the exact error and approximate error. (Test with a=0 b=pi f(x)=sin(x))
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.  
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m...
Using C++ code, write a program named q3.cpp to compute the total amount of medicine m absorbed by a rabbit, where the rabbit gets 2 pills containing n1 and n2 grams of medicine, respectively, of which the rabbit absorbs 60% and 35%, respectively, and n1 and n2 are input by a user via the keyboard.
9. The purpose of this problem is to use MATLAB to compute the magnitude, phase, and...
9. The purpose of this problem is to use MATLAB to compute the magnitude, phase, and total energy of a Fourier transform. a) Develop a MATLAB routine to plot the magnitude and phase of a given Fourier transform H(jω). The input part of your program will, of course, require that you specify the particular H(jω) of interest, but, once this is done, your program should not depend on the Fourier transform specified. You will need to select an appropriate range...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT