Day 7:
We learned about the find fucntions for matrices and other ways to call row and columns. We were also introudeced to & and | logic statements. We then moved on to if and else statements and then later onto switch and case structers.
We then did an example of following different and and or statemens on which ones returns 1's and 0's
Here is a picture.
Conclusion:
Today we learned about the find function which will be useful for targeting specific row and columns in data. We then got familiar with logic if else statements and also with switch case structures.
% HMWK 7
%7-1
t1= input('input number 1 \n') %number1
t2 = input ('input number 2 \n') %number2
t = input('input times \n') %range number
x = (1:t); %sets x range for counter
x(1) = t1; %sets x1
x(2) = t2; %sets x2
i = 3; %counter start at 3
while i<=t; %while loop i <t
x(i)=x(i-2)+x(i-1); %fib eq
i=i+1; %counter step 1
end
ang =(1:length(x)); %angle matrix of x
r = x; %radius of x
polar(ang,r) %graph
fprintf('the fibonacci seq to %d terms: %g \n',[t;x(t)]); %display
%7-2
t1= input('input number 1 \n') %number1
t2 = input ('input number 2 \n') %number2
t= 1000;
%t = input('input times \n') %range number
x = (1:t); %sets x range for counter
x(1) = t1; %sets x1
x(2) = t2; %sets x2
i = 3; %counter start at 3
while i<=t %i counter to t
x(i)=x(i-2)+x(i-1); %feb counter
i=i+1; %step up of i
end
t=0; %rest of t
k=3; %set k counter to 3
while (abs(x(k)/x(k-1) - x(k-1)/x(k-2))>0.001); %while check for golden ratio
t=t+1; %t step up
k=k+1; %k step up
end
i = 3; %set i 3
x=(1:t); %set x matrix for counter
while i<=t %i counter to t
x(i)=x(i-2)+x(i-1); %feb counter
i=i+1; %i step up
end
ang =(1:length(x)); %angle matrix of x
r = x; %radius of x
polar(ang,r) %graph
fprintf('the number of fibonacci seq terms %d value number %g \n',[t;x(t)]); %display
%%sqrt hmwk 7-2
function output = my_sqrt(num,e) %function for sqrt number guess
x = 1; %intial value of x =1
y = (1/num)*(x^2); %guess of Y
xg= (x/8)*(15-y*(10-3*y)); %number guess
while (abs((xg)-x)>e) %loop for checking on e
x = xg; %update x to x guess
y = (1/num)*(x^2); %guess of Y
xg = (x/8)*(15-y*(10-3*y)); %update x to x guess
end
output = xg; %output
%%hmwk 7-2
n = input('input number of root\n '); %Number n input
ng = my_sqrt(n,0.001); %number n guess by function
nr = sqrt(n); %number calc of square root by matlab
fprintf('\nUsing Halley''s algoritm the square root of %g = %g. \n',[n;ng])
fprintf('The square root of %g calc by matlab is %g. \n', [n;nr]);
Tuesday, September 22, 2015
Thursday, September 17, 2015
Day 6 - 3D plotting and Functions
Day 6:
We got introduced to 3d plotting and the different types like comet, surf plot, and meshgrid commands. We then tried a sphere example and found ways to manipulate the graph inside the graph instead of the usual by means of matlab code. We then got introduced to function and wrote our own one for distance, which we used later on for homework called hallpetch.
We then did an example. Here is a picture.
%HMWK 6
%Height rocket
t = 0:2:100; %time
h = (2.13*t.^2)-(0.0013*t.^4)+(0.000034*t.^(4.751)); %height eq
k = find(h<0 )%height find
a=t(k(1)) %time of crash
max1 = max(h) ; %height max
max2 = max(max(h));
plot(t,h),title('height v time'),xlabel('time (s)'),ylabel('height') %graph
grid on
axis([0,(63.5),0,1470.2]) %graph edit%6-2
batch = [1,116,45,110;2,114,42,115;3,118,41,120;4,124,38,95;5,126,61,118] %batch data
bn = [1,2,3,4,5] %batch num
tn = [116,114,118,124,126] %temp num
hn = [45,42,41,38,61] %humidity num
torn = [110,115,120,95,118] %pressure num
tempok = find(tn<=125 & tn>=115) %check if temp ok
humok = find(hn<=60 & hn>=40) %check if humidity ok
torok = find(torn<=200 & torn>=100) %check if pressure ok
a1 = numel(tempok)/5*(100) %percent pass temp
a2 = numel(humok)/5*100 %percen pass hum
a3 = numel(torok)/5*100 %percent pass pressure
a4 = 2/5*100 %percent total pass
fprintf('pass is %2.0f percent \n',a1)
fprintf('pass is %2.0f percent \n',a2)
fprintf('pass is %2.0f percent \n',a3)
fprintf('total %2.0f percent pass \n',a4)
#6-3
function output = money(x) %money function
x = input('salary \n') % x equal to salary amount
if x <=30000 %if x is less than 30k
xt = x+x*.1+x*.1 %total amount eq
fprintf('Money is %4.0f \n',xt) %output
elseif x >=30000 & x <60000 %if x is between 30k and 60k
xt = x+x*.1+(3000+.05*x) %total amount eq
fprintf('Money is %4.0f \n',xt) %output
elseif x >=60000 & x<100000 %if x is between 60k and 100k
xt = x+(6000+.08*x)+(3000+.05*x) %total amount moneny eq
fprintf('Money is %4.0f \n',xt) %output
elseif x>=100000 %if salary is greater than 100k
xt = x+(6000+.08*x) %total amount eq
fprintf('Money is %4.0f \n',xt) %output
end %end
We got introduced to 3d plotting and the different types like comet, surf plot, and meshgrid commands. We then tried a sphere example and found ways to manipulate the graph inside the graph instead of the usual by means of matlab code. We then got introduced to function and wrote our own one for distance, which we used later on for homework called hallpetch.
We then did an example. Here is a picture.
%HMWK 6
%Height rocket
t = 0:2:100; %time
h = (2.13*t.^2)-(0.0013*t.^4)+(0.000034*t.^(4.751)); %height eq
k = find(h<0 )%height find
a=t(k(1)) %time of crash
max1 = max(h) ; %height max
max2 = max(max(h));
plot(t,h),title('height v time'),xlabel('time (s)'),ylabel('height') %graph
grid on
axis([0,(63.5),0,1470.2]) %graph edit%6-2
batch = [1,116,45,110;2,114,42,115;3,118,41,120;4,124,38,95;5,126,61,118] %batch data
bn = [1,2,3,4,5] %batch num
tn = [116,114,118,124,126] %temp num
hn = [45,42,41,38,61] %humidity num
torn = [110,115,120,95,118] %pressure num
tempok = find(tn<=125 & tn>=115) %check if temp ok
humok = find(hn<=60 & hn>=40) %check if humidity ok
torok = find(torn<=200 & torn>=100) %check if pressure ok
a1 = numel(tempok)/5*(100) %percent pass temp
a2 = numel(humok)/5*100 %percen pass hum
a3 = numel(torok)/5*100 %percent pass pressure
a4 = 2/5*100 %percent total pass
fprintf('pass is %2.0f percent \n',a1)
fprintf('pass is %2.0f percent \n',a2)
fprintf('pass is %2.0f percent \n',a3)
fprintf('total %2.0f percent pass \n',a4)
#6-3
function output = money(x) %money function
x = input('salary \n') % x equal to salary amount
if x <=30000 %if x is less than 30k
xt = x+x*.1+x*.1 %total amount eq
fprintf('Money is %4.0f \n',xt) %output
elseif x >=30000 & x <60000 %if x is between 30k and 60k
xt = x+x*.1+(3000+.05*x) %total amount eq
fprintf('Money is %4.0f \n',xt) %output
elseif x >=60000 & x<100000 %if x is between 60k and 100k
xt = x+(6000+.08*x)+(3000+.05*x) %total amount moneny eq
fprintf('Money is %4.0f \n',xt) %output
elseif x>=100000 %if salary is greater than 100k
xt = x+(6000+.08*x) %total amount eq
fprintf('Money is %4.0f \n',xt) %output
end %end
Thursday, September 10, 2015
Day 4 - Importing Data into Matlab
Day 4:
We started with learning how to type into Matlab sin and cosine function and learned how to switch between radians and degrees.
We then did example with an air balloon and their forces. Here is a picture.
We then move on to commands that allowed us to sort data, which was later used for the weather example for precipitation. Here is a picture.
Conclusion:
We learned how use sin and cosine, switch between radians and degrees. Learned how to sort large data and find the mean, mode, and average. We also got a better understanding of how to manipulate a matrix to sort the data from high to low, to select a particular column and other things.
%HMWK 4 -1 **Code**
F = [0,1650,3400,5200,6850,7750,8650,9300,10100,10400]
l = [2,2.002,2.004,2.006,2.008,2.010,2.020,2.040,2.080,2.120]
lnot = 2
A = pi*(0.505/2)^2
sig = F/A
strain = (l - lnot)/lnot
plot(strain',sig', '-ok'), title('Stress V Strain'),xlabel('sigma' ),
ylabel('strain'),text(.004,4.5e4,'Yield P')
% 5 - 2
x = [0:.05:2*pi]
t = [0:.05:2*pi]
y1 = sin(x),y2 = cos(x),r1 = cos(t*3)
polar(x,r1,'--r'),title('3 petal'),xlabel('x'),ylabel('y')
hold on
x = [0:.05:2*pi]
t = [0:.05:2*pi]
y1 = sin(x),y2 = cos(x),r1 = .5*cos(t*4)
polar(x,r1,'--m'),title('graph 1'),xlabel('x'),ylabel('y')
%
clear,clc
x = [0:.05:2*pi]
t = [0:.05:2*pi]
r3= 1-1*sin(t)
polar(x,r3,'--m'),title('graph 1'),xlabel('x'),ylabel('y')
%
theta= 0:pi/3:2*pi
r= ones(1,7)
polar(theta,r)
r4 = sin(t*(pi/2)-(pi/2))
polar(theta,r),title('graph 1'),xlabel('x'),ylabel('y')
%
theta = [pi/6:(2/3)*pi:4*pi]
r= ones(1,6)
polar(theta,r)
hold on
theta = [pi/6:(2/3)*pi:4*pi]
r= ones(1,6)
polar(-theta,r)
%5-3
t=0:2:50
y = [2300 2500 4500 29000 134000 275000 1200000 3100000 4300000 7500000 8800000 9500000 21300000 22000000 42000000 54300000 105900000 220000000 592000000 241000000 291000000 582000000 681000000 789000000 1700000000 2000000000 2300000000 2600000000]
y= y'
ye = [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]
x = 1965:2:2015
dt = 30*2.^(t/2)
subplot(2,2,1)
plot(x,dt),title('graph 1'),xlabel('year'),ylabel('trans')
subplot(2,2,2)
semilogx(x,dt), title('graph 2'),xlabel('year'),ylabel('trans')
subplot(2,2,3)
semilogy(x,dt), title('graph 3'),xlabel('year'),ylabel('trans')
subplot(2,2,4)
loglog(x,dt), title('graph 4'),xlabel('year'),ylabel('trans')
figure
subplot(2,2,1)
plot(x,dt), title('graph 1'),xlabel('year'),ylabel('trans')
subplot(2,2,2)
semilogx(x,dt), title('graph 2'),xlabel('year'),ylabel('trans')
subplot(2,2,3)
semilogy(x,dt), title('graph 3'),xlabel('year'),ylabel('trans')
subplot(2,2,4)
loglog(x,dt), title('graph 4'),xlabel('year'),ylabel('trans')
%plot(x,y, '-ok'), title('Stress V Strain'),xlabel('sigma' ),
%ylabel('strain'),text(.004,4.5e4,'Yield P')
figure
semilogy(ye,y, 'ok',x,dt), title('moore law'),xlabel('year' ),
ylabel('trans')
legend(20,20,'real','expermintal')
*********picture of homework checked*********
We started with learning how to type into Matlab sin and cosine function and learned how to switch between radians and degrees.
We then did example with an air balloon and their forces. Here is a picture.
We then move on to commands that allowed us to sort data, which was later used for the weather example for precipitation. Here is a picture.
Conclusion:
We learned how use sin and cosine, switch between radians and degrees. Learned how to sort large data and find the mean, mode, and average. We also got a better understanding of how to manipulate a matrix to sort the data from high to low, to select a particular column and other things.
%HMWK 4 -1 **Code**
F = [0,1650,3400,5200,6850,7750,8650,9300,10100,10400]
l = [2,2.002,2.004,2.006,2.008,2.010,2.020,2.040,2.080,2.120]
lnot = 2
A = pi*(0.505/2)^2
sig = F/A
strain = (l - lnot)/lnot
plot(strain',sig', '-ok'), title('Stress V Strain'),xlabel('sigma' ),
ylabel('strain'),text(.004,4.5e4,'Yield P')
% 5 - 2
x = [0:.05:2*pi]
t = [0:.05:2*pi]
y1 = sin(x),y2 = cos(x),r1 = cos(t*3)
polar(x,r1,'--r'),title('3 petal'),xlabel('x'),ylabel('y')
hold on
x = [0:.05:2*pi]
t = [0:.05:2*pi]
y1 = sin(x),y2 = cos(x),r1 = .5*cos(t*4)
polar(x,r1,'--m'),title('graph 1'),xlabel('x'),ylabel('y')
%
clear,clc
x = [0:.05:2*pi]
t = [0:.05:2*pi]
r3= 1-1*sin(t)
polar(x,r3,'--m'),title('graph 1'),xlabel('x'),ylabel('y')
%
theta= 0:pi/3:2*pi
r= ones(1,7)
polar(theta,r)
r4 = sin(t*(pi/2)-(pi/2))
polar(theta,r),title('graph 1'),xlabel('x'),ylabel('y')
%
theta = [pi/6:(2/3)*pi:4*pi]
r= ones(1,6)
polar(theta,r)
hold on
theta = [pi/6:(2/3)*pi:4*pi]
r= ones(1,6)
polar(-theta,r)
%5-3
t=0:2:50
y = [2300 2500 4500 29000 134000 275000 1200000 3100000 4300000 7500000 8800000 9500000 21300000 22000000 42000000 54300000 105900000 220000000 592000000 241000000 291000000 582000000 681000000 789000000 1700000000 2000000000 2300000000 2600000000]
y= y'
ye = [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]
x = 1965:2:2015
dt = 30*2.^(t/2)
subplot(2,2,1)
plot(x,dt),title('graph 1'),xlabel('year'),ylabel('trans')
subplot(2,2,2)
semilogx(x,dt), title('graph 2'),xlabel('year'),ylabel('trans')
subplot(2,2,3)
semilogy(x,dt), title('graph 3'),xlabel('year'),ylabel('trans')
subplot(2,2,4)
loglog(x,dt), title('graph 4'),xlabel('year'),ylabel('trans')
figure
subplot(2,2,1)
plot(x,dt), title('graph 1'),xlabel('year'),ylabel('trans')
subplot(2,2,2)
semilogx(x,dt), title('graph 2'),xlabel('year'),ylabel('trans')
subplot(2,2,3)
semilogy(x,dt), title('graph 3'),xlabel('year'),ylabel('trans')
subplot(2,2,4)
loglog(x,dt), title('graph 4'),xlabel('year'),ylabel('trans')
%plot(x,y, '-ok'), title('Stress V Strain'),xlabel('sigma' ),
%ylabel('strain'),text(.004,4.5e4,'Yield P')
figure
semilogy(ye,y, 'ok',x,dt), title('moore law'),xlabel('year' ),
ylabel('trans')
legend(20,20,'real','expermintal')
*********picture of homework checked*********
Tuesday, September 8, 2015
Day 3 - fprintf
Day 3:
We spent our time learning about formatting our answers and finding ways to use the fprintf command. We then learned about m-scrpit file and how to save work.
We then worked on a UDF example. Here is a picture.
We then worked on the Voyager 1 and Voyager 2 power consumption. Here is a picture.
We then talked about the weather and how weather data could be transferred from excel file to matlab reading file that can be used to deduct information.
Conclusion:
We spent the learning ways to use the fprintf format to better showcase our answers then we learned about m-scripts and their usefulness. Later on we found ways to use excel files to import into Matlab, which will be useful for the homework.
HMWK 3
Q1
lat1 = input('latitude 1 in deg \n'); %input for lat1
long1 = input('longitude1 in deg \n'); %input fot long1
lat2 = input('latitude2 in deg \n'); %input for lat2
long2 = input('longitude2 in deg \n'); %input for long2
rho = unit(3960,'miles') %convertto si units
rb = 3960 %radius of earth in miles
phi = (90 - lat1)*(pi/180) %converts lat1 deg into rad
p1 = unit(lat1,'deg')
lat1*(pi/180)
theta = (360 - long1)*(pi/180) %converts long1 deg into rad
t1 = unit(long1,'deg')
long1*(pi/180)
x1 = rho*sin(phi)*cos(theta) %conver lat into spherical x
y1 = rho*sin(phi)*sin(theta) %conver long into spherical y
z1 = rho*cos(phi) %conver r into spherical r
phi2 = (90 - lat2)*(pi/180) %converts lat2 deg into rad
theta2 = (360 - long2)*(pi/180) %converts long2 deg into rad
x2 = rho*sin(phi2)*cos(theta2) %conver lat into spherical x2
y2 = rho*sin(phi2)*sin(theta2)%conver long into spherical y2
z2 = rho*cos(phi2) %conver r2 into spherical r2
dot = x1*x2 + y1*y2 + z1*z2 %dot of lat,long
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1) %mag of 1
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2) %mag of 2
gamma = acos(dot/(dist1*dist2)) %eq for gamma
% t2 = unit(lon2,'deg')
% xd = rho*sin(p2)*cos(t2)
% ye = rho*sin(p2)*sin(t2)
% zf = rho*cos(p2)
% p2 = unit(lat2,'deg')
% xa = rho*sin(p1)*cos(t1)
% yb = rho*sin(p1)*sin(t1)
% zc = rho*cos(p1)
% dot1 = xa*xd + yb*ye + zc*zf
% dista = sqrt(xa*xa + yb*yb + zc*zc)
% distb = sqrt(xd*xd + ye*ye + zf*zf)
% gamma1 = acos(dot1/(dista*distb))
gamma*rb %eq for real distance between two points
display('Great Circle Distance in miles:') %display
fprintf('%8.0f \n',gamma*rb) %display of data
display('Great Circle Distance in meters:')
% sprintf('%8.0f \n',gamma*rho)
%%hmwk 3 - 2
tt= b4 %tt is the excel of therm 1,2,3
ttt = b4' %ttt is the transpose of thermo 1,2,3
ttm = max(tt) %max temp for each of therm
tttm = max(ttt)
ttmin = min(tt) %min tem for teach therm
tttm2 = max(max(ttt)) %higest temp for therm
%%hmwk 3 - 3
r = randn(10000,1)*23.5+80; %creates a gauss random number
r1 =mean(r) %mean for gaussian random number
st = std(r) %standard dev of r numbers
y = st*r+r1
%%hmwk 3 - 4
zl = 0+5j %res of inductor
zc = 0+15j %resof cap
R = 5+0j %res of res
zt = zc+zl+R %res of circuit
V = 10+0j %% V = Izt
I = complex(V/zt) %current of circuit
%%hmwk 3 - 5
% Covina = 34.1,-117.9 ; 34.2,-118.4 no good
% weathr st = 33.9,-118.4
lat1 = input('latitude 1 in deg \n'); %input for lat1
long1 = input('longitude1 in deg \n'); %input fot long1
lat2 = input('latitude2 in deg \n'); %input for lat2
long2 = input('longitude2 in deg \n'); %input for long2
rho = unit(3960,'miles') %convertto si units
rb = 3960 %radius of earth in miles
phi = (90 - lat1)*(pi/180) %converts lat1 deg into rad
p1 = unit(lat1,'deg')
lat1*(pi/180)
theta = (360 - long1)*(pi/180) %converts long1 deg into rad
t1 = unit(long1,'deg')
long1*(pi/180)
x1 = rho*sin(phi)*cos(theta) %conver lat into spherical x
y1 = rho*sin(phi)*sin(theta) %conver long into spherical y
z1 = rho*cos(phi) %conver r into spherical r
phi2 = (90 - lat2)*(pi/180) %converts lat2 deg into rad
theta2 = (360 - long2)*(pi/180) %converts long2 deg into rad
x2 = rho*sin(phi2)*cos(theta2) %conver lat into spherical x2
y2 = rho*sin(phi2)*sin(theta2)%conver long into spherical y2
z2 = rho*cos(phi2) %conver r2 into spherical r2
dot = x1*x2 + y1*y2 + z1*z2 %dot of lat,long
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1) %mag of 1
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2) %mag of 2
gamma = acos(dot/(dist1*dist2)) %eq for gamma
gamma*rb %eq for real distance between two points
display('Great Circle Distance in miles:') %display
fprintf('%8.0f \n',gamma*rb) %display of data
display('Great Circle Distance in meters:')
tt = wd2; %tt is weather data
ttt = wd2' %ttt is transpose of weather data
t1 = sum(wd2) %t1 sum of weater data
t2 = sum(ttt) %t2 sum of weather data
format shorteng %format numbers
t1 = sum(wd2) %t1 sum of weather data
t2 = sum(wd2') %t2 sum of weather data
We spent our time learning about formatting our answers and finding ways to use the fprintf command. We then learned about m-scrpit file and how to save work.
We then worked on a UDF example. Here is a picture.
We then worked on the Voyager 1 and Voyager 2 power consumption. Here is a picture.
We then talked about the weather and how weather data could be transferred from excel file to matlab reading file that can be used to deduct information.
Conclusion:
We spent the learning ways to use the fprintf format to better showcase our answers then we learned about m-scripts and their usefulness. Later on we found ways to use excel files to import into Matlab, which will be useful for the homework.
HMWK 3
Q1
lat1 = input('latitude 1 in deg \n'); %input for lat1
long1 = input('longitude1 in deg \n'); %input fot long1
lat2 = input('latitude2 in deg \n'); %input for lat2
long2 = input('longitude2 in deg \n'); %input for long2
rho = unit(3960,'miles') %convertto si units
rb = 3960 %radius of earth in miles
phi = (90 - lat1)*(pi/180) %converts lat1 deg into rad
p1 = unit(lat1,'deg')
lat1*(pi/180)
theta = (360 - long1)*(pi/180) %converts long1 deg into rad
t1 = unit(long1,'deg')
long1*(pi/180)
x1 = rho*sin(phi)*cos(theta) %conver lat into spherical x
y1 = rho*sin(phi)*sin(theta) %conver long into spherical y
z1 = rho*cos(phi) %conver r into spherical r
phi2 = (90 - lat2)*(pi/180) %converts lat2 deg into rad
theta2 = (360 - long2)*(pi/180) %converts long2 deg into rad
x2 = rho*sin(phi2)*cos(theta2) %conver lat into spherical x2
y2 = rho*sin(phi2)*sin(theta2)%conver long into spherical y2
z2 = rho*cos(phi2) %conver r2 into spherical r2
dot = x1*x2 + y1*y2 + z1*z2 %dot of lat,long
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1) %mag of 1
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2) %mag of 2
gamma = acos(dot/(dist1*dist2)) %eq for gamma
% t2 = unit(lon2,'deg')
% xd = rho*sin(p2)*cos(t2)
% ye = rho*sin(p2)*sin(t2)
% zf = rho*cos(p2)
% p2 = unit(lat2,'deg')
% xa = rho*sin(p1)*cos(t1)
% yb = rho*sin(p1)*sin(t1)
% zc = rho*cos(p1)
% dot1 = xa*xd + yb*ye + zc*zf
% dista = sqrt(xa*xa + yb*yb + zc*zc)
% distb = sqrt(xd*xd + ye*ye + zf*zf)
% gamma1 = acos(dot1/(dista*distb))
gamma*rb %eq for real distance between two points
display('Great Circle Distance in miles:') %display
fprintf('%8.0f \n',gamma*rb) %display of data
display('Great Circle Distance in meters:')
% sprintf('%8.0f \n',gamma*rho)
%%hmwk 3 - 2
tt= b4 %tt is the excel of therm 1,2,3
ttt = b4' %ttt is the transpose of thermo 1,2,3
ttm = max(tt) %max temp for each of therm
tttm = max(ttt)
ttmin = min(tt) %min tem for teach therm
tttm2 = max(max(ttt)) %higest temp for therm
%%hmwk 3 - 3
r = randn(10000,1)*23.5+80; %creates a gauss random number
r1 =mean(r) %mean for gaussian random number
st = std(r) %standard dev of r numbers
y = st*r+r1
%%hmwk 3 - 4
zl = 0+5j %res of inductor
zc = 0+15j %resof cap
R = 5+0j %res of res
zt = zc+zl+R %res of circuit
V = 10+0j %% V = Izt
I = complex(V/zt) %current of circuit
%%hmwk 3 - 5
% Covina = 34.1,-117.9 ; 34.2,-118.4 no good
% weathr st = 33.9,-118.4
lat1 = input('latitude 1 in deg \n'); %input for lat1
long1 = input('longitude1 in deg \n'); %input fot long1
lat2 = input('latitude2 in deg \n'); %input for lat2
long2 = input('longitude2 in deg \n'); %input for long2
rho = unit(3960,'miles') %convertto si units
rb = 3960 %radius of earth in miles
phi = (90 - lat1)*(pi/180) %converts lat1 deg into rad
p1 = unit(lat1,'deg')
lat1*(pi/180)
theta = (360 - long1)*(pi/180) %converts long1 deg into rad
t1 = unit(long1,'deg')
long1*(pi/180)
x1 = rho*sin(phi)*cos(theta) %conver lat into spherical x
y1 = rho*sin(phi)*sin(theta) %conver long into spherical y
z1 = rho*cos(phi) %conver r into spherical r
phi2 = (90 - lat2)*(pi/180) %converts lat2 deg into rad
theta2 = (360 - long2)*(pi/180) %converts long2 deg into rad
x2 = rho*sin(phi2)*cos(theta2) %conver lat into spherical x2
y2 = rho*sin(phi2)*sin(theta2)%conver long into spherical y2
z2 = rho*cos(phi2) %conver r2 into spherical r2
dot = x1*x2 + y1*y2 + z1*z2 %dot of lat,long
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1) %mag of 1
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2) %mag of 2
gamma = acos(dot/(dist1*dist2)) %eq for gamma
gamma*rb %eq for real distance between two points
display('Great Circle Distance in miles:') %display
fprintf('%8.0f \n',gamma*rb) %display of data
display('Great Circle Distance in meters:')
tt = wd2; %tt is weather data
ttt = wd2' %ttt is transpose of weather data
t1 = sum(wd2) %t1 sum of weater data
t2 = sum(ttt) %t2 sum of weather data
format shorteng %format numbers
t1 = sum(wd2) %t1 sum of weather data
t2 = sum(wd2') %t2 sum of weather data
Thursday, September 3, 2015
Day 2 - Math Syntax
HMWK: Matlab code. #2
Day 2:
This day we got familiar with matlab math writing. Using the syntax of matlab. Some operations make sense if real world but not in matlab world.
Here is a picture of matlab code running.
We then example with PV = nRT. Here is a picture.
We then did an example unit conversion from the mars rover. Here is a picture.
Conclusion:
We learned how to type our understanding of math equations into the matlab syntax. We did tried relating it to the PV = nRT equations and do some unit conversions into SI units.
%HMWK 2
x = [-2:1:2]%vector x -2to2 by 1
abs(x) %absolute of x
sqrt(x) %square root of x
%#2
x1=[-3,3] %vector x2 -3,3
sqrt(x1) %square rot of x1
nthroot(x1,2) %nth root
x1.^(.5) %x1^(.5) power
%#3
x3 = [-9:3:12] %vector x3 -9to12 by 3
x3/2 %vector/2
rem(x3,2) %vector rem of 2
exp(x3) %vector exp
sign(x3) %sign for vector
%#4
factor(322) %factor
gcd(322,6) %greatest common denometer
isprime(322) %cheks if # is prime
primes(322) %numbers of prime up to 322
factorial(10) %10!
nchoosek(20,3) %Max # groups of 3 from 20-nomatter
%#5 P= Pnot*e^(rt)
pnot = 100 %intial pop
r = (9/10) %growth rate in fraction
t=10 %time in year
p = pnot*exp(r*t) %pop formula
pnot = input('intial pop \n') %input pop intial
r = input('growth rate in fraction \n') %input growth
t = input ('time in year \n') %input year
p=pnot*exp(r*t) %output for pop
%#6
bulb = 20*100 %J/s
app = 4*500 %J/s
out = 3000 %J/s
a1 = bulb*app*out %energy remove J/s
air = 2000 %aircond remove J/s
temp1 = a1/air %number of air needed for constant temp
bulb2 = 20*18 %new J/s for bulb at 18
a2 = bulb2*app*out %energy remove J/s
temp2 = a2/air %aircond remove J/s
bulb3 = input('# of bulbs \n')*100 %input for bulbs
app3 = input('# of appliances \n')*500 %input for apps
air3 = bulb3*app3/air %number of airconditoner needed
%#6 n!/(n-m)!
nchoosek(4,1) %line of 4
nchoosek(28,7) %differnt robo team -notmatter
factorial(28)/(factorial(28-7)) %differnt robo team - matter
nchoosek(52,5) %diff hands of 5
4/(nchoosek(52,5)) %chance of royal fush
******************ANS********************
Day 2:
This day we got familiar with matlab math writing. Using the syntax of matlab. Some operations make sense if real world but not in matlab world.
Here is a picture of matlab code running.
We then example with PV = nRT. Here is a picture.
We then did an example unit conversion from the mars rover. Here is a picture.
Conclusion:
We learned how to type our understanding of math equations into the matlab syntax. We did tried relating it to the PV = nRT equations and do some unit conversions into SI units.
%HMWK 2
x = [-2:1:2]%vector x -2to2 by 1
abs(x) %absolute of x
sqrt(x) %square root of x
%#2
x1=[-3,3] %vector x2 -3,3
sqrt(x1) %square rot of x1
nthroot(x1,2) %nth root
x1.^(.5) %x1^(.5) power
%#3
x3 = [-9:3:12] %vector x3 -9to12 by 3
x3/2 %vector/2
rem(x3,2) %vector rem of 2
exp(x3) %vector exp
sign(x3) %sign for vector
%#4
factor(322) %factor
gcd(322,6) %greatest common denometer
isprime(322) %cheks if # is prime
primes(322) %numbers of prime up to 322
factorial(10) %10!
nchoosek(20,3) %Max # groups of 3 from 20-nomatter
%#5 P= Pnot*e^(rt)
pnot = 100 %intial pop
r = (9/10) %growth rate in fraction
t=10 %time in year
p = pnot*exp(r*t) %pop formula
pnot = input('intial pop \n') %input pop intial
r = input('growth rate in fraction \n') %input growth
t = input ('time in year \n') %input year
p=pnot*exp(r*t) %output for pop
%#6
bulb = 20*100 %J/s
app = 4*500 %J/s
out = 3000 %J/s
a1 = bulb*app*out %energy remove J/s
air = 2000 %aircond remove J/s
temp1 = a1/air %number of air needed for constant temp
bulb2 = 20*18 %new J/s for bulb at 18
a2 = bulb2*app*out %energy remove J/s
temp2 = a2/air %aircond remove J/s
bulb3 = input('# of bulbs \n')*100 %input for bulbs
app3 = input('# of appliances \n')*500 %input for apps
air3 = bulb3*app3/air %number of airconditoner needed
%#6 n!/(n-m)!
nchoosek(4,1) %line of 4
nchoosek(28,7) %differnt robo team -notmatter
factorial(28)/(factorial(28-7)) %differnt robo team - matter
nchoosek(52,5) %diff hands of 5
4/(nchoosek(52,5)) %chance of royal fush
******************ANS********************
x =
-2
-1 0 1
2
ans =
2
1 0 1
2
ans =
0.0000 + 1.4142i 0.0000 + 1.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i 1.4142 + 0.0000i
sqrt(x1) %square rot of x1
nthroot(x1,2) %nth
root
x1.^(.5)
Undefined function
or variable 'x1'.
x1=[-3,3]
%vector x2 -3,3
sqrt(x1) %square rot of x1
nthroot(x1,2) %nth
root
x1.^(.5)
x1 =
-3
3
ans =
0.0000 + 1.7321i 1.7321 + 0.0000i
Error using nthroot
(line 31)
If X is negative, N
must be an odd integer.
x3 = [-9:3:12] %vector x3 -9to12 by 3
x3 = [-9:3:12] %vector x3 -9to12 by 3
x3/2 %vector/2
rem(x3,2) %vector
rem of 2
exp(x3) %vector exp
sign(x3) %sign for vector
%#4
factor(322) %factor
gcd(322,6) %greatest common denometer
isprime(322) %cheks if # is prime
primes(322)
%numbers of prime up to 322
factorial(10) %10!
nchoosek(20,3) %Max # groups of 3 from 20-nomatter
%#5 P= Pnot*e^(rt)
pnot = 100 %intial
pop
r = (9/10) %growth rate in fraction
t=10 %time in year
p = pnot*exp(r*t)
%pop formula
pnot =
input('intial pop \n') %input pop
intial
r = input('growth
rate in fraction \n') %input growth
t = input ('time in
year \n') %input year
p=pnot*exp(r*t)
%output for pop
%#6
bulb = 20*100 %J/s
app = 4*500 %J/s
out = 3000 %J/s
a1 = bulb+app+out
%energy remove J/s
air = 2000 %aircond
remove J/s
temp1 =
round(a1/air) %number of air needed for
constant temp
bulb2 = 20*18 %new J/s for bulb at 18
a2 = bulb2+app+out
%energy remove J/s
temp2 =
round(a2/air) %aircond remove J/s
bulb3 = input('# of
bulbs \n')*100 %input for bulbs
app3 = input('# of
appliances \n')*500 %input for apps
air3 =
round((bulb3+app3)/air) %number of airconditoner needed
%#6 n!/(n-m)!
nchoosek(4,1) %line of 4
nchoosek(28,7) %differnt robo team -notmatter
factorial(28)/(factorial(28-7))
%differnt robo team - matter
nchoosek(52,5) %diff hands of 5
4/(nchoosek(52,5)) %chance of royal fush
x3 =
-9
-6 -3 0
3 6 9
12
ans =
-4.5000
-3.0000 -1.5000 0
1.5000 3.0000 4.5000
6.0000
ans =
-1
0 -1 0
1 0 1
0
ans =
1.0e+05 *
0.0000
0.0000 0.0000 0.0000
0.0002 0.0040 0.0810
1.6275
ans =
-1
-1 -1 0
1 1 1
1
ans =
2
7 23
ans =
2
ans =
0
ans =
Columns 1 through 20
2
3 5 7
11 13 17
19 23 29
31 37 41
43 47 53
59 61 67
71
Columns 21 through 40
73
79 83 89
97 101 103
107 109 113
127 131 137
139 149 151
157 163 167
173
Columns 41 through 60
179
181 191 193
197 199 211
223 227 229
233 239 241
251 257 263
269 271 277
281
Columns 61 through 66
283
293 307 311
313 317
ans =
3628800
ans =
1140
pnot =
100
r =
0.9000
t =
10
p =
8.1031e+05
intial pop
100
pnot =
100
growth rate in
fraction
.9
r =
0.9000
time in year
10
t =
10
p =
8.1031e+05
bulb =
2000
app =
2000
out =
3000
a1 =
7000
air =
2000
temp1 =
4
bulb2 =
360
a2 =
5360
temp2 =
3
# of bulbs
10
bulb3 =
1000
# of appliances
8
app3 =
4000
air3 =
3
ans =
4
ans =
1184040
ans =
5.9676e+09
ans =
2598960
ans =
1.5391e-06
Tuesday, September 1, 2015
First day on Engr7
First day on Engr7:
We did an experiment here we had one person act like a robot and the other direct their movement. We then posted what we found important of our experience.
Here is a picture on our thoughts of it.
We later found the experimental equations to find the forces and velocity needed to safely land an egg from the roof.
Here is the video, we did not succeed.
Conclusion: Our first day was fun and was nice to do the physics before trying our strategy in keeping the egg safe from falling. We found out that our interpretation of our physical world did not match the real world so our strategy did not take into account factors like wind, spin and other real world properties.
HMWK1: Math lab code.
r1 = 10
r1 =
10
r2 = .5
r2 =
0.5000
v1 = pi*(4/3)*r1^2
v1 =
418.8790
v2 = pi*(4/3)*r1^2
v2 =
418.8790
v3 = pi*r2^2*15
v3 =
11.7810
vtot = v1+v2+v3
vtot =
849.5390
SA1 = 4*pi*r1^2SA1 =
1.2566e+03
SA2 = 4*pi*r1^2
SA2 =
1.2566e+03
SA3 = 2*pi*r2^2+2*pi*r2*15
SA3 =
48.6947
SAtot = SA1+SA2+SA3
SAtot =
2.5620e+03
P = 220,n = 2, V = 1,a = 5.536, b = 0.03049, R = 0.08314472
P =
220
n =
2
V =
1
a =
5.5360
b =
0.0305
R =
0.0831
T = P*V/(n*R)
T =
1.3230e+03
T2 = (P+(n^2*a)/V^2)*(V-(a*b))/(n*R)
T2 =
1.2104e+03
Res = 800,L = 100*10^-3,C=1*10^-6
Res =
800
L =
0.1000
C =
1.0000e-06
Splus = -(Res/(2*L))+sqrt((Res/(2*L))^2-(1/(L*C)))
Splus =
-1.5505e+03
Splus = -(Res/(2*L))+sqrt((Res/(2*L))^2-(1/(L*C)))
Splus =
-1.5505e+03
Sneg = -(Res/(2*L))-sqrt((Res/(2*L))^2-(1/(L*C)))
Sneg =
-6.4495e+03
Res = [100:1000];
K1 = (Res/(2*L))
Res = [100:100:1000];
K1 = (Res./(2*L))
Splus = -(K1)+sqrt((K1).^2-(1/(L*C)));
Sneg = -(K1)-sqrt((K1).^2-(1/(L*C)));
table = [Splus', Sneg']
G = 6.673*10^-11,me=6*10^24,mm=7.4*10^22,ravg=3.9*10^8;
G =
6.6730e-11
me =
6.0000e+24
mm =
7.4000e+22
F = G*me*mm/ravg
F =
7.5970e+28
ravg = linspace(3.8*10^8,4.0*10^8,10)
ravg =
1.0e+08 *
Columns 1 through 5
3.8000 3.8222 3.8444 3.8667 3.8889
Columns 6 through 10
3.9111 3.9333 3.9556 3.9778 4.0000
F = G*me*mm/ravg
Error using /
Matrix dimensions must agree.
F = G*me*mm./ravg
F =
1.0e+28 *
Columns 1 through 5
7.7969 7.7515 7.7067 7.6624 7.6187
Columns 6 through 10
7.5754 7.5326 7.4903 7.4484 7.4070
>> d = 12000;pg=3.5,CO=19.4;
pg =
3.5000
fortwo= d/37*(pg)
fortwo =
1.1351e+03
fortwo*CO=
fortwo*CO=
Error: The expression to the left of the equals sign
is not a valid target for an assignment.
cost1 = fortwo*CO
cost1 =
2.2022e+04
cars= [37,29,43,31,48,32,42];
CO2=12000./cars
CO2 =
Columns 1 through 5
324.3243 413.7931 279.0698 387.0968 250.0000
Columns 6 through 7
375.0000 285.7143
CO2=12000./cars*19.4
CO2 =
1.0e+03 *
Columns 1 through 5
6.2919 8.0276 5.4140 7.5097 4.8500
Columns 6 through 7
7.2750 5.5429
cost = 12000./cars*3.9
cost =
1.0e+03 *
Columns 1 through 5
1.2649 1.6138 1.0884 1.5097 0.9750
Columns 6 through 7
1.4625 1.1143
***done***
We did an experiment here we had one person act like a robot and the other direct their movement. We then posted what we found important of our experience.
Here is a picture on our thoughts of it.
We later found the experimental equations to find the forces and velocity needed to safely land an egg from the roof.
Conclusion: Our first day was fun and was nice to do the physics before trying our strategy in keeping the egg safe from falling. We found out that our interpretation of our physical world did not match the real world so our strategy did not take into account factors like wind, spin and other real world properties.
HMWK1: Math lab code.
r1 = 10
r1 =
10
r2 = .5
r2 =
0.5000
v1 = pi*(4/3)*r1^2
v1 =
418.8790
v2 = pi*(4/3)*r1^2
v2 =
418.8790
v3 = pi*r2^2*15
v3 =
11.7810
vtot = v1+v2+v3
vtot =
849.5390
SA1 = 4*pi*r1^2SA1 =
1.2566e+03
SA2 = 4*pi*r1^2
SA2 =
1.2566e+03
SA3 = 2*pi*r2^2+2*pi*r2*15
SA3 =
48.6947
SAtot = SA1+SA2+SA3
SAtot =
2.5620e+03
P = 220,n = 2, V = 1,a = 5.536, b = 0.03049, R = 0.08314472
P =
220
n =
2
V =
1
a =
5.5360
b =
0.0305
R =
0.0831
T = P*V/(n*R)
T =
1.3230e+03
T2 = (P+(n^2*a)/V^2)*(V-(a*b))/(n*R)
T2 =
1.2104e+03
Res = 800,L = 100*10^-3,C=1*10^-6
Res =
800
L =
0.1000
C =
1.0000e-06
Splus = -(Res/(2*L))+sqrt((Res/(2*L))^2-(1/(L*C)))
Splus =
-1.5505e+03
Splus = -(Res/(2*L))+sqrt((Res/(2*L))^2-(1/(L*C)))
Splus =
-1.5505e+03
Sneg = -(Res/(2*L))-sqrt((Res/(2*L))^2-(1/(L*C)))
Sneg =
-6.4495e+03
Res = [100:1000];
K1 = (Res/(2*L))
Res = [100:100:1000];
K1 = (Res./(2*L))
Splus = -(K1)+sqrt((K1).^2-(1/(L*C)));
Sneg = -(K1)-sqrt((K1).^2-(1/(L*C)));
table = [Splus', Sneg']
G = 6.673*10^-11,me=6*10^24,mm=7.4*10^22,ravg=3.9*10^8;
G =
6.6730e-11
me =
6.0000e+24
mm =
7.4000e+22
F = G*me*mm/ravg
F =
7.5970e+28
ravg = linspace(3.8*10^8,4.0*10^8,10)
ravg =
1.0e+08 *
Columns 1 through 5
3.8000 3.8222 3.8444 3.8667 3.8889
Columns 6 through 10
3.9111 3.9333 3.9556 3.9778 4.0000
F = G*me*mm/ravg
Error using /
Matrix dimensions must agree.
F = G*me*mm./ravg
F =
1.0e+28 *
Columns 1 through 5
7.7969 7.7515 7.7067 7.6624 7.6187
Columns 6 through 10
7.5754 7.5326 7.4903 7.4484 7.4070
>> d = 12000;pg=3.5,CO=19.4;
pg =
3.5000
fortwo= d/37*(pg)
fortwo =
1.1351e+03
fortwo*CO=
fortwo*CO=
Error: The expression to the left of the equals sign
is not a valid target for an assignment.
cost1 = fortwo*CO
cost1 =
2.2022e+04
cars= [37,29,43,31,48,32,42];
CO2=12000./cars
CO2 =
Columns 1 through 5
324.3243 413.7931 279.0698 387.0968 250.0000
Columns 6 through 7
375.0000 285.7143
CO2=12000./cars*19.4
CO2 =
1.0e+03 *
Columns 1 through 5
6.2919 8.0276 5.4140 7.5097 4.8500
Columns 6 through 7
7.2750 5.5429
cost = 12000./cars*3.9
cost =
1.0e+03 *
Columns 1 through 5
1.2649 1.6138 1.0884 1.5097 0.9750
Columns 6 through 7
1.4625 1.1143
***done***
Subscribe to:
Comments (Atom)