Plotting a sum with a variable

25 visualizaciones (últimos 30 días)
Dimitri
Dimitri el 3 de Mayo de 2014
Editada: Dimitri el 3 de Mayo de 2014
Hi everyone. I would like to plot something of the form:
sum( (factorial(k) / (factorial(i)*factorial(k-i)), i=1..k)
for different values of k, say, for k=1,2,..,10 in a single graph.
Does anyone know the syntax how to do that? I greatly appreciate your answers! Thanks! D

Respuesta aceptada

Jos (10584)
Jos (10584) el 3 de Mayo de 2014
Creat a function and use arrayfun:
fh = @(k) sum(factorial(k) ./ factorial(1:k) .* factorial(k-(1:k))) % function handle
x = 1:5
y = arrayfun(fh, x) % apply function to a list of values
plot(x, y ,'bo-')

Más respuestas (1)

Dimitri
Dimitri el 3 de Mayo de 2014
Editada: Dimitri el 3 de Mayo de 2014
Thank Jos, everything makes sense now!

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by