Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function[answer] = pow(x,n)
- global SAVED
- if(n==0)
- answer =1;
- elseif (isnan(SAVED(1,n))==0)
- answer=SAVED(1,n);
- elseif (n<0)
- answer ='Faster is not defined for negative n values';
- elseif ((2*floor(n/2))==n);
- answer =pow(x,(floor(n/2)))*pow(x,(floor(n/2)));
- SAVED(1,n) = answer;
- else
- answer =x*(pow(x,floor(n/2))*pow(x,(floor(n/2))));
- SAVED(1,n) = answer;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement