Why is my operation(with syms variables) too slow?
1 view (last 30 days)
Show older comments
Hello! I want to solve this operation:
for l=1236:4084
i= F3(l,1);
aux2=Aux23(l,:);
aux=Aux3(l,:);
xaux=x(i,:);
xaux(aux2)=[];
x1aux=x1(i,1);
x2aux=x2(i,1);
sumxxaux=sumxx(i,1);%chicas y delta
elast33(1,3)=subs(elast(1,3),[Ba,Bu,B1,B2,B3,e],[qqB2(i,4),qqB2(i,23),qqB2(i,aux(1,1)),qqB2(i,aux(1,2)),qqB2(i,aux(1,3)),qqE(i,4)]);
elast33(2,3)=subs(elast(2,3),[Ba,Bu,B1,B2,B3,e],[qqB2(i,4),qqB2(i,23),qqB2(i,aux(1,1)),qqB2(i,aux(1,2)),qqB2(i,aux(1,3)),qqE(i,4)]);
elast33(3,3)=subs(elast(3,3),[Ba,Bu,B1,B2,B3,e],[qqB2(i,4),qqB2(i,23),qqB2(i,aux(1,1)),qqB2(i,aux(1,2)),qqB2(i,aux(1,3)),qqE(i,4)]);
elast33(4,3)=subs(elast(4,3),[Ba,Bu,B1,B2,B3,e],[qqB2(i,4),qqB2(i,23),qqB2(i,aux(1,1)),qqB2(i,aux(1,2)),qqB2(i,aux(1,3)),qqE(i,4)]);
elast33(5,3)=subs(elast(5,3),[Ba,Bu,B1,B2,B3,e],[qqB2(i,4),qqB2(i,23),qqB2(i,aux(1,1)),qqB2(i,aux(1,2)),qqB2(i,aux(1,3)),qqE(i,4)]);
PQ=[ (qqA(i,4) - qqB2(i,4).*(0.13.*x1aux) - qqE(i,4).*(0.16.*x2aux+sumxxaux))./(0.13.*x1aux)
(qqA(i,4) - qqB2(i,23).*(0.16.*x2aux) - qqE(i,4).*(0.13.*x1aux+sumxxaux))./(0.16.*x2aux)
(qqA(i,4) - qqB2(i,aux(1,1)).*xaux(1,1) - qqE(i,4).*(0.13.*x1aux+0.16.*x2aux+sumxxaux-xaux(1,1)))./(xaux(1,1))
(qqA(i,4) - qqB2(i,aux(1,2)).*xaux(1,2) - qqE(i,4).*(0.13.*x1aux+0.16.*x2aux+sumxxaux-xaux(1,2)))./(xaux(1,2))
(qqA(i,4) - qqB2(i,aux(1,3)).*xaux(1,3) - qqE(i,4).*(0.13.*x1aux+0.16.*x2aux+sumxxaux-xaux(1,3)))./(xaux(1,3))];
%PQ=PQ';
Elast1(i,1)=double(subs(elast33(1,3).*PQ(1,1)));
Elast1(i,2)=double(subs(elast33(2,3).*PQ(2,1)));
Elast1(i,3)=double(subs(elast33(3,3).*PQ(3,1)));
Elast1(i,4)=double(subs(elast33(4,3).*PQ(4,1)));
Elast1(i,5)=double(subs(elast33(5,3).*PQ(5,1)));
Elast1(i,:)=[elastd3(1,3) elastd3(2,3) elastd3(3,3) elastd3(4,3) elastd3(5,3) 0 0 0 0 0 0]; end
elast is a matrix of functions where each contains the syms variables (Ba, Bu, B1, B2..e). In this way, for each iteration of "i", a new elast33 matrix is formed depending on this i and on the values taken by the syms variables qqB2, qqA, qqE.
Then I form the PQ matrix that also depends on these last variables and others that are already defined in the problem(xaux,aux,aux2..). Then I finally multiply both matrices.
I can not find where the problem of slowness is! It takes about 1 to 1.5 minutes in each iteration and I need to do it for 15,000 iterations. elast are long functions, can there be the problem? For example, in this case elast is:
elast(:,3)=
-(3*e^4 - 2*B2*e^3 - 2*B3*e^3 - 2*Bu*e^3 - 2*B1*e^3 + B1*B2*e^2 + B1*B3*e^2 + B2*B3*e^2 + B1*Bu*e^2 + B2*Bu*e^2 + B3*Bu*e^2 - B1*B2*B3*Bu)/(3*B1*e^4 + 3*B2*e^4 + 3*B3*e^4 + 3*Ba*e^4 + 3*Bu*e^4 - 4*e^5 - 2*B1*B2*e^3 - 2*B1*B3*e^3 - 2*B2*B3*e^3 - 2*B1*Ba*e^3 - 2*B2*Ba*e^3 - 2*B3*Ba*e^3 - 2*B1*Bu*e^3 - 2*B2*Bu*e^3 - 2*B3*Bu*e^3 - 2*Ba*Bu*e^3 + B1*B2*B3*e^2 + B1*B2*Ba*e^2 + B1*B3*Ba*e^2 + B2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+ B1*B2*B3*e^2 + B1*B2*Ba*e^2 + B1*B3*Ba*e^2 + B2*B3*Ba*e^2 + B1*B2*Bu*e^2 + B1*B3*Bu*e^2 + B2*B3*Bu*e^2 + B1*Ba*Bu*e^2 + B2*Ba*Bu*e^2 + B3*Ba*Bu*e^2 - B1*B2*B3*Ba*Bu)
0
0
0
0
0
Please Help! I need to solve this more faster because I have to submit my investigation.
Thanks!
0 Comments
Answers (0)
See Also
Categories
Find more on PID Controller Tuning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!