0% found this document useful (0 votes)
4 views12 pages

Lab Report_ Linear Transformations (II)

This lab report investigates linear transformations on a structured input space, focusing on visualization, analysis of transformation effects, and the significance of matrix multiplication order. It includes detailed MATLAB implementations for generating and transforming a 2D grid, demonstrating the impact of shear, reflection, and rotation transformations. The findings emphasize the non-commutative nature of matrix multiplication and the importance of precise plotting techniques for accurate visualization of transformations.

Uploaded by

b23087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Lab Report_ Linear Transformations (II)

This lab report investigates linear transformations on a structured input space, focusing on visualization, analysis of transformation effects, and the significance of matrix multiplication order. It includes detailed MATLAB implementations for generating and transforming a 2D grid, demonstrating the impact of shear, reflection, and rotation transformations. The findings emphasize the non-commutative nature of matrix multiplication and the importance of precise plotting techniques for accurate visualization of transformations.

Uploaded by

b23087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Lab Report: Linear Transformations (II)

Risa Niranjan Chaudhari


B23228
Objective
This lab aims to investigate the effects of linear transformations on a structured input space. The
primary objectives include:

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.

Part 1: Input Space Plot


Objective:-

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:-

●​ The input space is constructed using MATLAB’s meshgrid function to generate


coordinate pairs over the specified range.
●​ Instead of plotting the entire grid at once, for loops are used to plot individual vertical
and horizontal lines, offering flexibility in visualization.
●​ The structured grid consists of horizontal and vertical lines:
○​ Horizontal grid lines are represented as solid red ('r-'), emphasizing row-wise
coordinate variations.
○​ Vertical grid lines are represented as dashed blue ('b--'), highlighting
column-wise variations in the space.
●​ Axis labels and a title are added for better readability.
MATLAB Code:-
x = -2:1:3;
y = -2:1:3;
[X, Y] = meshgrid(x, y);

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');

Results and Inference:-

●​ 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.

Input Space Visualization:-


Part 2: Transformation Analysis (Question 1)
Objective

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

Effect of T6 (Shear Transformation):

●​ The transformation matrix T6 introduces a shear effect along the x-axis.


●​ This means that each point's x-coordinate is shifted proportionally to its y-coordinate
while keeping the y-values unchanged.

Effect of T7 (Reflection Across the Y-Axis):

●​ 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.

Composition of T6 and T7 (Sequential Transformation Impact):

●​ 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.

Loop-Based Plotting Ensures Accuracy:

●​ 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.

Transformed Space Visualization:


Part 3: Transformation Analysis (Question 2)
Objective:-

To examine the effects of transformations T8 and T9, including rotation and reflection
transformations.

Transformation Matrices:-

Simulation Setup:-

●​ The input space is initialized using meshgrid.


●​ Applying T8 (Rotation by 45 Degrees): The transformation matrix T8 performs a
counterclockwise rotation by 45 degrees, modifying both the x- and y-coordinates of
each point in the input space.g.
●​ Applying T9 (Reflection Across the X-Axis): The transformation matrix T9 is applied
separately to the input space. T9 reflects the transformed grid across the x-axis, flipping
all points vertically while preserving their x-coordinates.
●​ Composition of T10 (T8 Followed by T9): Mathematically, T10 is represented as:​
T10=T9×T8 where T8 first rotates the input space, and T9 then reflects the rotated grid
across the x-axis..
●​ Visualization and Comparison Using Subplots:A total of four subplots are
generated to systematically illustrate the transformation process:
1.​ Initial Input Space: Displays the original structured grid before any
transformation is applied.
2.​ After Applying T8: Shows the effect of applying transformation matrix T8, which
combines rotation and scaling, altering both the orientation and spacing of points.
3.​ After Applying T9: Demonstrates the impact of T9, which reflects the space
across the x-axis, flipping all points vertically.
4.​ After Sequential Application of T8 Followed by T9 (Composition of T8(T9)):
Illustrates the cumulative effect of first applying T8, which rotates and scales the
space, and then T9, which performs reflection.
●​ This visualization also reinforces the concept that matrix multiplication is not
commutative, as applying transformations in a different sequence would yield a different
final 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)], 'blue--');
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)
% rotation transformation
theta = 45;
theta_rad = deg2rad(theta);
t8 = [cos(theta_rad), -sin(theta_rad); sin(theta_rad),
cos(theta_rad)];
input_space = [X(:), Y(:)]';
input_space
transformed_points = t8 * input_space;
xt = reshape(transformed_points(1, :), size(X));
yt = reshape(transformed_points(2, :), size(Y));
% transformed grid
for i = 1:size(X,2)
plot(xt(:, i), yt(:, i), 'b--');
hold on;
end
for j = 1:size(Y,1)
plot(xt(j, :), yt(j, :), 'red');
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('transformation 8');
xlim([min(xt(:)), max(xt(:))]);
ylim([min(yt(:)), max(yt(:))]);
subplot(4,1,3)
t9 = [1, 0; 0, -1];
transformed_points = t9 * input_space;
xt = reshape(transformed_points(1, :), size(X));
yt = reshape(transformed_points(2, :), size(Y));
for i = 1:size(X, 2)
plot(xt(:, i), yt(:, i), 'b--');
hold on;
end
for j = 1:size(Y, 1)
plot(xt(j, :), yt(j, :), 'red');
hold on;
end
xlim([min(xt(:)), max(xt(:))]);
ylim([min(yt(:)), max(yt(:))]);
xlabel('X axis');
ylabel('Y axis');
title('transformation 9');
subplot(4,1,4)
% Transformation 2
t10 = [1/sqrt(2), -1/sqrt(2); -1/sqrt(2), -1/sqrt(2)];
transformed_points = t10 * input_space;
xt10 = reshape(transformed_points(1, :), size(X));
yt10 = reshape(transformed_points(2, :), size(Y));
for i = 1:size(X,2)
plot(xt10(:, i), yt10(:, i), 'b--');
hold on;
end
for j = 1:size(Y,1)
plot(xt10(j, :), yt10(j, :), 'red');
hold on;
end
xlabel('X axis');
ylabel('Y axis');
title('Transformation: Composition');
xlim([min(xt10(:)) max(xt10(:))]);
ylim([min(yt10(:)) max(yt10(:))]);
hold off;
Results and Inference

Effect of T8 (Rotation by 45 Degrees):

●​ T8 rotates the input space counterclockwise by 45 degrees, modifying both x- and


y-coordinates.
●​ This transformation alters the grid’s alignment, tilting originally horizontal and vertical
lines while maintaining relative spacing.

Effect of T9 (Reflection Across the X-Axis):

●​ 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.

Composition of T8 and T9 (Sequential Transformation Impact):

●​ Applying T8 first rotates the space, changing its orientation.


●​ Applying T9 afterward reflects the rotated grid across the x-axis.
●​ The final transformation differs significantly from applying each separately, emphasizing
that matrix multiplication is not commutative.

Loop-Based Plotting Ensures Accuracy:

●​ 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.

Transformed Space Visualization:


Conclusion
●​ Linear transformations introduce significant alterations in spatial structure, including
shear, rotation, and reflection.
●​ The loop-based plotting approach ensures fine control over the transformation
process, enhancing visualization accuracy.
●​ Sequential transformations produce different outcomes depending on order,
reinforcing the non-commutative nature of matrix multiplication.
●​ MATLAB provides an effective environment for studying transformation effects
systematically, bridging theory and computational application.

You might also like