close all
clear all

%% Problem 1: Plotting complex quantities in Matlab
% 1a
f = [1 6 25];
g = [1 6 5];

rf = roots(f)
rg = roots(g)

% 1b
figure()
plot(real(rf),imag(rf),'ro'); hold on;
plot(real(rg),imag(rg),'b+')
ylim([-10 10]); xlim([-10 10]);

% 1c
title('Complex roots of f(s) and g(s)');  ylabel('Imaginary Part');
 xlabel('Real Part');


% 2a
t = [0:0.01:2];
f = exp(1j*2*pi*5*t);

figure()
subplot(2,1,1)
plot(t,real(f))
xlabel('Time (s)'); ylabel('Real Part');
subplot(2,1,2)
plot(t,imag(f))
xlabel('Time (s)'); ylabel('Imaginary Part');

% 2b 
figure()
subplot(2,1,1)
plot(t,abs(f))
xlabel('Time (s)'); ylabel('Magnitude');
subplot(2,1,2)
plot(t,phase(f))
xlabel('Time (s)'); ylabel('Phase (radians)');


%% Problem 2: Prime numbers, infinity, etc.

% 1a
fs123 = factor(123)
fs248 = factor(248)
fs1767 = factor(1767)
fs999999 = factor(999999)

%1b
is2 = isprime(2)
is3 = isprime(3)
is4 = isprime(4)

% 1c
x = primes(10^6);
figure()
hist(x)

% 1d 
[n, bin_centers] = hist(x)
nbins = length(n)

% 1e
figure()
hist(x,100)
title('Primes between 1 and 10^6')
ylabel('Number of primes')
xlabel('Bins')

% 2a
x = 1/0
x = 0/0

% 2b 
x=log(0)

% 2c 
x=log(-1)


%% OLD
return

t = [0:.01:5];
f = exp((2*pi*5j)*t);

subplot(211)
plot(t,phase(f))


figure()
f = sin(2*pi*t/5);
plot(t,f)








