필터 지우기
필터 지우기

In what I missed

조회 수: 3 (최근 30일)
Saad Almalki
Saad Almalki 2020년 12월 7일
댓글: VBBV 2020년 12월 8일
function [ val, ea, iter] = IterMeth(x , es, maxit)
%%initialization
iter=12;
val = exp(1);
xr = [ ];
ea =100;
%iterative calculation
while (1)
xrold=xr;
xr= xr-x^iter/factorial(iter); <--------------------------here?
iter= iter+ 1;
if xr~=0
ea=abs((xr-xrold)/xr)*100;
end
if ea<=es || iter >= maxit,break,end
end
val=xr;
end
  댓글 수: 8
VBBV
VBBV 2020년 12월 8일
Ok. Is it same when there is keyword after comma ? In the e.g. you cited its a variable iter which changes values in the program
VBBV
VBBV 2020년 12월 8일
%if true
if ea<=es || iter >= maxit,break,end
Give a value to maxit variable before it enter the while loop

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 7일
편집: Walter Roberson 2020년 12월 7일
xr = [ ];
That is empty.
xrold=xr;
so that is empty.
xr= xr-x^iter/factorial(iter); %<--------------------------here?
empty minus anything would be empty.
You are passing in x, but if it is not a scalar, you need
xr = xr - x.^iter ./ factorial(iter);

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by