how to use sum?
1 次查看(过去 30 天)
显示 更早的评论
I am trying to use sum but with no success!
For example:
n=1:20;
sum(n./2.^n)
or:
n=20;
k=1:n;
sum(k);
but neither works!Am I missing sth here?
Thanks!
1 个评论
Jan
2013-2-18
"Neither works" is not a good description of the problem. Better post the error message of explain the difference between the results and your expectations.
采纳的回答
Azzi Abdelmalek
2013-2-18
编辑:Azzi Abdelmalek
2013-2-18
%They both work fine
%What is your error message?
%Try
clear sum
n=1:20;
sum(n./2.^n)
Mybe sum is used as a variable in your code
2 个评论
Jan
2013-2-18
No, Georg, not clear all, but clear sum. See Answers: avoid clear all. But instead of clearing variables, it is much better to avoid using the names of built-in functions as names of variables.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!