??? Subscript indices must either be real positive integers or logicals.
    3 ビュー (過去 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!




