Please, help! I get an NaN's cannot be converted to logicals. Error in Untitled (line 22) while tol_V2(i) && tol_V3(i) >= 0,00005; error. How can I fix it?
8 views (last 30 days)
Show older comments
clc;
clear all;
y12 = -40j;
y23 = -20j;
y13 = -20j;
i=1;
V1 = 1;
V2(i) = 1.05+0j;
V3(i) = 1+0j;
s3 = 5+4j;
p2 = 4.07;
tol_V2(i) = 1;
tol_V3(i) = 1;
while tol_V2(i) && tol_V3(i) >= 0,00005;
V3(i+1)= (V1*y13 + V2(i)*y23 - conj(s3)/conj(V3(i)))/(y13 + y23);
q2(i+1) = -imag(conj(V2(i))*((y12 + y13)*V2(i)- V3(i+1)* y23 - V1*y12));
s2(i+1) = p2 + 1j*q2(i+1);
V2(i+1) = (V3(i)*y23 + V1*y12 + conj(s2(i))/conj(V2(i)))/(y12 + y23);
e(i+1) = sqrt(real(V2(i + 1)^2 - imag(V2(i + 1))^2));
V2(i+1) = e(i+1)+ imag(V2(i + 1));
tol_V2(i+1) = abs(V2(i+1)-V2(i));
tol_V3(i+1) = abs(V3(i+1)-V3(i));
tol_V2(i) = tol_V2(i+1);
tol_V3(i) = tol_V3(i+1);
i = i+1;
end
0 Comments
Accepted Answer
Jan
on 15 May 2021
Edited: Jan
on 15 May 2021
Before the loop, tol_V2 is a scalar. Inside the first iteration you set tol_V2(i) and tol_V3(i) with i == 1. But after increasing i by 1, tol_V2(2) is not define. Solution:
tol_V2(i + 1) = abs(V2(i+1)-V2(i));
% ^^^
tol_V3(i + 1) = abs(V3(i+1)-V3(i));
% ^^^
3 Comments
Jan
on 16 May 2021
Yes, the values are growing fast until they reach Inf. You can checkthis by:
dbstop if naninf
More Answers (0)
See Also
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!