Thursday, October 22, 2015

Day 14 - Symbolic Plotting

We started the day learning different types of plotting with ezplot command. We learned other useful ez commands like ezmeh ezsurf and ezplot3 to name a few. We then move onto a ballistic problem again, here is a picture:
The real one for ballistic problem.
We then worked on calculus and integration in matlab. And finished the day with differential  equations examples.
Here are some pictures of examples done in class.




Conclusion:
Today was a day of learning about the ways to plot with the ez command. We then spent the rest of the day seeing how matlab takes cares of some calculus, integration and differential equations.


%%Hmwk 14
v = [1 2 3 4 5 6] %volume
t = [2494 1247 831 623 499 416] %temperture
z = interp1(v,t,3.8)    %interplation of v at 3.8
z1 = interp1(v,t,3.8,'cubic')   %interplation of v at 3.8 cubic
z2 = interp1(t,v,1000)  %interplation of t at 1000 linear
z3 = interp1(t,v,1000,'cubic') %interplation of t at 1000 cubic
%%Hmwk 14-2
plot(v,t)
coef1 = polyfit(v,t,1) %eq for 1 order
coef2 = polyfit(v,t,2) %eq for 2nd order
coef3 = polyfit(v,t,3) %eq for 3rd order
coef4 = polyfit(v,t,4) %eq for 4th order
c1 = polyval(coef1,v)   %polyval of v 1
c2 = polyval(coef2,v)   %polyval of v 2
c3 = polyval(coef3,v)   %polyval of v 3
c4 = polyval(coef4,v)   %polyval of v 4
plot(v,t,'o',v,c1)  %plot w/ 1st order
plot(v,t,'o',v,c2)  %plot w/ 2nd order
plot(v,t,'o',v,c3)  %plot w/ 3rd order
plot(v,t,'o',v,c4)  %plot w/4 order
%% Hmwwk 14-3
n = 1
v = [1 2 3 4 5 6] %volume
P = [2494 1247 831 623 499 416] %temperture
R = 8.314 %R value
k = polyfit(1./v,P,1) %polyfit slop
k2 = polyval(k,1./v) %Polyval uses polfit eq and plus number into
k3 = plot(1./v,k2) %plot of slope
temp = k(1)./R  %temperture close to 300K

Tuesday, October 20, 2015

Day 13 - Symbolic math

 We started the day with structure array example, finishing he one from last class. We then move on to a symbolic algebra example with the use of  𝑘=𝑘𝑜𝑒−𝑄/𝑅𝑇. Here is a picture:
Symbolic example in class.
We then move onto manipulation symbolic expressions. We then move on to a ballistic problem. Here is a picture:
Ballistic problem part 1.

 Conclusion:
We again worked with structure array to get a better understanding. We spent the rest of the time using symbolic math to solve problems. Let matlab do all the hard algebra is a good idea.



%hmwk 13

%hmwk 13-1
format short eng
syms pi f m g L I
eq1 = 2*pi*f == sqrt(m*g*L/I) %eq of penduilum
solve (eq1,'L') %solve for L
%hmwk 13 - 2
syms v0 t th g
dx = sym('v0*t*cos(th)')
dx1 = subs(dx,{v0,th},{100,(pi/4)})
dy = sym('v0*t*sin(th)-.5*g*t^2')
dy1 = subs(dy,{v0,g,th},{100,9.8,(pi/4)})
ezplot(dx1,dy1,[0,20])
title('ballastic distance')
xlabel('distance in meters')
ylabel('height in meters')
t = [0:.5:20]
%% 13 - 3
syms t
h = -0.12*t^4 + 12*t^3 - 380*t^2 + 4100*t +220
v = diff(h) %diff of h = velocity
acc = diff(v) %diff of velocity = accel
ans1 = max(double(solve(h,'t'))) %for real alt
ans2 = max(double(solve(v,'t'))) %for real velocity
ans3 = max(double(solve(acc,'t'))) %for real accleration
subplot(2,2,1)  %plot alt
ezplot(h,[0:48])
title('altitude')
xlabel('time')
ylabel('height in meters')
subplot(2,2,2) %plot speed
ezplot(v,[0:48])
title('velocity')
xlabel('time')
ylabel('speed')
subplot(2,2,3) %plot acc
ezplot(acc,[0:48])
title('acceleration')
xlabel('time')
ylabel('acc')
hmaxt =solve(v,'t')
hmax=real(max(double(subs(h,'t',hmaxt)))) %max height 17000 when third v = 0
%% 13- 4
syms f x n
f = sym(20*x) %force
work = int(f,'0','n-1') %work eq
% work = 10*(n-1 )^ 2
w2 = subs(work,'n','2') %sub in 2 feet for n
w3 = max(double(solve('25 = 10*(n-1)^2'))) %amount streched
%% 13 - 5
syms x tan(x)
y = sym('tan(x)')
y1 = int(y)     %int of tanx
eq1 = matlabFunction(y1) %matlab function
fplot(eq1,[-5,5]) %fplot of a function


Thursday, October 15, 2015

Day - 12 Arrays and different data types

 We started he day with array types in matlab. Then talked about the data types, such as classes for each type. We discussed floating point number, integers and double. Finally went over string and char and then move onto symbolic and logical data. We finished the with creating a structure array with planetary data and called the data in the m-file.
Here are some pictures of examples done in class.

Conclusion:
 We learned of different arrays and different data types. Each matrices type of data have classes. We worked with logical and symbolic functions.


%HMWK 12
%12 - 1
syms x a b c d X %loads variables
ex1 = x^2-1 %
EX1 = sym('x^2 - 1 ')
eq1 = sym(' x^2=1 ')
EQ1 = sym('x^2 = 1 ')
subs(ex1,x,4) %answwer is 15
subs(EX1,x,4) %answer is 15
subs(eq1,x,4) %answer is 16==1
%12 - 2
v = [0:10]
subs(ex1,x,v) %answwer is array
subs(EX1,x,v) %answer is array
subs(eq1,x,v) %answer is [==] exprssion
%12 - 3
ex4 = a*x^2 + b*x + c
EX4 = sym('a*x ^2 + b*x + c ')
eq4 = sym('a*x^2 + b*x + c=0 ')
EQ4 = sym('a*x ^2 + b*x + c = 0 ')
subs(ex4,{'a' 'b' 'c' 'x'},{3 4 5 1:0.5:5}) %answer in fractions
subs(EX4,{'a' 'b' 'c' 'x'},{3 4 5 1:0.5:5}) %answer same as above
subs(eq4,{'a' 'b' 'c' 'x'},{3 4 5 1:0.5:5}) %answer == returns
subs(EQ4,{'a' 'b' 'c' 'x'},{3 4 5 1:0.5:5}) %answer same as above
%12 - 4
%They are symbolic
%12 - 5
syms m g l L f %loads variables
X = sym('f*2*pi = sqrt(m*g*L/l)') %epressed version
solve(X,'L') %solving X for L
%12 - 6
syms mtops mbottoms x %loads variable
water = sym(' 50 = 0.2*mtops + 0.65*mbottoms')    %water
ethanol = sym('-100*x + 0.35*mtops + 0.25*mbottoms')    %ethanol
methanol = sym(' 50 = 100*x + 0.45*mtops + 0.1*mbottoms')     %methanol
[mtops mbottoms x] = solve(water,ethanol,methanol) %answer
k = double([mtops mbottoms x]) %converts symbloic answers into double bytes for fprint
k1 = sprintf(' mass top %3.2f \n mass bottom %3.2f \n percent methanol %3.2f \n',k) %outprint
msgbox(k1) %display box

Tuesday, October 13, 2015

Day - 11 Solving System of Equations


We started the day with working on circuit problem here is a picture:

Solving Simultaneous Equations in an Electric Circuit ex.
We then talked about reduced row echelon function, rref and we can rewrite matrices in that form.
We then did an example of  a material balances desalination unit. Here is a picture:

Material Balances on a Desalination Unit

We then move onto a Force on a Statically Determinate Truss example. Here is picture:

A Force on a Statically Determinate Truss

Lastly we finish the day with special types of matrices like pascal and magic.

Conclusion:
Solving linear algebra systems is easy with matlab. However using which type on method is important, like ref, rref, or other forms like the first example tied in class.

%%HMWK 11
%hmwk 11-1
doublea = 5 - 3i %double complex, 16 bytes
singlea = single(5 - 3i)  %Single complex, 8 bytes
k1 = doublea^100 %double complex raise 100 power
k2 = singlea^100 %single comples raise 100 power
% k1 returns intergers vaules of double complex
% k2 returns -inf and +inf in single complex
% the reason being the scope of single cant handle 100 power byte "weight"
%hmwk 11-2
char(85) %one element
num2str(8)
char(56)
char(53)
%hmwk 11-3
mess = input('words','s') %message input
encode = char(mess+11) %encode message
decode = char(encode-11) %decode message
%hm11-4
k = 1;
response = menu('Would you like to enter planetary data?','yes','no');
while response==1
disp('Remember to enter strings in single quotes')
planetary(k).name = input('Enter a planet names','s');
planetary(k).mass = input('Enter the mass in multiples of earth''s mass: ');
planetary(k).year = input('Enter the length of the planetary year in Earth years: ');
planetary(k).velocity = input('Enter the mean orbital velocity in km/sec: ');
planetary(k)
increment = menu('Was the data correct?','Yes','No');
switch increment
case 1
increment = 1;
case 2
increment = 0;
end
k = k+increment;
response = menu('Would you like to enter more planetary data?','yes','no');
end
plan2 = {planetary.name; planetary.mass; planetary.year; planetary.velocity}
oo = struct2table(planetary) %struct table command

%hmwk 11-5
metal = {'Aluminum' ,'Copper ','Iron ','Molybdenum ','Cobalt ','Vanadium '} %metal names
sy = ['AL', 'Cu', 'Fe', 'Mo', 'Co', 'V'] %element symbolys
atomicn = int8([13 29 26 42 27 23]) %atomic number of elements
atomicw = [26.98 63.55 55.85 95.94 58.93 50.94] %atomic weight of elements
den = single([2.71 8.94 7.87 10.22 8.9 6.0]) %density of each element g/cm
ty = ['FCC','FCC','BCC','BCC','HCP','BCC'] %type of structre per element
super = {metal sy atomicn atomicw den ty} %super cell of 6 different arrays
cell2table(super)
sup1 = [super{1}(4) super{4}(4) super{6}(10:12)] %cell sup1 is forth deep in super cell
sup2 = [super{1}]' %names of elements in metal cell
sup3 = sum(super{4}/length(super{4})) %average atomic weight of forth column