zoukankan      html  css  js  c++  java
  • python scipy 求解简单线性方程组和fmin求函数最小值

    ###这是一个利用内置函数求最小值#####
    def
    func(x): return x ** 2 - 2 *x x = 1 func(x) opt.fmin(func ,x)

    ## 用scipy求解线性方程组
    from scipy.optimize import fsolve from math import sin, cos def f(x): x0 = float(x[0]) x1 = float(x[1]) x2 = float(x[2]) return [5 * x1 + 3, 4 * x0 * x0-2 * sin(x1 * x2), x1 * x2 -1.5] def J(x): x0 = float(x[0]) x1 = float(x[1]) x2 = float(x[2]) return[[0, 5, 0], [8 * x0, -2*x2*cos(x1*x2),-2*x1*cos(x1*x2)], [0, x2,x1]] result = fsolve(f, [1,1,1],fprime = J) print result print f(result)
  • 相关阅读:
    枚举
    枚举
    比特币中的密码学原理
    贪心
    dp
    二分
    mac解决matplotlib中文乱码
    Keras使用多个GPU并行
    pyspark使用-dataframe操作
    箱线图
  • 原文地址:https://www.cnblogs.com/Kermit-Li/p/6808080.html
Copyright © 2011-2022 走看看