Lab Report_ Linear Transformations (II)
Lab Report_ Linear Transformations (II)
1. Visualizing the Input Space: Constructing a structured 2D grid representation using
different plotting techniques.
2. Applying and Analyzing Transformations: Implementing transformation matrices to
examine their effects on spatial properties such as orientation, scaling, shearing, and
reflection.
3. Understanding Sequential Transformations: Investigating how compositions of
transformations alter the input space and demonstrating the significance of matrix
multiplication order.
4. Exploring Computational Approaches: Comparing different MATLAB implementations
for transformation visualization and analyzing their effectiveness.
5. Enhancing Mathematical Intuition: Understanding the interplay between
transformation matrices and geometric changes in a structured manner.
To generate a structured 2D grid representation of the input space in ℝ2, covering x- and
y-coordinates from -2 to 3. The grid is visualized using distinct line styles to differentiate
between horizontal and vertical elements.
Simulation Setup:-
figure;
for i = 1:length(x)
plot([x(i) x(i)], [y(1) y(end)], 'blue--');
hold on;
end
for j = 1:length(y)
plot([x(1) x(end)], [y(j) y(j)], 'red');
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('Input Space Plot');
● The structured grid is successfully plotted, ensuring that horizontal and vertical lines are
visually distinct and evenly spaced.
● Using an explicit loop-based plotting approach instead of meshgrid provides better
control over individual grid elements, allowing precise visualization and modification of
transformations.
● Using explicit loop-based plotting instead of mesh allows better control over individual
grid elements, aiding in the analysis of transformations.
To analyze the effects of applying transformations T6 and T7 to the input space, as well as their
composition.
Transformation Matrices:-
Simulation Setup:-
● The input space is first initialized using meshgrid, which generates a structured grid
over the range x = -2 to 3 and y = -2 to 3. The grid points are stored as coordinate pairs
in a 2 × N matrix, allowing transformation using matrix multiplication.
● The first transformation, T6, is applied to the input space. Since T6 introduces shear
along the x-axis, each point’s x-coordinate is modified in proportion to its y-coordinate,
while the y-values remain unchanged. The transformed points are then reshaped back
into the original grid structure and plotted in a subplot for comparison.
● Next, T7 is applied to the input space. This transformation reflects all points across the
y-axis by negating their x-coordinates while keeping y-coordinates unchanged. The
transformed grid is reshaped and plotted in a separate subplot to visualize the effect of
the reflection.
● To analyze the combined effect of these transformations, T7 is applied after T6,
meaning the new transformation matrix is T8 = T7 × T6. This composition first shears the
grid using T6 and then reflects the sheared space using T7. The final transformed points
are again reshaped and displayed in a subplot, illustrating how matrix composition
affects the overall transformation.
● All transformations are plotted as four subplots to allow easy comparison between the
original input space, the effects of T6 and T7 individually, and their combined effect. This
visualization clearly demonstrates that matrix multiplication is not commutative, as
reversing the order of transformations would yield a different result.
MATLAB Code (Structured)
x = -2:1:3;
y = -2:1:3;
[X, Y] = meshgrid(x, y);
figure;
subplot(4,1,1)
% Original Grid
for i = 1:length(x)
plot([x(i) x(i)], [y(1) y(end)], 'b--');
hold on;
end
for j = 1:length(y)
plot([x(1) x(end)], [y(j) y(j)], 'r');
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('Original Grid');
subplot(4,1,2)
% Transformation 1
t6 = [1, 1; 0, 1];
input_space = [X(:), Y(:)]';
input_space
transformed_points = t6*input_space;
xt6 = reshape(transformed_points(1, :), size(X));
yt6 = reshape(transformed_points(2, :), size(Y));
yt6
size(Y,1)
% Plot Transformed Grid
for i = 1:size(X, 2)
plot(xt6(:, i), yt6(:, i), 'b--');
hold on;
end
for j = 1:size(Y, 1)
plot(xt6(j, :), yt6(j, :), 'red');
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('Transformation: 6');
xlim([min(xt6(:)) max(xt6(:))]);
ylim([min(yt6(:)) max(yt6(:))]);
subplot(4,1,3)
% Transformation 2
t7 = [-1, 0; 0, 1];
transformed_points = t7*input_space;
xt7 = reshape(transformed_points(1,:), size(X));
yt7 = reshape(transformed_points(2,:), size(Y));
% Plot Transformed Grid
for i = 1:size(X, 2) % iterating column wise
plot(xt7(:, i), yt7(:, i), 'b--');
hold on;
end
for j = 1:size(Y, 1)
plot(xt7(j, :), yt7(j, :), 'red'); %iterating rowwise
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('Transformation: 7');
xlim([min(xt7(:)) max(xt7(:))]);
ylim([min(yt7(:)) max(yt7(:))]);
subplot(4,1,4)
% Transformation 2
t8 = t7*t6;
transformed_points = t8*input_space;
xt8 = reshape(transformed_points(1,:), size(X));
yt8 = reshape(transformed_points(2,:), size(Y));
yt8
% Plot Transformed Grid
for i = 1:size(X, 2)
plot(xt8(:, i), yt8(:, i), 'b--');
hold on;
end
for j = 1:size(Y, 1)
plot(xt8(j, :), yt8(j, :), 'red');
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('Transformation: Composition');
xlim([min(xt8(:)) max(xt8(:))]);
ylim([min(yt8(:)) max(yt8(:))]);
Results and Inference
● The transformation matrix T7 reflects the input space across the y-axis, flipping the
horizontal positions of all points.
● This transformation reverses the x-coordinates of all points while keeping their
y-coordinates unchanged.
● Applying T6 first shears the space along the x-axis, altering the alignment of grid points.
● Then applying T7 reflects the sheared space across the y-axis, further distorting the grid.
● The final transformed space is significantly different from simply applying each
transformation separately, demonstrating that matrix multiplication order affects the
result.
● The script uses size(X,1) and size(Y,1) to correctly iterate through grid points
while plotting transformed structures.
● This approach ensures that each transformed point is accurately mapped,
preserving the grid’s relative structure after transformation.
To examine the effects of transformations T8 and T9, including rotation and reflection
transformations.
Transformation Matrices:-
Simulation Setup:-
● T9 reflects the grid across the x-axis, flipping all points vertically while keeping
x-coordinates unchanged.
● This transformation inverts the y-values of all points, creating a mirrored effect.
● The script iterates over size(X,1) and size(Y,1) to correctly plot the transformed
grid.
● This ensures precise mapping and preserves the grid’s structure after
transformations.