Clear Filters
Clear Filters

separation matrix in several matrices, "i" times

3 views (last 30 days)
So, I want to calculate the matrix (JAC). All the results throw me in a single matrix, instead of for each point (x,y,z) of the new matrix.
So how would you do that for each of (x,y,z) a new matrix
Code: a1 = 250; d1 = 645; a2 = 1000; a3 = 230; d2 = 1587.4;
% inputing for GUI minimal
x_min = 2;
y_min = 3;
z_min = 4;
% inputing for GUI resolution
x_res = 1;
y_res = 1;
z_res = 1;
% inputing for GUI maximal
x_max = 4;
y_max = 5;
z_max = 6;
% vector
x = [x_min:x_res:x_max]';
y = [y_min:y_res:y_max]';
z = [z_min:z_res:z_max]';
% calculation of internal coordinates
S3 = sin(a3);
C3 = cos(a3);
B = d2*S3 - a3*C3;
SB = sqrt(-(B*B)+a3*a3+d2*d2);
q3 = atan2(a3,d2)-atan2(B, SB);
S2 = sin(a2);
C2 = cos(a2);
q2 = atan2(S2,C2);
if length(x)==length(y)
dv =length(x);
for i=1:dv
q1(i) = atan2(y(i),x(i));
end
else
display('vektorja x in y nista enako dolga !!');
end
% calculate Jac matrix
A(i) = (-d2*cos(q1(i))*cos(q2)*sin(q3)-d2*cos(q1(i))*sin(q2)*cos(q3)-a3*cos(q1(i))*cos(q2)*cos(q3)+a3*cos(q1(i))*sin(q2)*sin(q3)-a2*cos(q1(i))*cos(q2)+a1*sin(q1(i))); % "levi zgoraj"
B(i) = (d2*sin(q1(i))*sin(q2)*sin(q3)-d2*sin(q1(i))*cos(q2)*cos(q3)+a3*sin(q1(i))*sin(q2)*cos(q3)+a3*sin(q1(i))*cos(q2)*sin(q3)+a2*sin(q1(i))*sin(q2)+a1*cos(q1(i))); % "sredina zgoraj"
C(i) = (-d2*sin(q1(i))*cos(q2)*cos(q3)+d2*sin(q1(i))*sin(q2)*sin(q3)+a3*sin(q1(i))*cos(q2)*sin(q3)+a3*sin(q1(i))*sin(q2)*cos(q3)-a2*sin(q1(i))*cos(q2)+a1*cos(q1(i))); % "desno zgoraj"
D(i) = (-d2*sin(q1(i))*cos(q2)*sin(q3)-d2*sin(q1(i))*sin(q2)*cos(q3)-a3*sin(q1(i))*cos(q2)*cos(q3)+a3*sin(q1(i))*sin(q2)*sin(q3)-a3*sin(q1(i))*cos(q2)+a3*cos(q1(i))); % "levi v sredini"
E(i) = (-d2*cos(q1(i))*sin(q2)*sin(q3)+d2*cos(q1(i))*cos(q2)*cos(q3)-a3*cos(q1(i))*sin(q2)*cos(q3)-a3*cos(q1(i))*cos(q2)*sin(q3)-a3*cos(q1(i))*sin(q2)+a3*sin(q1(i))); % "sredina v sredini"
F(i) = (d2*cos(q1(i))*cos(q2)*cos(q3)-d2*cos(q1(i))*sin(q2)*sin(q3)-a3*cos(q1(i))*cos(q2)*sin(q3)-a3*cos(q1(i))*sin(q2)*cos(q3)+a3*cos(q1(i))*cos(q2)+a3*sin(q1(i))); % "desni v sredini"
G(i) = (d2*sin(q2)*sin(q3)+d2*cos(q2)*cos(q3)+a3*sin(q2)*cos(q3)+a3*cos(q2)*sin(q3)+a2*sin(q2)+d1); % "levi spodaj"
H(i) = (d2*cos(q2)*sin(q3)+d2*sin(q2)*cos(q3)+a3*cos(q2)*cos(q3)-a3*sin(q2)*sin(q3)+a2*cos(q2)+d1); % "sredinski spodaj"
I(i) = (d2*sin(q2)*cos(q3)+d2*cos(q2)*sin(q3)-a3*sin(q2)*sin(q3)+a3*cos(q2)*cos(q3)+a2*sin(q2)+d1); % "desni spodaj"
Jac = [A, B, C; D, E, F; G, H, I]
  10 Comments
Image Analyst
Image Analyst on 27 Sep 2012
That's happened to me to. What happens more often is when I get done typing and move my right hand over to the mouse and accidentally bump the "back" button on the side of the mouse with my thumb. Sometimes going forward won't recover the text you had typed in. For that reason, and for a reason like you described, you need to use Lazarus. http://getlazarus.com/ I can't tell you how many times it's saved me a ton of re-typing. Basically it remembers what you typed into the last several edit boxes so on any web page, you can resurrect any of those texts that you've typed by right-clicking and selecting the text you want to paste into the edit box.
Star Strider
Star Strider on 27 Sep 2012
Thank you for the Lazarus reference. I'll look into it.
You comment also seems relevant to the current thread ‘What’s missing from MATLAB Central...’. I suggest you post a version of it there as well.

Sign in to comment.

Answers (5)

mirch
mirch on 26 Sep 2012
Edited: mirch on 26 Sep 2012
Yes .. I want it to be 3-dimensional!
I muss include a new variable, or just use (i)?
Or what i suppose to do, that i get 3-dimensional Jac?
Please help me with some code:)

Star Strider
Star Strider on 26 Sep 2012
Edited: Star Strider on 26 Sep 2012
First, I suggest not using i or j as variables. MATLAB uses them for its imaginary operators, and using them as variables in your code could be confusing if you also have complex numbers. (I use k1 for outer loops, k2 for the next level of inner loops, and so on. It works for me.)
Second, I am not certain what you are doing, but with that caution, I suggest you consider something like this:
for i = 1:something
A(i) = ...
.
.
.
I(i) = ...
end
Then, to create your Jac matrix:
Jac(1,1,:) = A;
Jac(1,2,:) = B;
.
.
.
Jac(3,3,:) = I;
That is probably the easiest (although not the neatest) way for you to create your Jac matrix. At least you do not have to re-write large parts of your code to create it that way.
I am guessing how you want to set up your Jac matrix. Change the code as necessary to do what you intend.
  1 Comment
mirch
mirch on 27 Sep 2012
Thank You ... but i need so much Jac matrix, how much is x length

Sign in to comment.


mirch
mirch on 27 Sep 2012
Edited: mirch on 27 Sep 2012
Now i did on this way:
%TEST IZRAČUNA MATRIKE
% dimenzije robota ACMA XR701%
a1 = 250;
d1 = 645;
a2 = 1000;
a3 = 230;
d2 = 1587.4;
% branje minimalne vrednosti
x_min = 2;
y_min = 3;
z_min = 4;
% skaliranje vrednosti
x_res = 1;
y_res = 1;
z_res = 1;
% branje maksimalne vrednosti
x_max = 5;
y_max = 6;
z_max = 7;
% grupiranje podatkov v točke
x = [x_min:x_res:x_max]';
y = [y_min:y_res:y_max]';
z = [z_min:z_res:z_max]';
% izračun notranjih koordinat
S3 = sin(a3);
C3 = cos(a3);
B = d2*S3 - a3*C3;
SB = sqrt(-(B*B)+a3*a3+d2*d2);
q3 = atan2(a3,d2)-atan2(B, SB);
S2 = sin(a2);
C2 = cos(a2);
q2 = atan2(S2,C2);
if length(x)==length(y)
dv =length(x);
for k1=1:dv
q1(k1) = atan2(y(k1),x(k1));
end
else
display('vektorja x in y nista enako dolga !!');
end
% izračun posameznik elementov Jacobijanove matrike
for k2 = 1:dv
A(k2) = (-d2*cos(q1(k2))*cos(q2)*sin(q3)-d2*cos(q1(k2))*sin(q2)*cos(q3)-a3*cos(q1(k2))*cos(q2)*cos(q3)+a3*cos(q1(k2))*sin(q2)*sin(q3)-a2*cos(q1(k2))*cos(q2)+a1*sin(q1(k2))); % "levi zgoraj"
B(k2) = (d2*sin(q1(k2))*sin(q2)*sin(q3)-d2*sin(q1(k2))*cos(q2)*cos(q3)+a3*sin(q1(k2))*sin(q2)*cos(q3)+a3*sin(q1(k2))*cos(q2)*sin(q3)+a2*sin(q1(k2))*sin(q2)+a1*cos(q1(k2))); % "sredina zgoraj"
C(k2) = (-d2*sin(q1(k2))*cos(q2)*cos(q3)+d2*sin(q1(k2))*sin(q2)*sin(q3)+a3*sin(q1(k2))*cos(q2)*sin(q3)+a3*sin(q1(k2))*sin(q2)*cos(q3)-a2*sin(q1(k2))*cos(q2)+a1*cos(q1(k2))); % "desno zgoraj"
D(k2) = (-d2*sin(q1(k2))*cos(q2)*sin(q3)-d2*sin(q1(k2))*sin(q2)*cos(q3)-a3*sin(q1(k2))*cos(q2)*cos(q3)+a3*sin(q1(k2))*sin(q2)*sin(q3)-a3*sin(q1(k2))*cos(q2)+a3*cos(q1(k2))); % "levi v sredini"
E(k2) = (-d2*cos(q1(k2))*sin(q2)*sin(q3)+d2*cos(q1(k2))*cos(q2)*cos(q3)-a3*cos(q1(k2))*sin(q2)*cos(q3)-a3*cos(q1(k2))*cos(q2)*sin(q3)-a3*cos(q1(k2))*sin(q2)+a3*sin(q1(k2))); % "sredina v sredini"
F(k2) = (d2*cos(q1(k2))*cos(q2)*cos(q3)-d2*cos(q1(k2))*sin(q2)*sin(q3)-a3*cos(q1(k2))*cos(q2)*sin(q3)-a3*cos(q1(k2))*sin(q2)*cos(q3)+a3*cos(q1(k2))*cos(q2)+a3*sin(q1(k2))); % "desni v sredini"
G(k2) = (d2*sin(q2)*sin(q3)+d2*cos(q2)*cos(q3)+a3*sin(q2)*cos(q3)+a3*cos(q2)*sin(q3)+a2*sin(q2)+d1); % "levi spodaj"
H(k2) = (d2*cos(q2)*sin(q3)+d2*sin(q2)*cos(q3)+a3*cos(q2)*cos(q3)-a3*sin(q2)*sin(q3)+a2*cos(q2)+d1); % "sredinski spodaj"
I(k2) = (d2*sin(q2)*cos(q3)+d2*cos(q2)*sin(q3)-a3*sin(q2)*sin(q3)+a3*cos(q2)*cos(q3)+a2*sin(q2)+d1); % "desni spodaj"
end
% izračun Jacobijanove matrike
for k3 = 1:dv
Jac(1,1,:) = A;
Jac(1,2,:) = B;
Jac(1,3,:) = C;
Jac(2,1,:) = D;
Jac(2,2,:) = E;
Jac(2,3,:) = F;
Jac(3,1,:) = G;
Jac(3,2,:) = H;
Jac(3,3,:) = I;
end
% zložitev Jacobijanove matrike
for k4 = 1:dv
Jac(:,:,(k4));
end
% izračun determinante matrike
for k5 = 1:dv
dJac(k5) = det(Jac(k5));
end
% izračun gibljivostnega indeksa
for k6 = 1:dv
w(k6) = sqrt(dJac(k6)*(Jac(k6)));
end
So i get so much of matrix, how much points i have (x,y,z)
  1 Comment
Star Strider
Star Strider on 27 Sep 2012
1. You do not need the k3 loop. It does the same thing three times and the results do not change.
2. What do you want to do in your k4 loop? You are not doing anything with your Jac matrix here.
3. What do you want to do in you k5 loop? What parts of Jac do you want the determinant of? Your Jac matrix is [3 x 3 x 4]. Your reference to Jac(k5) is calling the single elements [Jac(1,1,1) Jac(2,1,1) Jac(3,1,1) Jac(1,2,1)] in order.
4. I do not know what you are doing in your k6 loop, but we will consider that after we get your k4 and k5 loops doing what you want them to do.

Sign in to comment.


mirch
mirch on 27 Sep 2012
  1. I deleted k3 loop
  2. This loop is because i want 3x3 matrix n times. Not all 3x3 matrices in one matrix. So i dont want 3x3x4 - just 3x3 n times.
  3. I want determinant of all this Jac matrices (3x3)
  4. then i calculate with Jac and determinant of Jac some indeks for every point (x,y,z)
  5 Comments
mirch
mirch on 2 Oct 2012
w(k6) = sqrt(dJac(k6)*(Jac(k6)));
i have one error in my calculations ... Jac(k6) must be transpose Jac(k6).
I'm sorry I told so late
How I tranpose every Jac to tranpose(Jac)?
Please help
Star Strider
Star Strider on 2 Oct 2012
Edited: Star Strider on 2 Oct 2012
You cannot transpose a matrix with more than two dimensions, so you cannot simply transpose w since your w matrix is [3 x 3 x 4]. I do not know what in that situation you want to transpose, so I cannot give you specific advice. However, if you want to transpose every page of the 3rd dimension of w, I suggest:
for k6 = 1:dv
wt(:,:,k6) = w(:,:,k6)';
end
If you want to do something else, change that code appropriately.
Also, you have two options for transposing your w matrix, since it is complex.
The usual transpose operator (') is actually the complex conjugate transpose. So if you want the complex conjugate transpose, and we define wt as the transpose of w, do as I described in the previous loop.
If you want to do the transpose and not also do the complex conjugate operation, use the ‘dot-transpose’ operator (.') and do this:
for k6 = 1:dv
wt(:,:,k6) = w(:,:,k6).';
end
What you do depends on what you want to do with your wt matrix later.

Sign in to comment.


mirch
mirch on 2 Oct 2012
If We start again, because I doing all wrong.
I define only the cube size, and density of points. (x_min, x_res, x_max, y_min, ...)
Then for every kind of that point need calculation.
Then I get from this calculation w, which is point to point differend.
This w would then define the color of the point
So if I have cube 3 times 3 times 3 big, i should calculate 27 calculations for w.
How do I do this?
For now I have this: %TEST IZRAČUNA MATRIKE clear all % dimenzije robota ACMA XR701% a1 = 250; d1 = 645; a2 = 1000; a3 = 230; d2 = 1587.4;
% branje minimalne vrednosti
x_min = 1;
y_min = 2;
z_min = 3;
% skaliranje vrednosti
x_res = 1;
y_res = 1;
z_res = 1;
% branje maksimalne vrednosti
x_max = 3;
y_max = 4;
z_max = 5;
% grupiranje podatkov v točke
x = [x_min:x_res:x_max]';
y = [y_min:y_res:y_max]';
z = [z_min:z_res:z_max]';
% ustvarjanje mreže
[X, Y, Z] = meshgrid(x, y, z);
%scatter3 (X(:), Y(:), Z(:), 10)
% izračun notranjih koordinat
S3 = sin(a3);
C3 = cos(a3);
B = d2*S3 - a3*C3;
SB = sqrt(-(B*B)+a3*a3+d2*d2);
q3 = atan2(a3,d2)-atan2(B, SB);
S2 = sin(a2);
C2 = cos(a2);
q2 = atan2(S2,C2);
q1 = atan2(Y,X);
[m,n]=size(q1);
%k1m = 1:m;
%k1n = 1:n;
JA = (-d2*cos(q1)*cos(q2)*sin(q3)-d2*cos(q1)*sin(q2)*cos(q3)-a3*cos(q1)*cos(q2)*cos(q3)+a3*cos(q1)*sin(q2)*sin(q3)-a2*cos(q1)*cos(q2)+a1*sin(q1)); % "levi zgoraj"
JB = (d2*sin(q1)*sin(q2)*sin(q3)-d2*sin(q1)*cos(q2)*cos(q3)+a3*sin(q1)*sin(q2)*cos(q3)+a3*sin(q1)*cos(q2)*sin(q3)+a2*sin(q1)*sin(q2)+a1*cos(q1)); % "sredina zgoraj"
JC = (-d2*sin(q1)*cos(q2)*cos(q3)+d2*sin(q1)*sin(q2)*sin(q3)+a3*sin(q1)*cos(q2)*sin(q3)+a3*sin(q1)*sin(q2)*cos(q3)-a2*sin(q1)*cos(q2)+a1*cos(q1)); % "desno zgoraj"
JD = (-d2*sin(q1)*cos(q2)*sin(q3)-d2*sin(q1)*sin(q2)*cos(q3)-a3*sin(q1)*cos(q2)*cos(q3)+a3*sin(q1)*sin(q2)*sin(q3)-a3*sin(q1)*cos(q2)+a3*cos(q1)); % "levi v sredini"
JE = (-d2*cos(q1)*sin(q2)*sin(q3)+d2*cos(q1)*cos(q2)*cos(q3)-a3*cos(q1)*sin(q2)*cos(q3)-a3*cos(q1)*cos(q2)*sin(q3)-a3*cos(q1)*sin(q2)+a3*sin(q1)); % "sredina v sredini"
JF = (d2*cos(q1)*cos(q2)*cos(q3)-d2*cos(q1)*sin(q2)*sin(q3)-a3*cos(q1)*cos(q2)*sin(q3)-a3*cos(q1)*sin(q2)*cos(q3)+a3*cos(q1)*cos(q2)+a3*sin(q1)); % "desni v sredini"
JG = (d2*sin(q2)*sin(q3)+d2*cos(q2)*cos(q3)+a3*sin(q2)*cos(q3)+a3*cos(q2)*sin(q3)+a2*sin(q2)+d1); % "levi spodaj"
JH = (d2*cos(q2)*sin(q3)+d2*sin(q2)*cos(q3)+a3*cos(q2)*cos(q3)-a3*sin(q2)*sin(q3)+a2*cos(q2)+d1); % "sredinski spodaj"
JI = (d2*sin(q2)*cos(q3)+d2*cos(q2)*sin(q3)-a3*sin(q2)*sin(q3)+a3*cos(q2)*cos(q3)+a2*sin(q2)+d1); % "desni spodaj"
so ... then I need for every point 'Jac' ... Jac = [JA, JB, JC; JD, JE, JF; JG, JH, JI]
Please help me to continue

Tags

Community Treasure Hunt

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

Start Hunting!