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.

ANSWER ALL QUESTIONS

Homework Answers

Answer #1

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....

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions