使用trapz函数计算数值积分报错。
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
果博东方注册网站【80877·tv】
il 15 Mag 2023
Risposto: 百家乐真人平台网址【微8785092】
il 15 Mag 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 Commenti
Risposta accettata
百家乐真人平台网址【微8785092】
il 15 Mag 2023
简单讲就是,你以为 n / 0.0005 是一系列整数,但这只是你以为。实际上由于浮点存储精度,很多计算结果是 整数 ± 1e-12 这样的非整数。
这种情形应当避免使用 向量 / 步长 去算索引,而应改以索引为循环变量,由索引去算向量元素。比如改为
for Index = 1 : 1 : numel( n ) % 索引为正整数
Current_n = n( Index );
% 其他计算同理
end
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!