Skip to content Skip to sidebar Skip to footer

Solve Highly Non-linear Equation For X In Python

I am trying to solve the following equation for dB (for simplicity, I stated dB as x in the question title): All of the other terms in the equation are known. I tried using SymPy

Solution 1:

Here are the four single-dim root-methods:

from scipy.optimize import brentq, brenth, ridder, bisect
for rootMth in [brentq, brenth, ridder, bisect]:
    dbub = rootMth(dB, 0.01, dbed)
    print 'dbub = ', dbub, '; sanity check (is it a root?):', dB(dbub)

Also the newton-raphson (secant / haley) method:

from scipy.optimize import newton
dbub = newton(dB, dbed)
print'dbub = ', dbub, '; sanity check (is it a root?):', dB(dbub)

The scipy documentation recommends brentq if you have a bracketing interval.

Solution 2:

To solve what's in your title is easy:

In [9]:

import numpy as np

import scipy.optimize as so

In [10]:

def f(x):

    return ((x-0.32)**0.8+(x+1.45)**1.1-np.exp(0.8))**2In [11]:

so.fmin(f, x0=5)

Optimization terminated successfully.
         Currentfunctionvalue: 0.000000
         Iterations: 20Function evaluations: 40Out[11]:

array([ 0.45172119])

In [12]:

f(0.45172119)

Out[12]:

4.7663411535618792e-13

All the other parameters are fixed?

Post a Comment for "Solve Highly Non-linear Equation For X In Python"