フィルターのクリア

how to use sum?

3 ビュー (過去 30 日間)
George
George 2013 年 2 月 18 日
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
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
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 件のコメント
George
George 2013 年 2 月 18 日
Ok!It wanted clear all!Maybe it messed up with something!!And I was going crazy!
Jan
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 ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by