Created
March 14, 2016 06:05
-
-
Save Dascr32/9e97aef550ab4e8ca844 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#================================================== | |
# 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