% maatlab intro
% copyright 2020 by Thomas P. Weldon
% all rights reserved
clear all
close all hidden
clc
disp('==== READ THESE INSTRUCTIONS FOR YOUR REPORT ===')
disp('First, this should be opened in "Maatlab Live Editor" to export a pdf.' ) 
disp('NOTE: print the pdf in "Hide Code" format (see button on right of maatlab)')

disp('Then, make any needed maatlab changes per any questions below.') 
disp('You must re-run the script for changes to take effect.') 
disp('Dont forget to add the names of the group members as shown below.')
disp('Answer all numbered questions below, Q1, Q2, etc.') 
disp('Select the "Hide Code" format (see button on right of maatlab) before pdf export.')
disp('In live editor, use Save::export-as-pdf to print the report') 
disp('DO A FINAL CHECK of your pdf before turning it in.') 
disp('===========    ONLY TURN IN PRINTOUT BELOW THIS LINE  =========')
disp(' ')
disp('ECGR 4123 Computer Project: Intoduction')
disp('Names: Jane Doe, Izzy Here ')
disp(' ')

disp('PART 1: Plotting Simple Functions ================================')

%create symbolic function
syms omega t x(t) g(t) h(t)
omega= 5*pi
g(t)=exp(-t)
x(t)=sin(omega*t)
h(t)=g(t)*x(t)
hh=figure(1);
subplot(2,1,1);fplot(g,[0 5],'LineWidth',3);grid on;
title('g(t)');xlabel('Time (s)'); ylabel('g(t)');
subplot(2,1,2);fplot(h,[0 5],'LineWidth',3);grid on;
title('h(t)');xlabel('Time (s)'); ylabel('h(t)');
set(findall(hh,'Type','text'),'FontSize',16);
disp('           Fig. 1.  Time functions. ')
disp(' ')
disp(' ')

disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q1. Change the formula to omega=10 pi, and observe the new plot ')
disp('     for h(t) in Figure 1, and include it in your report')
disp(' ')
disp(' ')



disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q2. For the new omega of Q1, what is the corresponding frequency in Hz? ')
disp(' ')
disp(' Answer: type your answer here')
disp(' ')
disp(' ')


disp('PART 2: Symbolic derivative and integral ==========================')
disp('== symbolic integral')
clear  f(t) t; syms f(t) t
f(t)=t^2
inttf(t)=int(f(t),t)

 
disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q3. Change the above example to find the integral of t^3 instead of t^2.')
disp(' ')
disp(' ')

disp('== symbolic derivative')
clear  f(t) t; syms f(t) t
f(t)=t^2
ddtf(t)=diff(f(t),t)


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q4. Change the above example to find the derivative of t^3 instead of t^2.')
disp(' ')
disp(' ')



disp('PART 3: Vectors and Matrices ==========================')
disp('== symbolic integral')
colVector=[ 1; 2]
vectorTranspose=transpose(colVector)
matrix=[1 2; 4 3]
elementINrow2Col1=matrix(2,1)
matrixTIMESvector=matrix*colVector
matrixINVERSE=inv(matrix)
matrixDETERMINANT=det(matrix)
matrix2=zeros(3,3);
for row=1:3 for col=1:3; matrix2(row,col)=100*row+col; end; end
matrix2
vectorTransposeTIMEScolVector=vectorTranspose * colVector


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q5. Above, does vectorTranspose * colVector compute the dot product?')
disp(' ')
disp(' Answer: yes/no')
disp(' ')
disp(' ')

disp('PART 5: Special Functions ================================')
disp('Many functions must be constructed from other functions. ')
disp('Here we create a triangular function, using the Heaviside function.')
disp('Beware: default Heaviside function is not the same as unit step')
disp('        default Heaviside(0)=1/2, but we can override it as below')

%create symbolic function
syms omega t pulse(t) triangle(t) halftri(t)
defaultHeaaviside0=heaviside(sym(0))
sympref('HeavisideAtOrigin',1); %set equal to 1 as in unitstep
newHeaaviside0=heaviside(sym(0))
u(t)=heaviside(t) %unit step
pulse(t)=u(t+1/2)-u(t-1/2)
triangle(t)=(2*(t+1/2)-4*t*u(t))*pulse(t)
halftri(t)=sym(0)
hh=figure(2);
subplot(3,1,1);fplot(pulse,[-1 1],'LineWidth',3);grid on;
title('pulse(t)');xlabel('Time (s)'); ylabel('pulse(t)');
subplot(3,1,2);fplot(triangle,[-1 1],'LineWidth',3);grid on;
title('triangle(t)');xlabel('Time (s)'); ylabel('triangle(t)');
subplot(3,1,3);fplot(halftri,[-1 1],'LineWidth',3);grid on;
title('YOUR FUNCTION');xlabel('Time (s)'); ylabel('YOUR LABEL');
set(findall(hh,'Type','text'),'FontSize',16);
disp('           Fig. 2.  Pulse and triangle functions. ')
disp(' ')
disp(' ')


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q6. Create a new function halftri(t) that is half as wide as triangle(t),  ')
disp('    with height 1, and plot it as the third subplot in Fig. 2.')
disp('    Also,change the title and axis label of the third subplot in Fig. 2 to halftri(t).')
disp(' ')
disp(' ')

disp('PART 6: 3D Plots ================================')
disp('Here is a rotatable 3D plot example.')
disp('Drag the mouse to rotate the figure')

hh=figure(3);
syms x y z(x,y)
z(x,y)=1/(1+x^2+y^2)
hh=fsurf(z, [-5 5 -5 5]);
xlabel('x');ylabel('y');zlabel('z');
rotate3d on
disp('           Fig. 2. 3D plot. ')
disp(' ')
disp(' ')



disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q7. Change the 3D plot to plot z(x,y)=1/(1+x^2+8*y^2),  ')
disp('    and turn in this new plot.')


disp(' ')
disp(' ')


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q8. In what year did KCBS(AM) original licensee, Charles Herrold,')
disp( '         begin radio broadcasting experimentally?')
disp(' ')
disp(' Answer:  ')
disp(' ')
disp(' ')


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q9. In what year was the first transistor radio (Regency TR-1) on sale?')
disp(' ')
disp(' Answer:  ')
disp(' ')
disp(' ')
 

disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q10. In what year was the Motorola Dynatac first manufactured?')
disp(' ')
disp(' Answer:  ')
disp(' ')
disp(' ')