자연로그에 사용되는 오일러 수 e를 게산하기 위한 프로그램을 아래의 전개식을 참고하시오.
e=1+1/1!+ 1/2! + 1/3! +....+1/(n-1)1 + 1/n!
단, 위의 전개식에서 연속된 두 개항 사이의 차이가 10^(-300)보다 작은 경우 반복을 종료 할때의 e값과, 몇번의 반복을 수행해 해당 값을 구했는지 출력하시오.
NM=sum(1./factorial(a));
Epoint=(1/factorial(t))-(factorial(t+1));
cod=0;
t=0;
n=1;
while (cod==1)
n=n+1;
t=t+1;
if Epoint >= (10^(-300))
a=0:t;
fprintf('when repeat %d, e is %d' ,n, NM )
cod=cod+1;
end
end
이렇게 했는데 error: 'a' undefined near line 1 column 22
error: called from
edmlrkqt at line 1 column 4
error: evaluating argument list element number 1
error: called from
edmlrkqt at line 1 column 4
error: evaluating argument list element number 1
error: called from
edmlrkqt at line 1 column 4
>>
란 오류가 뜨네요 아무리 봐도 도저히 모르겠는데 도와주실 수 있으신지....
a를 너는 동적으로 선언하자나
1/n 이 n이 몇일때 10^-300인지만 찾고 그때 n값이 반복수행값이고 for문으로 더해서 e값출력하는게 나을듯
아긔발//몇일->며칠 [리듬 맞춤법 봇♬]