Advertisement
mixster

Untitled

Dec 8th, 2011
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.43 KB | None | 0 0
  1. function[answer] = pow(x,n)
  2. global SAVED
  3.  
  4. if(n==0)
  5.     answer =1;
  6.  
  7. elseif (isnan(SAVED(1,n))==0)
  8.     answer=SAVED(1,n);
  9.    
  10. elseif (n<0)
  11.     answer ='Faster is not defined for negative n values';
  12.  
  13.    
  14. elseif ((2*floor(n/2))==n);
  15.         answer =pow(x,(floor(n/2)))*pow(x,(floor(n/2)));
  16.         SAVED(1,n) = answer;
  17.  
  18. else
  19.     answer =x*(pow(x,floor(n/2))*pow(x,(floor(n/2))));
  20.     SAVED(1,n) = answer;
  21. end
  22.  
  23. end
  24.  
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement