%Homework # 2

%% Problem # 1

%Writing a m.file function, which is in a seperate file. See 'HW2_myDiv.m'

Result = HW2_myDiv(10,5)


%% Problem # 2
%Creating an anonymous function that does the same job.

myDivAnon = @(Input1,Input2)Input1./Input2; % The dot is added to give element-wise operations. 

Output = myDivAnon(10,5)


%% Problem # 3
% Here is my exact code that generated the plot

X=linspace(0,6,100); %Create finely spaced array for plotting
Y=cos(X*5);          %function 1
Y2=sin(X*5);         %function 2   

F=figure(); % This creates the figure
Ax=axes();  % This creates a set of axes within the figure
P=plot(X,Y); %This plots Y vs X in the axes

Ax.XLabel.String='Time (s)'; %Changes the axis label
Ax.YLabel.String='Signal (V)'; %Changes the axis label
P.LineWidth=5; % makes the plot line thicker
P.LineStyle='--'; %Change style
P.Marker='none'; %Remove marker
P.Color='r'; %Change color
T=title('Experiment 1'); %Add title
hold on; %Plot next plot into same axis
P2=plot(X,Y2);
P2.Color='g'; %Change color
legend('run 1', 'run 2'); %Create legend
Ax.XLabel.FontSize=6; %Change font sizes on axis
Ax.YLabel.FontSize=20; %Change font sizes on axis
T.FontName='Stencil'; %Change title font (you may not have Stencil)
Ax.FontWeight='bold'; %Bold the axis fonts. 


%% Problem # 4
% Airy Disk

%Create an array
X=(-10:.5:10)
Y=(-10:.5:10)

%Create X and Y grids 
[XGrid,YGrid]=meshgrid(X,Y)

%Calculate an array of distances from center
R=sqrt(XGrid.^2+YGrid.^2)

a = find(R==0);                     %Finding the index of the origin, where MATLAB will give 'NAN'.

AiryDisk = (2*besselj(1,R)./R).^2;  
AiryDisk(a) = 4*0.25;               %Replacing NAN with the given value.

figure
Ax=axes();
M=mesh(XGrid,YGrid,AiryDisk)        %3D mesh plot

%I can remove the axis labels this way:
Ax.XTickLabel={}
Ax.YTickLabel={}
Ax.ZTickLabel={}

%Make lines black (not necessary)
M.EdgeColor='k'




