How to get new double array from sym array
Ältere Kommentare anzeigen
I'm doing assigenment for Foward kinematics. But the loop doesn't stop. What do i have to do? The code is below. Thank you for your help.
syms a1 a2 a4 a5;
d1=100;d2=250;d3=50;d4=250;d5=100;
% define transformation matrix
T_01=[sin(a1) 0 cos(a1) 0; -cos(a1) 0 sin(a1) 0; 0 -1 0 d1; 0 0 0 1];
T_12=[cos(a2) 0 sin(a2) d2*cos(a2); sin(a2) 0 -cos(a2) d2*sin(a2); 0 1 0 0; 0 0 0 1];
T_23=[-1 0 0 0; 0 0 1 0; 0 1 0 d3; 0 0 0 1];
T_34=[cos(a4) -sin(a4) 0 d4*cos(a4); sin(a4) cos(a4) 0 d4*sin(a4); 0 0 1 0; 0 0 0 1];
T_4H=[cos(a5) -sin(a5) 0 d5*cos(a5); sin(a5) cos(a5) 0 d5*sin(a5); 0 0 1 0; 0 0 0 1];
% Calculate center of E.E. frame
T_0H=T_01*T_12*T_23*T_34*T_4H;
P = transpose([0 0 0 1]);
P1_0=T_0H*P;
% Get array of center point
for a1 = 0:pi/1000:pi/2
for a2 = 0:-pi/500:-pi
for a4 = 0:pi/1000:pi/2
for a5 = 0:-pi/1000:-pi/2
P1_0;
end
end
end
end
3 Kommentare
Dyuman Joshi
am 19 Okt. 2023
Bearbeitet: Dyuman Joshi
am 19 Okt. 2023
Can you specify what the purpose of the 4 nested for loops is?
With the 4 nested for loops, you are running
fprintf('~ %d Billion iterations', floor(501*501*501*501/1e9))
That's a big number. No wonder it is going to take much time to run, with whatever is performed inside the loops.
Dyuman Joshi
am 19 Okt. 2023
If you mean from the points from the for loops, then they are not 500 points, they are ~63 billion points together.
And as Walter has mentioned in his answer - you might not have enough storage for that amount of data.
Akzeptierte Antwort
Weitere Antworten (1)
the cyclist
am 19 Okt. 2023
Bearbeitet: the cyclist
am 19 Okt. 2023
I expect it does stop, eventually. In the code below, I changed the loop over a5, so that it executes only 1/100th as many iterations, and the code took 36 seconds. I expect your code would have taken about one hour to complete. Did you wait that long?
Note that I did not spend any time looking at whether your code is sensible or not.
syms a1 a2 a4 a5;
d1=100;d2=250;d3=50;d4=250;d5=100;
% define transformation matrix
T_01=[sin(a1) 0 cos(a1) 0; -cos(a1) 0 sin(a1) 0; 0 -1 0 d1; 0 0 0 1];
T_12=[cos(a2) 0 sin(a2) d2*cos(a2); sin(a2) 0 -cos(a2) d2*sin(a2); 0 1 0 0; 0 0 0 1];
T_23=[-1 0 0 0; 0 0 1 0; 0 1 0 d3; 0 0 0 1];
T_34=[cos(a4) -sin(a4) 0 d4*cos(a4); sin(a4) cos(a4) 0 d4*sin(a4); 0 0 1 0; 0 0 0 1];
T_4H=[cos(a5) -sin(a5) 0 d5*cos(a5); sin(a5) cos(a5) 0 d5*sin(a5); 0 0 1 0; 0 0 0 1];
% Calculate center of E.E. frame
T_0H=T_01*T_12*T_23*T_34*T_4H;
P = transpose([0 0 0 1]);
P1_0=T_0H*P;
tic
n = 0;
% Get array of center point
for a1 = 0:pi/1000:pi/2
for a2 = 0:-pi/500:-pi
for a4 = 0:pi/1000:pi/2
for a5 = 0:-pi/10:-pi/2
P1_0;
n = n+1;
end
end
end
end
toc
n
1 Kommentar
동욱
am 19 Okt. 2023
Kategorien
Mehr zu Code Performance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!