Monday, March 20, 2017

Week Ten

Not Shocking People Whilst Using MATLAB

Week Ten

%1 
clear all;
close all;
x = [1 2 3 4 5];
y = 2.^x;
plot(x, y, 'LineWidth', 6)
xlabel('Numbers', 'FontSize', 12)
ylabel('Results', 'FontSize', 12)

clear all; %2 clear all removes prior variable and function definitions

close all; %3 closes any prior command based windows (i.e. plot, ext.)

x = [1 2 3 4 5]; 

y = 2.^x;

plot(x, y, 'LineWidth', 6)

xlabel('Numbers', 'FontSize', 12)

ylabel('Results', 'FontSize', 12)

%4 when typing x and pressing enter, the prior logged values for x appear
%the matrix has one row and five colomns.

%5 the semicolon is used when defining the function, which without it, would
%the values would not be stored and the plot function nor defined

%6 If a . is not used before the power, the x values will be read as a whole
%matrix instead of being recognized individually.

%7 It affects the thickness of the line that is plotted

%8
clear all; 
close all; 
x = [1 2 3 4 5];

y = 2.^x;

plot(x, y, '-rO','LineWidth', 5,'markersize',18)

xlabel('Numbers', 'FontSize', 12)

ylabel('Results', 'FontSize', 12)



%9
clear all; 
close all; 
x = [1; 2; 3; 4; 5;];

y = 2.^x;

plot(x, y, '-rO','LineWidth', 5, 'markersize',18)

xlabel('Numbers', 'FontSize', 12)

ylabel('Results', 'FontSize', 12)



%The plot stays the same, as these colons are already expressed when the .
%is placed before the ^

%10
clear all; 
close all; 
x = [1 2 3 4 5];

y = 2.^x;

plot(x, y, ':ks','LineWidth', 6, 'markersize',14)
grid on
xlabel('Numbers', 'FontSize', 12)

ylabel('Results', 'FontSize', 12)



%11
%a : on google calculator
%sin(30)=0.5

%b
%sin(30) = -0.9880
%They are differenct because google automatically calculates sin using
%degree values inside the parenthesis, whereas when in MATLAB, sin(x) is a
%radian command, while sind(x) is using degrees

%c
%sind(30) = 0.5000

%12
clear all;
close all;
t = linspace(0,0.12,10);
y = 10*sin(100*t);
u = linspace(0,0.12,1000);
z = 10*sin(100*u);

plot(t,y,'-ro')
hold on
plot(u,z,'-k')

xlabel('Time(s)')
ylabel('y function')
legend('Course','Fine')



%13 
%Differences: Two plots were formatted atop one another using the hold on
%command, the variables were defined using intervals of range of values,
%there was a legend added.

%14
clear all;
close all;
t = linspace(0,0.12,10);
y = 10*sin(100*t);
u = linspace(0,0.12,1000);
z = 10*sin(100*u);
f=find(z>5)
z(f)=5
plot(t,y,'-ro')
hold on
plot(u,z,'-k')

xlabel('Time(s)')
ylabel('y function')
legend('Course','Fine')


PART B
1.

2.
%PART B
%2

clear all;
close all;
f=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2]
v=[3.25 3.82 3.66 3.58 3.5 3.4 3.3 3.2 3.07 2.96 2.85 2.75 2.63 2.53 2.45 2.35 2.28 2.2 2.12 2.05]

plot(f,v,'-ro')

xlabel('frequency(KHz)')
ylabel('V out(V)')
grid on


3.
fc= 1/(2*3.141593*7500*0.000000022)
fc =

  964.5753

%The voltage at 965 is 3

clear all;
close all;
f=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2];
v=[3.25 3.82 3.66 3.58 3.5 3.4 3.3 3.2 3.07 2.96 2.85 2.75 2.63 2.53 2.45 2.35 2.28 2.2 2.12 2.05];
c=find(v>3)
v(c)=3
plot(f,v,'-ro')

xlabel('frequency(KHz)')
ylabel('V out(V)')
grid on


%4
clear all;
close all;
f=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2];
v=[3.25 3.82 3.66 3.58 3.5 3.4 3.3 3.2 3.07 2.96 2.85 2.75 2.63 2.53 2.45 2.35 2.28 2.2 2.12 2.05];
c=find(v>3)
v(c)=3
plot(f,v,'-ro')
hold on
y=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2];
u=[3.25 3.82 3.66 3.58 3.5 3.4 3.3 3.2 3.07 2.96 2.85 2.75 2.63 2.53 2.45 2.35 2.28 2.2 2.12 2.05];
plot(y,u,'--k')
legend('output with cutoff','output')

xlabel('frequency(KHz)')
ylabel('V out(V)')
grid on
%5
%1 & 3



%2
clc;
clear all;
close all;
f=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2]
v=[3.25 3.82 3.66 3.58 3.5 3.4 3.3 3.2 3.07 2.96 2.85 2.75 2.63 2.53 2.45 2.35 2.28 2.2 2.12 2.05]

plot(f,v,'-ro')

xlabel('frequency(KHz)')
ylabel('V out(V)')




8 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. your graphs for the low and high pass filter looks different from ours, I think it is because we used different values of capacitor and resistor which makes the cut off frequency to be around 200 Hz. Also, It is hard to read the blog because the questions aren't included , putting the questions would makes it much easier to read the blog.

    Good job guys!

    ReplyDelete
  3. When you just copy and paste your code from Matlab the formatting makes both the code and blog hard to read. The graphs all look good though.

    ReplyDelete
  4. nice job this week. i noticed your last two graphs looked a lot different from ours. our high and low pass filter graphs had a more smooth incline or decline. im not sure why yours looked how it did especially the high pass. any ideas? also what did you guys think was the hardest part about this week? we had difficulties with the find function

    ReplyDelete
  5. Data and graphs look well done, though it could have been formatted a bit better. I especially like your Part B #1 chart showing the measured vs calculated cut off.

    ReplyDelete
  6. Great blog. Our codes look similar but it looks like you did a couple things different then us which is cool to see it done differently.

    ReplyDelete
  7. I like how you included the % sign in your blog this week. Because in matlab that's how you comment out comments. Your graphs and tables look very informative this week. Like when you color coded your calculated and measured cutoffs. We are close to the same values so I'm sure you did it right.

    ReplyDelete