필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by