gpt4 book ai didi

matlab - 不知道如何纠正: “In an assignment A(I) = B, the number of elements in B and I must be the same.”

转载 作者:行者123 更新时间:2023-12-03 07:54:50 25 4
gpt4 key购买 nike

我看到了有关此错误的其他主题,但无法弄清楚。错误“在赋值A(I)= B中,B和I中的元素数必须相同”在第二个for循环中发生。如何更改代码以避免此错误?

h1 = [70 31.859 15 5.774 3.199 2.15 1.626];
h2 = [31.859 15 5.774 3.199 2.15 1.626 1.415];
b = [1253 1253 1253 1253 1253 1253 1253];
R = [455.4 425.6 377.6 374.9 371.3 273.7 268.3];
r = [0.5448714286 0.5291754292 0.6150666667 0.4459646692 0.3279149734 0.2437209302 0.1297662977];
k = [200 200 200 200 200 200 200];
s = sqrt(r/(1-r));
v2 = [20 0 0 0 0 0 0];
v1 = [0 0 0 0 0 0 0];
Ch1 = [0 0 0 0 0 0 0];
Ch2 = [0 0 0 0 0 0 0];
C = [100 100 100 100 100 100 100];

F = b .* k .* sqrt(R-(h1-h2))- R.*sin((acos((R-((h1-h2)./2))./R))) .* (pi/2) .* (1./sqrt(r./(1-r))) .* (atan(sqrt(r./(1-r))))-(pi/4) - (1./(sqrt(r./(1-r)) .* sqrt(h2./R))).* log((h2+R.*((sqrt(h1./R).*tan(1/2 .* atan(sqrt(r./(1-r)).*sqrt(h1./r).*log(1./(1-k))))).^2).*sqrt(1-r))./h2)


M = -R.*R.*(k./2).*(.2*(sqrt(h2./R)*tan(0.5*(atan(s)))-(pi/8).*sqrt(h2./R).*log(1./1-r)))-(acos((R-((h1-h2)./2))./R))


for i=1:6
v1(i) = ((v2(i)*h2)/h1);
v2(i+1) = v1(i);
end


vr = ((v1.*h1)./h2)./(((tan(0.5.*((atan(s)))-(pi/8).*sqrt(h2./R).*log(1./(1-r)))).^(2))+1)

%--------------------------------------------------------------------------

% Calculating E

w = (((2.*R.*h2).^(3/2))./(300.*(b.^2)))

if (w <= (3*10^-4));
E = ((0.0821.*((log(w))^2))+(1.25.*log(w))+4.89)
end

if ((3*10^-4)<= w <= (2.27*10^-3));
E = ((0.0172.*((log(w)).^2))+(0.175.*log(w))+0.438)
end

if (w > (2.27*10^-3))
E = 0.01
end

%--------------------------------------------------------------------------

% Calculating Ch:

y = ((((2.*R).^(0.5)).*((h2).^(1.5)))./(b.^2))

N1 = (0.5-(1/pi).*atan((log(y)+8.1938)./(1.1044)))

N = ((h2./h1).*N1)

for i=1:1;7
Ch2(i) = (h2.*((N.*((Ch1(i)./h2)-(C./h2)))+(C/h2)))
Ch1(i+1) = Ch2(i)
end

DeltaStrain = (E.*((Ch2./h2)-(Ch1./h1)))

if DeltaStrain > 0;
Stepp = ((2/pi).*(sqrt(DeltaStrain))))
Control = 2;
else
Stepp = ((2/pi).*(sqrt(-DeltaStrain))
Control = 0;
end

最佳答案

在行中

       Ch2(i) = (h2.*((N.*((Ch1(i)./h2)-(C./h2)))+(C/h2)))
h2是 vector ,而 Ch2(i)是标量。您不能将 vector 的值分配给标量。我怀疑您要替换整个 for循环。现在你有
for i=1:1;7
Ch2(i) = (h2.*((N.*((Ch1(i)./h2)-(C./h2)))+(C/h2)))
Ch1(i+1) = Ch2(i)
end

(?? 1:1;7的意思是什么?这是一个错字吗?我在想您想要 1:7 ...

由于您似乎正在使用一个循环的结果来更改要在下一循环中再次使用的Ch1的值,因此矢量化可能会比较棘手;但我想知道您期望的输出是什么,因为根据方程式的RHS确实确实有一个 vector 。我不确定是否要一次计算一个元素的结果,还是要计算 vector (最终将结果附加到 Ch1Ch2)。下一行将运行而不会引发错误-但这可能不是您想要的计算。如果这是一个错误的猜测,请说明您希望达到的目标。
for i = 1:7
Ch2(i) = h2.*(N.*((Ch1(i) - C(i))./h2(i))) + C(i)./h2(i);
Ch1(i+1) = Ch2(i);
end

关于matlab - 不知道如何纠正: “In an assignment A(I) = B, the number of elements in B and I must be the same.” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20690753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com