clc
clear all
close all
a=-0.71;
b=1.44;
r=0.1:0.1:3;
theta=(-pi):(1/99):(pi);

% Function 1: f(z) = e^z/(z-a)
figure(1)
for n=1:1:length(r)
    rad=r(n);
    cir=rad*exp(1i*theta);
    subplot(121)
    scatter(real(cir),imag(cir),'c.')
    hold on
    pause(0.00001)
end
subplot(121)
scatter(real(a),imag(a),'rx');

[res1,res2]=fctn1(a,r,theta);
subplot(122)
plot(r,abs(res1),'b-')
hold on
plot(r,abs(res2),'r--')
xlabel('radius of the circle, r')
ylabel('Absolute value of Contour Integration')
title(strcat('Contour integration of e^z/(z-a) over a circle of radius r with a=',num2str(a)))
legend('Piecewise approximation method','Cauchy Integral formula');

% Function 2: f(z) = e^z/(z-a)(z-b)
figure(2)
for n=1:1:length(r)
    rad=r(n);
    cir=rad*exp(1i*theta);
    subplot(121)
    scatter(real(cir),imag(cir),'c.')
    hold on
    pause(0.00001)
end
subplot(121)
scatter(real(a),imag(a),'rx');
hold on;
scatter(real(b),imag(b),'mx');

[res1,res2]=fctn2(a,b,r,theta);
subplot(122)
plot(r,abs(res1),'b-')
hold on
plot(r,abs(res2),'r--')
xlabel('radius of the circle, r')
ylabel('Absolute value of Contour Integration')
title(strcat('Contour integration of e^z/(z-a)(z-b) over a circle of radius r with a=',num2str(a),'and b=',num2str(b)))
legend('Piecewise approximation method','Cauchy Integral formula');

% Function 3: f(z) = e^z/(z-a)^2
figure(3)
for n=1:1:length(r)
    rad=r(n);
    cir=rad*exp(1i*theta);
    subplot(121)
    scatter(real(cir),imag(cir),'c.')
    hold on
    pause(0.00001)
end
subplot(121)
scatter(real(a),imag(a),'rx');


[res1,res2]=fctn3(a,r,theta);
subplot(122)
plot(r,abs(res1),'b-')
hold on
plot(r,abs(res2),'r--')
xlabel('radius of the circle, r')
ylabel('Absolute value of Contour Integration')
title(strcat('Contour integration of e^z/(z-a)^2 over a circle of radius r with a=',num2str(a)))
legend('Piecewise approximation method','Cauchy Integral formula');

% Function 4: f(z) = e^z/(z-a)^2(z-b)
figure(4)
for n=1:1:length(r)
    rad=r(n);
    cir=rad*exp(1i*theta);
    subplot(121)
    scatter(real(cir),imag(cir),'c.')
    hold on
    pause(0.00001)
end
subplot(121)
scatter(real(a),imag(a),'rx');
hold on;
scatter(real(b),imag(b),'mx');

[res1,res2]=fctn4(a,b,r,theta);
subplot(122)
plot(r,abs(res1),'b-')
hold on
plot(r,abs(res2),'r--')
xlabel('radius of the circle, r')
ylabel('Absolute value of Contour Integration')
title(strcat('Contour integration of e^z/(z-a)^2(z-b) over a circle of radius r with a=',num2str(a),'and b=',num2str(b)))
legend('Piecewise approximation method','Cauchy Integral formula');

% Function 5: f(z) = e^z/(z-a)^2(z-b)^2
figure(5)
for n=1:1:length(r)
    rad=r(n);
    cir=rad*exp(1i*theta);
    subplot(121)
    scatter(real(cir),imag(cir),'c.')
    hold on
    pause(0.00001)
end
subplot(121)
scatter(real(a),imag(a),'rx');
hold on;
scatter(real(a),imag(a),'rx');

[res1,res2]=fctn5(a,b,r,theta);
subplot(122)
plot(r,abs(res1),'b-')
hold on
plot(r,abs(res2),'r--')
xlabel('radius of the circle, r')
ylabel('Absolute value of Contour Integration')
title(strcat('Contour integration of e^z/(z-a)^2(z-b)^2 over a circle of radius r with a=',num2str(a),'and b=',num2str(b)))
legend('Piecewise approximation method','Cauchy Integral formula');
