Linear Transformation Contest: Sample Code in Matlab

in #steemstem8 years ago (edited)

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

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


All images without image sources are my creations :)

Follow me @dexterdev


 ____ _______  ______ _________ ____ ______    
/  _ /  __\  \//__ __/  __/  __/  _ /  __/ \ |\
| | \|  \  \  /  / \ |  \ |  \/| | \|  \ | | //
| |_/|  /_ /  \  | | |  /_|    | |_/|  /_| \// 
\____\____/__/\\ \_/ \____\_/\_\____\____\__/
Sort:  

Congratulations @dexterdev! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on any badge to view your own Board of Honor on SteemitBoard.

To support your work, I also upvoted your post!
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Do not miss the last announcement from @steemitboard!