??? Subscript indices must either be real positive integers or logicals.
조회 수: 2 (최근 30일)
이전 댓글 표시
Here's my code:
N = 10;n=0:N;
f(n) = cumsum(((-1).^n)/(3.^n));
g(n) = 3/4+1/4*(-1/3).^n;
I am new to Matlab. Please send a complete solution. Thank you.
댓글 수: 2
Star Strider
2012년 10월 10일
I will not send a complete solution, but I will point out that MATLAB interprets your f(n) and g(n) statements as array references, not functions. To create functions, see the documentation on Anonymous Functions.
Matt Fig
2012년 10월 10일
How could we send a complete solution when we don't even have a complete question?
Please learn to format your code. Highlight the code, then push the button that looks like {}Code.
답변 (2개)
Muruganandham Subramanian
2012년 10월 10일
Hi, I matalab, you cannot find f(0). so you should start with n=1:N and check the below coding, it may help you..
N = 10;
for n=1:N;
f(n) = cumsum(((-1).^n)/(3.^n));
g(n) = 3/4+1/4*(-1/3).^n;
end
댓글 수: 0
Andrei Bobrov
2012년 10월 10일
f1 = @(n)cumsum((-1).^n./3.^n);
g1 = @(n)3/4+1/4*(-1/3).^n;
>> N = 10;
>> n1 = 0:N;
>> f1(n1)
ans =
1 0.66667 0.77778 0.74074 0.75309 0.74897 0.75034 0.74989 0.75004 0.74999 0.75
0:N
ans =
1 0.66667 0.77778 0.74074 0.75309 0.74897 0.75034 0.74989 0.75004 0.74999 0.75
or
f2 = @(N)cumsum((-1).^(0:N)./3.^(0:N));
g2 = @(N)3/4+1/4*(-1/3).^(0:N);
>> f2(10)
ans =
1 0.66667 0.77778 0.74074 0.75309 0.74897 0.75034 0.74989 0.75004 0.74999 0.75
>> g2(10)
ans =
1 0.66667 0.77778 0.74074 0.75309 0.74897 0.75034 0.74989 0.75004 0.74999 0.75
댓글 수: 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!