Tuesday, September 22, 2015

home work 7

code for the first part and half of the second part of question 1 

second half of part 2 and question 2 code

the my_sqrt function code pretty simple stuff

Thursday, September 17, 2015

homework 6 Talk about a pain and why cant I just upload a file that links to the code???

can you see the code, let me know if not cause ill copy and past it instead
as far as output, its not interesting so....




Tuesday, September 15, 2015

Homework 5

clear;clc;
1.
%(a) Write a MATLAB® function called num_grains to find the number of
%grains in a 1-square-inch area (N ) at 100 x magnification when the ASTM
%grain size is known.
    %just did it. will call the function in next line
%(b) Use your function to find the number of grains for ASTM grain sizes
%n = 10 to 100
n=10:100;
num_grains(n);
%(c) Plot your results
    %done in function
    %%
    clear;
    clc;
function output= num_grains(n)
N=2.^(n-1);%equation that is used
output=N;%values that i get from the function
semilogy(n,N,'k-')%part c done in function to save time
title('number of grains in metal sample')
xlabel('n from 10 to 100')
ylabel('Number of grains in logrithmic form')


2. Create a function called polygon that draws a polygon with any number
%of sides. Your function should require a single input: the number of sides
% desired. It should not return any value to the command window but should
%draw the requested polygon in polar coordinates.
    %see function polygon, call with numberr of sides desired.
function output = polygon(s)
%this function answers question number two in the homework
%effectivly it creates a polygon based on user input

figure (2)
sides=s;%determines what polygon to create
degrees=2*pi/sides ;%draws polygon
theta=0:degrees:360-degrees ;% part one of polar graph
radius=ones(1,numel(theta)) ; % part 2 of polar grph
polar(theta,radius) % graphs polygon


%%
    clear;clc;


3. Perhaps the most famous equation in physics is

%E = mc2

%which relates energy E to mass m . The speed of light in a vacuum, c , is
%the property that links the two together. The speed of light in a vacuum is
%2.9979 * 108 m / s.

%(a) Create a function called energy to find the energy corresponding to a
%given mass in kilograms. Your result will be in joules, since
%1 kg m2 / s2 = 1 J.
    %see function energy
%(b) Use your function to find the energy corresponding to masses from 1 kg
%to 106 kg. Use the logspace function (consult help logspace ) to create an
%appropriate mass vector.
    m=logspace(0,6);%mass from 1 to 10^6kg
    E=energy(m); %energy of those masses
%(c) Create a plot of your results. Try using different logarithmic
%plotting approaches (e.g., semilogy , semilogx , and loglog ) to determine
%the best way to graph your results.
subplot(2,2,1);
semilogy(m,E)
xlabel('mass in kilograms')
ylabel('energy in Joules logged')
title('Energy Plot')
subplot(2,2,2)
semilogx(m,E)
xlabel('mass in kilograms logged')
ylabel('energy in Joules')
title('Energy Plot')
subplot(2,2,3)
loglog(m,E)
xlabel('mass in kilograms logged')
ylabel('energy in Joules logged')
title('Energy Plot')

function output=energy(m)
E=m.*(2.9979*10^8)^2%energy equation with c written as a number
output=E;



4.
%%
clear;clc;
%(a) Create a function M-fi le called distance to find the distance to the
%horizon. Your function should accept two vector inputs—radius and
%height—and should return the distance to the horizon. Don’t forget that
%you’ll need to use meshgrid because your inputs are vectors.

%(b) Create a MATLAB® program that uses your distance function to find the
%distance in miles to the horizon, both on the earth and on Mars, for hills
 %   from 0 to 10,000 feet. Remember to use consistent units in your
  %  calculations. Note that

%• Earth’s diameter = 7926 miles
REARTH=7929/2;RMARS=4217/2;
%• Mars’ diameter = 4217 miles

h=0:1000:10000;
height=h/5280;
From_Earth= distance(REARTH,height);
From_Mars=distance(RMARS,height);
height=height';
From_Earth=From_Earth';
From_Mars=From_Mars';

%Report your results in a table. Each column should represent a different
%planet, and each row a different hill height.
table(height,From_Earth,From_Mars)
function result=distance(r,h)

d=sqrt(2.*r.*h+h.^2);
result=d;function result=distance(r,h)


Friday, September 11, 2015

Homework 4 finally caught up XD

%(a) Use the provided data to calculate the stress 
%and the corresponding strain for each data pair. 
%The tested sample was a rod of diameter 0.505 in., 
%so you’ll need to find the cross-sectional area to use 
%in your calculations.
clear;clc
%the following varible has the values of force
F=[0 1650 3400 5200 6850 7750 8650 9300 10100 10400];
%and this variable has the values of length used to find strain
e=[2 2.002 2.004 2.006 2.008 2.010 2.020 2.040 2.080 2.120];
% using the strain fuction to calulate the stress from the force values
x=stress(F);
% and now the strain function
y=strain(e);
%now we plot with title and lable for the axis
plot(y,x,'k-')
xlabel('Strain')
ylabel('Stress, lb/in2')
title('Stress Vs Strain')

















%%
clear;clc
%(a) Create a “flower” with three petals.
theta = 0:0.01:pi;
rho = sin(3*theta);
%polar graph
figure
polar(theta,rho,'r--');
hold on;

%(b) Overlay your figure with eight additional petals, half the size of the three original ones.
theta2 = 0:0.01:2*pi;
rho2 = (sin(4*theta2))/2;
polar(theta2,rho2,'m-');
hold off

%(c) Create a heart shape.
figure(2)
t=0:0.01:2*pi;%theta from 0 to 2 pi
r=3*sin(t)+2*abs(cos(t)).^0.6-2.5-1.5*cos(2*t);%rho
polar(t,r,'r-');
%(d) Create a six-pointed star.
figure (3)
% need to create two triangles ontop of the same graph
thet = pi/6:(2/3)*pi:4*pi;
rh= ones(1,6);
polar(thet,rh)
hold on;
thet = pi/6:(2/3)*pi:4*pi;
rh= ones(1,6);
polar(-thet,rh)
%creat a hexagon
figure (4)
close
sides=6;
degrees=2*pi/sides ;
theta=0:degrees:360-degrees ;
radius=ones(1,numel(theta)) ;
















polar(theta,radius)
%%
clear;clc
%(a) Letting t = 0 represent the year 1965 and t = 50 represent 2015, use
%this model to calculate the predicted number of transistors per square
%inch for the 50 years from 1965 to 2015. Let t increase in increments of 2
% years. Display the results in a table with two columns—one for the year
% and one for the number of transistors.
t=0:2:50;%t stands for time, in this case years
d=Moore(t);% d is for density made from a function
t=transpose(t);% table friendly
d=transpose(d);% table friendly
T=table(t,d)% table


%(b) Using the subplot feature, plot the data in a linear x – y plot, a
%semilog x plot, a semilog y plot, and a log–log plot. Be sure to title the
% plots and label the axes.
%linear
subplot(2,2,1);
plot (t,d);
xlabel('Time in Years');
ylabel('Density');
title('Moores Law linear');
subplot(2,2,2);
%semilogx
semilogx(t,d);
xlabel('Log Time in Years');
ylabel('Density');
title('Moores Law semilogx');
subplot(2,2,3);
%semilogy
semilogy(t,d);
xlabel('Time in Years');
ylabel('Log Density');
title('Moores Law semilogy');
subplot(2,2,4);
%loglog
loglog(t,d);
xlabel('Log Time in Years');
ylabel('Log Density');
title('Moores Law Loglog');
%(c) The total transistor count on integrated circuits produced over the
%last 35 years is shown in the table at right. Create a semilog plot (with
%the y -axis scaled logarithmically) of the actual data, using circles only
%to indicate the data points (no lines). Include a second line representing
%the predicted values using Moore’s law, based on the 1971 count as the
% starting point. Add a legend to your plot.
figure (2)
t=[1971 1972 1974 1979 1982 1985 1989 1993 1996 1997 1997 1999 1999 1999 2000 2003 2003 2003 2004 2006 2006 2006 2006 2007 2006 2008 2010 2011];
d=[2300 2500 4500 29000 134000 275000 1200000 3100000 4300000 7500000 8800000 9500000 21300000 22000000 42000000 54300000 105900000 220000000 592000000 241000000 291000000 582000000 681000000 789000000 170000000 200000000 230000000 260000000];
semilogy(t,d,'or')
xlabel('Years');
ylabel('Log Values of Density');
title('Theoretical Moores and experimental Vs Time');
hold on
t=1971:2011;
d=Moore(0:40);
semilogy(t,d,'k-');
legend('Experimental','Theoretical Law');

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 

Tuesday, September 1, 2015

Homework 2 questions


So this is the work done on paper 1-3. What you might see on the white board had this been done in class.


and 4 and 5.



This is the matlab work for question 1 and 2. Fairly saimple.







All of these images are for question 3 since we had to narrow down the final answer there was a lot of Matrices involved. There was some syntax error earlier on but it was corrected. a similar problem happened on question five.





question 4 with the range in the form of a matrix using the linspace function.




Question five, Professor Mason and Mahmoud went around checking this problem so I'm not going to explain it in detail.