필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to convert the following program to vector operation (not using for loop)

조회 수: 2 (최근 30일)
TY
TY 2014년 11월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

Roger Stafford
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.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by