In what I missed
    1 view (last 30 days)
  
       Show older comments
    
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
Answers (1)
  Walter Roberson
      
      
 on 7 Dec 2020
        
      Edited: Walter Roberson
      
      
 on 7 Dec 2020
  
      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); 
0 Comments
See Also
Categories
				Find more on Software Development Tools in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


