Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to convert the following program to vector operation (not using for loop)
2 ビュー (過去 30 日間)
古いコメントを表示
function y= natural_log(x,n)
if (abs(x)>=1)||(n<=0)
disp ('Error')
else if ((abs(x)<1)&&(n>0))
y=x;
q=1;
for a=2:n
q=q*(-1);
y=y+q*((1/a)*(x^a));
end
end
end
0 件のコメント
回答 (1 件)
Roger Stafford
2014 年 11 月 18 日
elseif
y = sum(-(-x).^(1:n)./(1:n);
...
You should be aware that this series sum will approach log(1+x), not log(x). Also be aware that the original for-loop might be faster than the vectorized form for large n.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!