All about

이 글은 제가 공부한 내용을 정리하는 글입니다. 잘못된 내용이 있을 수 있으며, 잘못된 내용을 찾으셨다면 리플로 알려주시길 부탁드립니다. 감사합니다.




Numerical Optimization, 즉 수치최적화를 공부하고 그 내용을 정리하고자 합니다.



Secant method 가 잘 설명되어 있는 영상입니다. 알고리즘 자체의 방법론과 Rate of convergence 에 대한 설명은 영상에 충분히 시각화되어 추가적인 설명이 필요 없다고 생각됩니다.


여기선 Secant method 의 장점과 단점을 생각해보려합니다.


장점


1. 미분이 필요 없습니다. 따라서 미분이 불가능한 함수에 적용할 수 있습니다.

2. Rate of convergence 가 더 높기 때문에 Bisection 에 비해 일반적으로 더 빠르게 해를 찾습니다.


단점



1. 영상에 나와 있듯이 탐색된 두 지점의 접선이 x 축과 평행하다면 더 이상의 탐색이 불가능하게 됩니다.



코드 구현


핑계일 뿐이지만, 제대로된 코딩 수업을 들어본 적이 없기 때문에 코드가 개똥 같을 수 있습니다.


import numpy as np
import math

def myEquation1(x):
return -1 * (x**3)

def secant(a, b, iteration, my_func):
# secant 가 가장 general 한 case 에 적용 가능
if my_func(b) < 0.0000001 and my_func(b) > (-1 * 0.0000001):
print("case close")
print("iteration:", str(iteration).ljust(3), "x: ", str(b).ljust(23), "f(x): ", str(my_func(b)).ljust(23))
elif my_func(a) < 0.0000001 and my_func(a) > (-1 * 0.0000001):
print("case close")
print("iteration: ", str(iteration).ljust(3), "x: ", str(a).ljust(23), "f(x): ", str(my_func(a)).ljust(23))
else:
iteration = iteration + 1
c = b - ((b - a)/(my_func(b) - my_func(a))) * my_func(b)
print("iteration:", str(iteration).ljust(3), "a: ", str(a).ljust(23), "b: ", str(b).ljust(23), "c: ", str(c).ljust(23), my_func(c))
secant(b, c, iteration, my_func)

secant(-100, 50, 0, myEquation1)


secant method 설명 secant method 뜻 secant method 구현 secant method 코드

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading