Slow routine to make 3D mesh
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
The following code creates a surface mesh from A, B,C defined below. The vpasolver routine runs much slower than I expect for this type of problem, at over a minute. I'm looking for ways to speed up execution. Any ideas. The same routine written in Prime 3.1 executes in under a second.
%Set Area of Cable Components
Aa=0.6247;
As=0.1017;
Ac=0.726346;
w(1)=1.093;
RTSDrake=31500;
%Set Thermal Expansion Coeff of Cable Components, Tref
AlphaAL=12.8E-6;
AlphaST=6.4E-6;
AlphaCOMP=10.455446E-6;
Tref=70;
%Set Initial Tension Hinitial of Cables, Span Length, Slack, Fit Variable
Hinitial=1000;
Span=1000;
Slack=0.01;
Init_Fit=-0.00461765;
ii=1;
jj=1;
kk=1;
t=0;
while kk<20
while Slack/Span*100<=0.5
A(ii,jj)=Slack/Span*100;
B(ii,jj)=w(kk);
syms H;
Ten=vpasolve(2*(H/w(kk))*sinh(Span*w(kk)/(2*H))-Span-Slack==0,H,Hinitial);
C(ii,jj)=double(Ten/Ac);
HTension(ii,jj)=C(ii,jj)*Ac;
Slack=Slack+0.1;
ii=ii+1;
t=t+1;
end
Slack=0.01;
w(kk+1)=w(kk)+0.15;
ii=1;
jj=jj+1;
kk=kk+1;
end
0 Commenti
Risposte (1)
Shlok
il 27 Ago 2024
Hi Gerald,
I understand that your code is using “vpasolver”, which can be slow, especially for larger problems. Hence, I'd recommend switching to “fsolve” instead, as it offers several advantages. Unlike “vpasolve”, which relies on symbolic computation, “fsolve” is designed for numerical solutions, using iterative methods to find the roots of nonlinear equations. This approach typically results in faster execution, especially for large or complex systems, due to its reliance on numerical approximations rather than symbolic expressions.
Here’s how you can modify your code:
tic
%Set Area of Cable Components
Aa=0.6247;
As=0.1017;
Ac=0.726346;
w(1)=1.093;
RTSDrake=31500;
%Set Thermal Expansion Coeff of Cable Components, Tref
AlphaAL=12.8E-6;
AlphaST=6.4E-6;
AlphaCOMP=10.455446E-6;
Tref=70;
%Set Initial Tension Hinitial of Cables, Span Length, Slack, Fit Variable
Hinitial=1000;
Span=1000;
Slack=0.01;
Init_Fit=-0.00461765;
ii=1;
jj=1;
kk=1;
t=0;
while kk<20
while Slack/Span*100<=0.5
A(ii,jj)=Slack/Span*100;
B(ii,jj)=w(kk);
% replace the 'vpasolver' with 'fsolve'
eqn = @(H) 2 * (H / w(kk)) * sinh(Span * w(kk) / (2 * H)) - Span - Slack;
options = optimoptions('fsolve', 'Display', 'off');
Ten = fsolve(eqn, Hinitial, options);
C(ii,jj)=double(Ten/Ac);
HTension(ii,jj)=C(ii,jj)*Ac;
Slack=Slack+0.1;
ii=ii+1;
t=t+1;
end
Slack=0.01;
w(kk+1)=w(kk)+0.15;
ii=1;
jj=jj+1;
kk=kk+1;
end
toc
After making this change, I saw the execution time drop significantly from 79.2 seconds to just 2.35 seconds on my machine. Keep in mind that the results might differ slightly due to the numerical approximations used by “fsolve”.
For more details on “fsolve”, you can refer to the following MathWorks documentation link:
Hope it helps.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!