Linear Transformation Contest: Sample Code in Matlab

Words
191
Reading
1 min
Listen
Play
8y

Here I will post my sample code corresponding to the running contest on linear transformation.

clear  %clear all variables from matlab memory workspace
close all % close all figure windows (like previous plots)
clc % clear the screen

%% This section just creates a square 2D mesh of vectors
[X Y] = meshgrid(-10:1:10); % coordinates for vector positions
VX = X; % X,Y components of vector
VY = Y;
quiver(X, Y, VX, VY, 2)
title('Input: The 2D space')
axis square

%% reshaping the vectors for linear transformation
YY=reshape(VY,[1 21*21]);
XX=reshape(VX,[1 21*21]);
XY=[XX ;YY];

A=[1 2;-0.5 1]; % Our transformation matrix A
XY_t=A*XY; % linear transform operation

%% This section just creates a "transformed" 2D mesh of vectors
X_t=reshape(XY_t(1,:),[21 21]);
Y_t=reshape(XY_t(2,:),[21 21]);
figure
quiver(X_t, Y_t, VX, VY, 2)
axis square
title('Output: The transformed 2D space')

Don't use modified versions of this code as a solution! (A friendly warning.)

The input and output of the code is given below:

Input

alt

Output

The transformation matrix considered is
A=

1      2
-0.5   1

o.png

Yes I have copy-pasted my code from github!

Don't blame me for plagiarism because I have uploaded it yesterday in github.

I am tagging #steemstem because this contest comes as a part of Linear algebra article I wrote recently. So I don't expect #steemstem vote for this. See those articles below:


Join #steemSTEM

Join the active science community #steemSTEM at discord: https://discord.gg/BZXkmWw

And to steemSTEM beginners:

You can ask for help in our discord page. There are people ready to help you there.


gif courtesy: rocking-dave@rocking-dave


All images without image sources are my creations :)

Follow me dexterdev@dexterdev


 ____ _______  ______ _________ ____ ______    
/  _ /  __\  \//__ __/  __/  __/  _ /  __/ \ |\
| | \|  \  \  /  / \ |  \ |  \/| | \|  \ | | //
| |_/|  /_ /  \  | | |  /_|    | |_/|  /_| \// 
\____\____/__/\\ \_/ \____\_/\_\____\____\__/
Linear Transformation Contest: Sample Code in Matlab | Ecency