1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import matplotlib.pyplot as plt
from numpy import *
 
 
def insert_str(string, str_to_insert, index):
    return string[:index] + str_to_insert + string[index:]
 
 
def is_numchar(c):
    if c == ".":
        return True
    return c.isdigit()
 
 
def format_fx(fx):
    fx = fx.replace("^", "**")
 
    xi = False
    _fx = fx
    correction = 0
    for i, c in enumerate(_fx):
        try:
            if c == ")" and (_fx[i + 1].isalpha() or _fx[i + 1] == "("):
                fx = insert_str(fx, "*", (i + 1) + correction)
                correction += 1
        except IndexError:
            pass
 
        if is_numchar(c) or (c == "x" and not xi):
            xi = True
        elif xi:
            if c != "x":
                xi = False
            if c.isalpha() or c == "(":
                fx = insert_str(fx, "*", i + correction)
                correction += 1
 
    return fx
 
 
fx = format_fx(input("y= "))
print(fx)
x = linspace(-10, 10, 100)
y = eval(fx)
 
plt.plot(x, y)
 
cs


식을 변환해주는 과정이 뒤지게 어렵네요 머리터질거같음


1
2
y= 2xlog((x+1)^2(x+2)/(x+3)sin(x^2))tan(2^x+1)
2*x*log((x+1)**2*(x+2)/(x+3)*sin(x**2))*tan(2**x+1)
cs

식을 입력하면 이런식으로 변환이 됩니다


1
2
y= log(x)/2^xx
log(x)/2**x*x
cs

이런것도 잘 됨


테스트를 많이 해본게 아니라서 아직 발견못한 예외가 엄청날듯 ㅋㅋ

자스충이었는데 파이썬에만 있는 툴들이 많아서 재밌다