Skip to content

Instantly share code, notes, and snippets.

@Dascr32
Created March 14, 2016 06:05
Show Gist options
  • Save Dascr32/9e97aef550ab4e8ca844 to your computer and use it in GitHub Desktop.
Save Dascr32/9e97aef550ab4e8ca844 to your computer and use it in GitHub Desktop.
#==================================================
# Nth root approximation algorithm.
# Universidad de Costa Rica.
# Tarea # 1.
# Daniel Aguilar S (B40129).
#--------------------------------------------------
# USAGE
#
# Use "source("<script_path>/calcroot.m")" in order
# to use all the functions in this script.
#
#==================================================
1;
function approx = calcroot (startingPoint, degree, radicand)
range = 0 : 19;
if (startingPoint == "null" || startingPoint == 0)
approx = radicand / degree;
else
approx = startingPoint;
endif
for x = range
approx = ( ((degree - 1) / degree) * approx) + (radicand / (degree * (approx ^ (degree - 1)) ));
endfor
endfunction
function retval = relerror (current, previus)
retval = abs((current - previus) / current);
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment