Symbolic summation within a for-loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Robert Mason
el 22 de Jul. de 2016
Respondida: Azzi Abdelmalek
el 22 de Jul. de 2016
I have a function that is dependent on two variables, f(j, k). I would like to create a loop that, for each j, sums the function for each value of k. I have tried the code:
for j=1:10;
g(j)=symsum(f(j,k), k, 1, 10);
end;
However, I get an error message "Undefined function 'symsum' for input arguments of type 'double'." on running the code. What is the best way to do the above in MATLAB?
Respuesta aceptada
Walter Roberson
el 22 de Jul. de 2016
symsum cannot use the summation variable to index.
If f is not vectorized then you use
sum( arrayfun(@(k) f(j, k), 1:10) )
If f is vectorized you might be able to use
sum( f(j, 1:10) )
but you might need
sum( f(repmat(j,1,10), 1:10) )
depending on how f is coded.
0 comentarios
Más respuestas (1)
Azzi Abdelmalek
el 22 de Jul. de 2016
Look at this example
syms f j k
f=j*sin(k)
for jj=1:10;
ff(k)=subs(f,j,jj);
s=symsum(ff(k), k, 1, 10);
g(jj)=double(s)
end;
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!