MATLAB: I have a problem with plotting a summation equation, Help me!

#plotting #summationequation

The question: For the fuction:
I tried as described below, but failed. I hope to help from you. Thanks.
k=6; %scalar, example
def f(k,x): return sum( sqrt((2*k-3)/((3+i)*(2*k-4-i))) for i in range(x+1))
plot(f(k,x) for x in range (2*k-8) )

Best Answer

Hi.
Editing - I had a (3-i) instead of (3+i) in the denominator - it's fixed now:
k = 6;
f = @(x)sum(sqrt((2*k-3)./((3 + [0:(x+1)]).*(2*k-4-[0:(x+1)]))));
x = 0:(2*k-8);
y = zeros(size(x));
for j = 1:length(x)
y(j) = f(x(j));
end
plot(x,y,':+');
hold on;
title(['f(k,x) where k = ' num2str(k)]);
ylabel('f(k,x)'); xlabel('x');
legend('location','southwest');
strangePlot.png