Question

# 1. Create a function that calculates N!, where N is an input variable to the function....

1. Create a function that calculates N!, where N is an input variable to the function. Use a for loop and calculate the factorial without using the factorial function built into MATLAB.

2. Prof. Sky wants to retire when his retirement account first reaches or exceeds \$2,000,000. He deposits \$20,000 at the beginning of every year into the account which pays 9% interest per year, compounded annually. Create a function that calculates how many years Prof Moss will have to teach before he can retire? (Hint: assume a \$20,000 initial balance for year 0.)

3.Generate a vector of 1 million random numbers that are normally distributed. Plot the points in a histogram with 100 bins.

Matlab Code:

function [ fact ] = factorialNumber( N )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
fact = 1;
for i = 1:1:N
fact = fact*i;
end

------------------

Sample Run:

>> factorialNumber( 4 )

ans =

24

>> factorialNumber( 5 )

ans =

120

>>

------------------------------------------

Matlab Code:

r = rand(1,1e6);
hist(r,100)
xlabel 'bins'
ylabel 'Random Value'
title 'Histogram of Random Numbers'

-------------------------------

Result: ---------------------------------------------------------

Matlab Code :

clc;clear;

year = 0;
amount = 20000;

while (amount < 2000000)

amount = amount + ((amount*9)/100);
year = year + 1;

end
sprintf('No of Years Reuired = %d',year)

----------------------------------------

output :

ans =

No of Years Reuired = 54

-----------------

Dont Forget to hit like....

#### Earn Coins

Coins can be redeemed for fabulous gifts.

##### Need Online Homework Help?

Most questions answered within 1 hours.

##### Active Questions
• Sharp Company manufactures a product for which the following standards have been set: Standard Quantity or...
• Case 12.1 Determine what variables are categorical (either nominal or ordinal scales), perform the appropriate descriptive...
• GDebi Enterprises is thinking of building a chemical processing plant to produce 4-hydroxy-3-methoxybenzaldehyde. The firm estimates...
• Suppose you are picking one number from the set of natural numbers from 97 to 4....
• What is the wavelength (in meters) of photons with the following energies? Part A.) 136 kJ/mol...
• In your own words, define nonverbal communication and explain three differences between verbal and nonverbal communication...