Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Newton-iteroinnilla funktion sin(x) = 0 nollakohta Pi
- # Juhani Kaukoranta 17.3.2022
- tarkkuus10=101 # desimaaliluvun tarkkuus
- precision = floor(Int,tarkkuus10*log2(10))+1 # bittitarkkuus
- setprecision(BigFloat,precision)
- epsilon = 1/big(10)^tarkkuus10 # vastauksen tarkkuus
- h = 1/big(10)^(tarkkuus10-2)
- function Newton(x0)
- f(x) = sin(big(x)) # funktio, jonka nollakohta etsitään
- xold = big(x0) # alkuarvo
- while true
- fold = f(xold)
- xnew = xold - h*fold/(f(xold+h)-fold) # x(n+1) = x(n)- f(x(n))/f'(x(n))
- if abs(xnew - xold) < epsilon
- return xnew
- end
- xold = xnew
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement