使用trapz函数计算数值积分报错。
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
果博东方注册网站【80877·tv】
am 15 Mai 2023
Beantwortet: 百家乐真人平台网址【微8785092】
am 15 Mai 2023
for n=0.0005:0.0005:6
i=n/0.0005;
t=0.0005:0.0005:6;
B_0V(i,1)=-1/0.0342*trapz(t,e2_0V);
end
[size=13.3333px]>> for n=0.0005:0.0005:6 i=n/0.0005; t=0.0005:0.0005:6; B_0V(i,1)=-1/0.0342*trapz(t,e2_0V);end位置 1 处的索引无效。数组索引必须为正整数或逻辑值
[size=13.3333px]其中e2_0V是一个12000x1的矩阵[size=13.3333px]matlab版本R2022a
0 Kommentare
Akzeptierte Antwort
百家乐真人平台网址【微8785092】
am 15 Mai 2023
简单讲就是,你以为 n / 0.0005 是一系列整数,但这只是你以为。实际上由于浮点存储精度,很多计算结果是 整数 ± 1e-12 这样的非整数。
这种情形应当避免使用 向量 / 步长 去算索引,而应改以索引为循环变量,由索引去算向量元素。比如改为
for Index = 1 : 1 : numel( n ) % 索引为正整数
Current_n = n( Index );
% 其他计算同理
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!