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

1 vue (au cours des 30 derniers jours)
DIEGO PACHECO
DIEGO PACHECO le 11 Jan 2020
Commenté : DIEGO PACHECO le 14 Jan 2020
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) )

Réponse acceptée

Meg Noah
Meg Noah le 11 Jan 2020
Modifié(e) : Meg Noah le 12 Jan 2020
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
  1 commentaire
DIEGO PACHECO
DIEGO PACHECO le 14 Jan 2020
Hi!! Your answer is perfect !! Thanks so much for the help!

Connectez-vous pour commenter.

Plus de réponses (1)

David Hill
David Hill le 11 Jan 2020
k=6;
f=zeros(1,2*k-7)
for i=0:2*k-8
f(i+1)=sqrt((2*k-3)/((3+i)*(2*k-4-i)));
end
f=cumsum(f);
f=f(1:2:end);%x=0,2,4
plot(f);

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by