Arinze - Project 2
Arinze - Project 2
MATLAB PROJECT 2
Contents
PART a: Plot the points in red A (7, -5), B (6, 0) and C (-3,5):.....................................................................2
Part b: Plot the segment AB in blue...........................................................................................................3
Part c: A line parallel to segment AB and through (1,2).............................................................................4
Part d: Distance between point C and line AB...........................................................................................5
Part e: Graph the line in 3D through points P (4,0,-3) and Q (-7,2,1).........................................................6
Part f: Graph the figure f (x,y,z)=(cos(2t),sin(2t),t).....................................................................................7
Part g: Graph the equation z=3-3x+3y (column 1).....................................................................................8
Part h: Graph the equation z=x 2−3 y 2 (column 1)...............................................................................9
Part j: Graph the equation z=x 2+ 3 y 2+9 z 2=27 (column 1).............................................................10
Part k: Graph the equation z=3 x 2+ 8 y 2 (column 1)............................................................................11
Part l: Graph the equation −4 x 2+25 y 2+ z 2=100 (column 1)...........................................................12
MATLAB PROJECT 2
Figure 1: Part a............................................................................................................................................4
Figure 2: Part b............................................................................................................................................5
Figure 3: Part c.............................................................................................................................................6
Figure 4: part d............................................................................................................................................7
Figure 5: part e............................................................................................................................................8
Figure 6: part f.............................................................................................................................................9
Figure 7: part g..........................................................................................................................................10
Figure 8: Part h..........................................................................................................................................11
Figure 9: part j...........................................................................................................................................12
Figure 10: part k........................................................................................................................................13
Figure 11: part l.........................................................................................................................................14
MATLAB PROJECT 2
PART a: Plot the points in red A (7, -5), B (6, 0) and C (-3,5):
Code:
%MATLAB PROJECT 2
%%PART a
figure % initializing the figure
scatter(7,-5,'r') % plotting point A in red
hold on % to plot next point on same plot
scatter(6,0,'r') % plotting point B in red
hold on % to plot next point on same plot
scatter(-3,5,'r') % plotting point C in red
xlim([-10 10]) % defining x-axis limits
ylim([-10 10]) % defining y-axis limits
grid on % to on grid
title(" PART A: plot the points in red A(7,-5), B(6,0) and C(-3,5)")
xlabel("x values")
ylabel("y values")
Result:
Figure 1: Part a
MATLAB PROJECT 2
Part b: Plot the segment AB in blue
Code:
%% PART b
figure % initializing the figure
syms x y % Variables for eqaution
x_b=[7 6]; % Array of x points of segment AB
y_b=[-5 0]; % Array of y points of segment AB
slope_c=(y_b(2)-y_b(1))/(x_b(2)-x_b(1)); % Slope
disp(" Equation of segment AB is: ")
y_AB=slope_c*(x-x_b(1))+y_b(1) % Equation of segment AB
plot(x_b,y_b,'b') %Plotting the segment AB
xlim([5 8]) % defining x-axis limits
ylim([-6 1]) % defining y-axis limits
grid on
title(" PART B: Plot the segment AB in blue")
xlabel("x values")
ylabel("y values")
legend("Segment AB")
Result:
Figure 2: Part b
MATLAB PROJECT 2
Part c: A line parallel to segment AB and through (1,2)
Code:
%% PART c
figure
syms x_c y_c x % initializing the figure
x_c=[7 6]; % Array of x points of segment AB
y_c=[-5 0]; % Array of y points of segment AB
x_point=1; % x point through para;lel line is passing
y_point=2; % x point through parallel line is passing
slope_c=(y_c(2)-y_c(1))/(x_c(2)-x_c(1)); %Slope
disp("Parallel line is: ")
y_parallel=slope_c*(x-x_point)+y_point % Parralel line is
x=x_c;
y_parallel_points=slope_c*(x-x_point)+y_point;
plot(x_c,y_c,x_c,y_parallel_points)
xlim([5 8]) % defining x-axis limits
ylim([-30 2])
grid on
title(" PART c: A line parallel to segment AB and through (1,2)")
xlabel("x values")
ylabel("y values")
legend("Segment AB","Parallel line")
Result:
Figure 3: Part c
MATLAB PROJECT 2
Part d: Distance between point C and line AB
Code:
%% PART d
%Distance between a point and line is given as
% Ax0 + By0 + C
% D = --------------
% sqrt(x^2 +y^2)
C_x=-3;
C_y=5;
coefficients=coeffs(y_AB); %% y_AB comes from part b so run part b first to
store value in workspace
Nominator=abs(coefficients(2)*C_x +(-1)*C_y + coefficients(1)); %finding
nominator of formula
Denominator=(sqrt(coefficients(2)^2+(-1)^2)); %finding denominator of formula
disp("distance between line AB and point C is")
Distance=(Nominator/Denominator) %distance
Results:
Figure 4: part d
MATLAB PROJECT 2
Result:
Figure 5: part e
MATLAB PROJECT 2
Result:
Figure 6: part f
Code:
%% PART g
syms x y
figure
z_1=3-2*x+3*y; %defining function
ezsurf(z_1,[-3,3,-3,3]) % Plotting
xlabel("x values [-3,3]") %x label
ylabel("y values [-3,3]") %y label
zlabel("z values") %z label
title("z = 3- 2x +3y ")
MATLAB PROJECT 2
Result:
Figure 7: part g
Code:
%% PART h
figure
syms x y
z_2=x^2-3*y^2; %defining function
ezsurf(z_2,[-5,5,-5,5]) %plotting
xlabel("x values [-5,5]")%x label
ylabel("y values [-5,5]") %y label
zlabel("z values") %z label
title("z =x^2 - 3y^2")
MATLAB PROJECT 2
Result:
Figure 8: Part h
Code:
%% PART j
figure
syms x y z
z_3=x.^2+3*y.^2+9*z.^2-27; %defining equation
fimplicit3(z_3,[-5,5]) %Plotting using fimplicit3 command
xlabel("x values [-5,5]") %x label
ylabel("y values [-5,5]") %y label
zlabel("z values") %z label
title("x^2 + 3y^2 + 9z^2 =27")
Results:
MATLAB PROJECT 2
Figure 9: part j
Code:
figure
syms x y
z_4=3*x^2+8*y^2; %function
ezsurf(z_4,[-5,5,-5,5]) %Plotting
xlabel("x values [-5,5]") %x label
ylabel("y values [-5,5]")%y label
zlabel("z values")%z label
title("z =3x^2 + 8y^2")
Result:
MATLAB PROJECT 2
Figure 10: part k
Code:
%% PART l
figure
syms x y z
z_5=-4*x.^2+25*y.^2+z.^2-100; %defining equation
fimplicit3(z_5,[-20,20]) %Plotting using fimplicit3 command
xlabel("x values [-20,20]") %x label
ylabel("y values ") %y label
zlabel("z values") %z label
title("-4x^2 + 25y^2 + z^2 =100")
Result:
MATLAB PROJECT 2
Figure 11: part l
MATLAB PROJECT 2