kangwonlee / kangwonlee/nmisp

10 / 10 visualize how sequential finds the root

Open
#207 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Jupyter Notebook
Stars
12
Forks
76
PR merge metrics
No merged PRs in 30d

Description

* 0510154
* `pdb` ?
``` python
import pdb

def sequential(f, x_init, x_interval, epsilon, x_final, b_print_counter=True, b_debug=False):
if b_debug:
pdb.set_trace()

# result 의 초기값
# Initial value for sqrt_10
result = 'Not Found'

# 일련의 x_i 값을 미리 준비한다
# Prepare a series of x_i values in advance
x_array = py.arange(x_init, x_final+x_interval*0.5, x_interval)

# 몇번 반복했는지 측정하는 변수를 선언
# Declare a variable to count the number of iterations
counter = 0

# x_i 에 관한 반복문
# x_i loop
for x_i in x_array:
# x = x_i 에서의 함수 f(x)값을 계산하여 y_i에 저장
# Evaluate the function f(x) at x = x_i and store in y_i
y_i = f(x_i)

# counter 변수 1 증가
# Increase the counter by one
counter += 1

# y_i 의 절대값이 epsilon 보다 작은지 확인
# Check if absolute value is smaller than epsilon
if abs(y_i) < epsilon:
# y_i의 절대값이 epsilon 보다 작다면 근을 찾은 것임
# if the absolute value of y_i is smaller than epsilon
# we found the root
result = x_i

# 근을 찾았으므로 for 반복문을 중단함
# As we found a root, break out of the for loop
break

# 반복 횟수
# Number of iterations
if b_print_counter:
print('counter =', counter)

# f(x)의 절대값을 epsilon 보다 작게 만드는 결과값을 반환
# return the result that would make
# the absolute value of f(x) smaller than epsilon
return result
```
``` python
sequential(x_sq_minus_ten, 3.1621, x_interval, epsilon, x_final, b_debug=True)
```

* set break point at 28 `counter += 1`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.