P1: Given Scripts/Functions
MakeConic
function Z = MakeConic(A,B,C,D,E,F)
% Represents the conic defined by
%
% Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
Z = struct('A',A,'B',B,'C',C,'D',D,'E',E,'F',F);
P1A
% Script P1A
%
% Plots the coeficients A, B, C, D, E, and F as the conic
%
% 2x^2 + xy + 3y^2 - x + y - 2
%
% is rotated around the origin (0,0).
close all
n = 200;
Kappa = MakeConic(2,1,3,-1,1,-2);
phi = linspace(0,2*pi,n)';
P = zeros(n,6);
% Store the A, B, C, D, E, and F values in the columns of P
for k=1:n
Z = RotateConic(Kappa,phi(k));
P(k,:) = [Z.A Z.B Z.C Z.D Z.E Z.F];
end
% Plot the A, B, and C values
plot(phi,P(:,1),'-',phi,P(:,2),':',phi,P(:,3),'--')
xlabel('phi (the counter-clockwise rotation angle)')
legend('A','B','C')
title('Values of A, B, C when 2x^2 + xy + 3y^2 - x + y - 2 is rotated \phi radians')
% Plot the D, E, and F values
figure
plot(phi,P(:,4),'-',phi,P(:,5),':',phi,P(:,6),'--')
xlabel('phi (the counter-clockwise rotation angle)')
legend('D','E','F')
title('Values of D, E, F when 2x^2 + xy + 3y^2 - x + y - 2 is rotated \phi radians')
P1B
% Script P1B
clc
disp(' A B C D E F a b h k phi')
disp('-----------------------------------------------------------')
for A = 0:1
for B = 0:2
for C = 0:2
for D = [-1 1]
for E = [-1 1]
for F = [-1 1]
Kappa = MakeConic(A,B,C,D,E,F);
Eta = MakeEllipse(Kappa);
if ~isempty(Eta)
a = Eta.a; b = Eta.b; h = Eta.h; k = Eta.k; phi = Eta.phi;
s1 = sprintf('%2d %2d %2d %2d %2d %2d',A,B,C,D,E,F);
s2 = sprintf('%6.3f %6.3f %6.3f %6.3f %6.3f',a,b,h,k,phi);
disp([s1 ' ' s2])
end
end
end
end
end
end
end
P1C
% Script P1C
% Illustrates ShowEllipse
close all
% Display the ellipse (x/3)^2 + (y/2)^2 = 1
% and what is obtained by rotating it counterclockwise pi/6, pi/3, and pi/2
% radians.
for i=1:4
subplot(2,2,i)
ShowEllipse(MakeEllipse(RotateConic(MakeConic(1/9,0,1/4,0,0,-1),(i-1)*pi/6)))
title(sprintf('angle = %3d degrees',(i-1)*30))
end
% Display 2x^2 + xy + 3y^2 -x + y -2 = 0
figure
Eta = MakeEllipse(MakeConic(2,1,3,-1,1,-2));
ShowEllipse(Eta)
title(sprintf('a = %6.4f b = %6.4f (h,k) = (%6.4f,%6.4f) phi = %6.4f',...
Eta.a, Eta.b, Eta.h, Eta.k, Eta.phi))