% Unit 2 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%==========================================
% sine function (mask out negative values)
%==========================================
clear all
close all
clc

% physical constants
A      = 12.5;
Phi0   = -45.;
PhiEnd = Phi0+360.;

% numerical constants
N      = 1000.;

% conversion factor from degrees to radians
deg2rad = pi/180;

% generate an array containing N values from Phi0 to PhiEnd
Phi    = [Phi0:(PhiEnd-Phi0)/(N-1):PhiEnd];

% sine function
Sine   = A*sin(Phi*deg2rad);

% plot sine function
plot(Phi,Sine)
xlabel('angle [radian]')
ylabel('sine')
axis([Phi0 PhiEnd -1.1*A 1.1*A])

% mask out all negative values
i = find(Sine < 0);
Sine(i) = 0;

% plot sine function
hold on
plot(Phi,Sine,'r')
hold off
