Thursday, September 3, 2015

Homework 2 Yall

clear, clc
% HomeWork #2
% 1 of 2 in class

a = factor(322) %Factoring number. like a bauss
b = gcd(322,6) %Finding the greatest common denominator. like a bauss
c = isprime(322) %Checking prime number. like a bauss
d = primes(322); %Finding all the prime numbers. like a bass
% The workspace shows that there are 66 primes from 0 to 322. did you
% really want to see them all?
p = rat(16/26) %Approximating p(16th letter in the alphabet) as a rational number.like a bauss
e = factorial(10) %Finding 10!. like a bauss
f = nchoosek(20,3) %How many groups of 3 people can be made from a group of 20. if order doesnt matter. like a bauss
format short g % Returning the format from rat to short g. like a bausss
%% 2 of 2 in class (take home) exercises.
clear, clc

% Context Example: USING THE CLAUSIUS-CLAPEYRON EQUATION
%
% Clausius-Clapeyron equation: ln(Po/6.11) = (dHv/Rair)*[(1/273)-(1/T)]
%
% Stating the problem: Using the Clausius-Clapeyron equation find the
% saturation water-vapor pressure within the temperature range
% of -60F and 120F.
%
% Po = 6.11*exp((dHv/Rair)*(1/273 - 1/T))
%
Tf = [-60:120]; % Temperature range of earth's surface in Fahrenheit. I dont even use Fahrenheit
dHv = 2.453e+6; % Latent heat of vaporization for water (J/kg). vaporize with lazers
Rair = 461; % Gas constant for moist air (J/kg).
Tk = (Tf-32)*5/9+273; % Temperature conversion from Fahrenheit to kelvins. not calvins
A = dHv/Rair;
B = 1./Tk;
Po = 6.11*exp((A)*(1/273 - B));
Table1 = [Tf; Po];
DegF = (' TemperatureFahrenheit ');
SatVapP = (' SaturationVaporPressure ');
Table2 = [DegF, SatVapP] % This will label the top of the columns.
fprintf(' %15.4f %20.4f\n',Table1) % This will align the values under the appropriate titles.
%%
clear, clc
% Homework #2
% Parctice problems
% Problem 1
x = [-2:2]; % Vector x from -2 to +2. that's right
a = abs(x); % Absolute value of each member of the x vector. so like 3 values
b = sqrt(x); % Square root of each member of the x vector. crazy shiz
Table = [x;a;b]'% TABLES!!!!
%%
clear, clc
% Problem 2
y = [-3,3] %Setting members for y vector. y? because I want to
a = sqrt(y) %Using the square root function of the members of the y vector. some more craziness
c = y.^(1/2) %Raising each member of the y vector to 1/2 power. its soooo different
b = nthroot(y,2) 
% NOTES***
% Using the nthroot function of the members of the y vector.
% Values for a and c are the same but matlab does not allow nthroot()
% function to have negative number if the n is an even number.


%%
clear, clc
% Problem 3
x = [-9:3:12] % Creating a vector x from -9 to 12 in increments of 3.
a = x./2 % Dividing each member in the vector by 2.
b = rem(x,2) % Finding the remainder of each member of the x vecter after it has been divided by 2.
c = exp(x) % Raising e to each member of the x vector.
d = sign(x) % Using the sign function. -1 means x value is < 0, 0 means = 0, and +1 means > 0.
Table = [x;a;b;c;d]' % Displaying a table with the values runing top to bottom.

%%
clear, clc
% Homework #2
%
% Problem 1
%Populations tend to expand exponentially, that is, 
%P = P0*exp(rt)
%P = current population  
%P0= original population  
%r = continuous growth rate, expressed as a fraction  
%t = time. 
t=1;
P0=input('Insert initial population ');%Initial population just like the title says....
r=input('Insert growth rate as a fraction ');%Growth rate ...
P = P0*exp(r*t);%Current population. It was a given equation. I dont know that by heart
fprintf('The population will be %f \n',P)


%%
clc, clear
%Problem 2
%The interior of the house is warmed by waste heat from lighting 
%and electrical appliances, by heat leaking in from the outdoors, 
%and by heat generated by the people in the home. 
%An air-conditioner must be able to remove all this thermal energy 
%in order to keep the inside temperature from rising. 
%(a)How much heat must the air-conditioner be able 
% to remove from the home per second?  
b=20;%number of bulbs
bh=b*100;%total bulbs heat
a=4;%number of appliances
ah=a*500;%total appliances heat
outh=3000;%heat getting in
aircon=bh+ah+outh;%how much air needs to be pumped out
fprintf('The air conditioner must be able to remove %f heat from the home per second \n',aircon)
%%(b)One particular air-conditioning unit can handle 2000 J/s. 
%How many of these units are needed to keep the home 
%at a constant temperature?
airh=2000;%air unit performance
airnum=aircon/airh;%number of air units for hot air
airnum=round(airnum);%cant have a percent of air unit
fprintf('The number of air units needed are %f \n',airnum)
%If you replaced the bulbs with CF bulbs which just used 18W, 
%does this chance the number of units required? 
%NOTE, since CF bulbs are more efficient and release less energy as heat,
%then it will reduce the amount of air units needed.
%(c)Allow the user to enter the number of lightbulbs and appliances and 
%calculate the number of air conditioning units required
b=input('Insert amount of bulbs ');%redefine number of bulbs
bh=b*100;%total bulbs heat
a=input('Insert number of appliances ');%redefine number of appliances
ah=a*500;%total appliances heat
outh=3000;%heat getting in
aircon=bh+ah+outh;%total appliances heat
airh=2000;%air unit performance
airnum=aircon/airh;%number of air units for hot air
airnum=round(airnum);%cant have a percent of air unit
fprintf('The number of air units needed are %f \n',airnum)

%%
clc, clear
%Problem 3
%%3.Here are some discrete math questions for you to implement in MATLAB.
%a. If you have four people, how many different ways can you 
% arrange them in a line? 

a = factorial(4)

%b. How many different robotics teams of 7 members can you form from a 
% class of 28 students? (Combinations—order does not matter).  

b = nchoosek(28,7) %28!/((28-7)!*7!)

%c. Since each player on a robotics team is assigned a particular role, order does matter. Recalculate
%the possible number of different robotics teams that can be formed when order is taken into
%account.

c= factorial(28) / factorial(7) %order matters

%d. There are 52 different cards in a deck. How many different hands of 5 cards each are possible?
%Remember, every hand can be arranged 120 (5!) different ways. What are the chances of
%getting dealt a royal flush?

d = nchoosek(52,5) %52!/((52-5)!*5!)

e = 4/d * 100 %There are only 4 possible royal flush arrangements out of all the different possible hands 

No comments:

Post a Comment