MATLAB: I’m trying to plot this for loop with the kappa values with respect to the increasing n but the plot that it shows is empty and the x axis is from 99 to 101 instead of 1 to 100 like the for loop dictates. Can anybody tell me what I’m doing wrong

for loopplotting

close all
for n=1:100
lammax = 4-2*cos(sqrt(n)*pi/(sqrt(n)+1));
lammin = 4-2*cos(pi/(sqrt(n)+1));
kappa = lammax/lammin;
end
plot(n, kappa, 'r--')
xlabel('n')
ylabel('Condition Number')

Best Answer

Try this slight variation on your code:
for n=1:100
lammax(n) = 4-2*cos(sqrt(n)*pi/(sqrt(n)+1));
lammin(n) = 4-2*cos(pi/(sqrt(n)+1));
kappa(n) = lammax(n)/lammin(n);
end
n=1:100;
plot(n, kappa, 'r--')
xlabel('n')
ylabel('Condition Number')
Related Question