Index exceeds matrix dimensions using for and while loop
Mostra commenti meno recenti
clc
clear
close
%define variables
Re = [2500:1:500000];
n = numel (Re);
t(1)= 0;
e = 1;
f = 1;
for i = 1:n
g(i+1) = 4*log10(Re(i)*sqrt(f))-0.4-(1/sqrt(f));
while e > 0.000005
i = i+1;
t(i+1) = f(i) + (4*log10(Re*sqrt(f(i)))-0.4-(1/sqrt(f(i))))/((2/(f(i)*log(10)))+(1/(2*f(i)^(2/3))))
e = abs(t(i+1) - t(i))
end
end
It gives index exceeds matrix dimensions error. I checked each raw of code, but I cannot see it
Risposte (1)
Anirudh Vajpeyi
il 30 Apr 2022
0 voti
while e > 0.000005
i = i+1;
t(i+1) = f(i) + (4*log10(Re*sqrt(f(i)))-0.4-(1/sqrt(f(i))))/((2/(f(i)*log(10)))+(1/(2*f(i)^(2/3))))
e = abs(t(i+1) - t(i))
end
This loop is basically an infinite loop and also 'f' has just one value. So, not sure what exactly do you want to achieve.
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!