MATLAB循环计算特别慢,计算不难但是算着算着就不动了。

MATLAB循环计算特别慢,计算不难但是算着算着就不动了。

X=0,Z=1,thetas=26,Ap=3.5;thetaw=35;Nc=9.0;k=1.26;Ncp=9.0;d=0.084;f=1.3;En=2;deltX=2;
while thetas>0
X=X+deltXcosd(thetas);
Z=Z+deltX
sind(thetas);
VX=vpa(X,5)
VY=vpa(Z,5)
Su=kZ;Tp=fApNcpSu;Tw=Tp/cosd(thetaw);
syms z
Q=NcEndint(kz,z,0,Z)/Z;
thetaa=sqrtm(2ZQ/Tw)*180/pi;
thetas=thetaw-thetaa;
Vthetas=vpa(thetas,4)
end
figure
plot(VX,VY)
xlable('拖曳距离')
ylable('嵌入深度')

我想输出每一步的X、Z并制作成图像。结果算到下面这个数就慢的不行,几乎不动了。求专家帮满优化一下!
X =

 0

Z =

 1

thetas =

26

VX =

1.7976

VY =

1.8767

Vthetas =

21.35

VX =

3.6603

VY =

2.6048

Vthetas =

18.92

VX =

5.5523

VY =

3.2533

Vthetas =

17.03

VX =

7.4646

VY =

3.8389

Vthetas =

15.48

VX =

9.3921

VY =

4.3726

Vthetas =

14.16

VX =

11.331

VY =

4.862

Vthetas =

13.03

VX =

13.28

VY =

5.3129

Vthetas =

12.03

VX =

15.236

VY =

5.7298

Vthetas =

11.15

VX =

17.198

VY =

6.1165

Vthetas =

10.36

VX =

19.166

VY =

6.476

有一些*号他没显示

估计是内存资源一直在增加而没有及时释放不需要的内存

是不是循环速度太快,循环体和次数太多导致CPU卡慢

vpa设置一下精度,位数限制,不然默认精度高,算的慢

比如7位的精度就用

vpa(x,7)

cpu占用过多就跑不起来了,要是用服务器跑,你看它快不快