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

No comments:

Post a Comment