Thursday, 6 February 2014

Euler's formula and How to plot the XY axis at the center of the plot?


%% Clearing workspace
clc;
clear all;
close all;
home;

%% Just a circle -- Euler's circle
f = 1; tm = 1/f;
numberOfSamplesPerCycle = 6; % define the sides of the polygon, if large the polygon appears as circle. If = 6, we get hexagon.

dt = tm / numberOfSamplesPerCycle;

t = 0:dt:(1/f); % the number of sides in the circle depend on the 'dt' step - this define the sample time interval

s = exp(1i*2*pi*f*t);


%% Another way to plot a circle -- Trigonometric relation with complex numbers

% We can get the same polygon using this below code:
r = abs(s);
theta = phase(s);
x = r .* cos(theta);
y = r .* sin(theta);
figure; plot(s,'g'); hold on; plot(x,y,'r*');% hold on;
legend('Euler''s style', 'polar style','Location','best');
xlabel('Real part');
ylabel('Imaginary part');
set(findall(gcf, '-property', 'FontSize'), 'FontSize', 12, 'fontWeight', 'normal')
set(findall(gcf,'Type','line'),'linewidth',2);
saveas(gcf,'fig1.jpg');
Circle plot using Euler's formula and polar form formula

%% To draw the XY axes at the centre of the plot
xL = xlim;
yL = ylim;
line([0 0], yL); %x-axis
line(xL, [0 0]); %y-axis


xlabel('Real part');
ylabel('Imaginary part');
set(findall(gcf, '-property', 'FontSize'), 'FontSize', 12, 'fontWeight', 'normal')
set(findall(gcf,'Type','line'),'linewidth',2);
saveas(gcf,'fig2.jpg');

Plotting Center XY coordinate lines

%% To draw a circle
f = 1; tm = 1/f;
numberOfSamplesPerCycle = 60; % define the sides of the polygon, if large the polygon appears as circle. If = 6, we get hexagon.

dt = tm / numberOfSamplesPerCycle;

t = 0:dt:(1/f); % the number of sides in the circle depend on the 'dt' step - this define the sample time interval
s = exp(1i*2*pi*f*t);

figure; plot(s,'r');

xL = xlim;
yL = ylim;
line([0 0], yL); %x-axis
line(xL, [0 0]); %y-axis

xlabel('Real part');
ylabel('Imaginary part');
set(findall(gcf, '-property', 'FontSize'), 'FontSize', 12, 'fontWeight', 'normal')
set(findall(gcf,'Type','line'),'linewidth',2);

saveas(gcf,'fig3.jpg');
Smooth Cirle



%% Concentric circles
r1 = 0:0.1:50;
theta1 = r1;
x1 = r1 .* cos(theta1);
y1 = r1 .* sin(theta1);

figure;plot(x1,y1,'g')
xL = xlim;
yL = ylim;
line([0 0], yL); %x-axis
line(xL, [0 0]); %y-axis

xlabel('Real part');
ylabel('Imaginary part');
set(findall(gcf, '-property', 'FontSize'), 'FontSize', 12, 'fontWeight', 'normal')
set(findall(gcf,'Type','line'),'linewidth',2);
saveas(gcf,'fig4.jpg');
Spiral plot using Euler's formula


%% Complex plane: s-plane
sigma = 0:0.1:1;
jOmega = sigma;
s = sigma + 1i * jOmega;
figure;plot(s)
xlabel('Real part');
ylabel('Imaginary part');
set(findall(gcf, '-property', 'FontSize'), 'FontSize', 12, 'fontWeight', 'normal')
set(findall(gcf,'Type','line'),'linewidth',2);

saveas(gcf,'fig5.jpg');
S-plane plot of a complex number

No comments:

Post a Comment