odepack.error:函数及其Jacobian必须是可调用函数

2024-09-27 17:45:53 发布

您现在位置:Python中文网/ 问答频道 /正文

在odepack.error:函数及其Jacobian必须是可调用函数。我怎么解决这个问题?在

#!/usr/bin/env python
from sympy import *
from scipy.integrate import odeint
from matplotlib import pyplot as plt 
from scipy import optimize as opt 
import numpy as np 

x = Symbol('x')

def f(x):
    y =  100*(1-x**2)**2+(1-x)**2
    return y

def steepestDescent(f,x0,x):
    #y = np.zeros(100)
    for i in range(100):
        y = odeint(f,x0,x)
        x0 = x0-0.1*y;
    return x0

if __name__ == '__main__':
    x = np.linspace(-8,8,100)
    plt.plot(x,f(x),x,steepestDescent(f(x),2,x))
    plt.show()

Tags: 函数fromimportreturndefasnpplt

热门问题