## 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)

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)

%

**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')

%

**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.

%

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')

%

**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