# How to find x and y component of a vector

57 views (last 30 days)
Luca Amicucci on 17 Sep 2020
Answered: Jon on 17 Sep 2020
Hi!
I was doing an exercise about position velocity and accelleration of a four-bar linkage.
So, for example, I wrote the vector position as: (given input angular velocity and acceleration )
for i = 1:360
theta2(i,1) = i*pi/180; % theta 2 in radians
w2(i,1) = ...
alpha2(i,1) = ...
% I find w3,w4,alpha3,alpha4 and then I calculate..
Ra(i,1) = R2*exp(1i*theta2(i,1)); % vector position of link 1 ( input link )
% thus deriving Ra --> Va
Va(i,1) = R2*1i*w2(i,1)*exp(1i*theta2(i,1)); % vectot velocity of link 1
% thus deriving Va --> Aa
Aa(i,1) = (R2*alpha2(i,1)*1i*exp(1i*theta2(i,1)))-(R2*w2(i,1)^2*exp(1i*theta2(i,1))); % vector acceleration of link 1
...
end
Now , I want ask :
Is the x-component of these vectors the real part and the y-component the imag. part ?
Aax = real(Aa) ?
Aay = imag(Aa) ?
and
The complete, for example, acceleration is Aa = sqrt(Ax^2 + Ay^2) , so if i need to plot the Aa , i plot sqrt(Ax^2 + Ay^2) ??

Jon on 17 Sep 2020
Yes I think you should be able to recover the x and y components using the real and imaginary parts, that is using MATLAB's real and imag functions as you have suggested.
You can get the magnitude of the acceleration using your expression, Aa = sqrt(Ax^2 + Ay^2) where I assume the Ax and Ay were recovered from the complex values using the real and imaginary parts.
It is simpler though to just use MATLAB's abs command which finds the magnitude of a complex value.
So if the acceleration is given by the complex value Aa you just plot abs(Aa).

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!