简体   繁体   中英

how to use broyden1 algorithm to calculate an exponential value

I have to find the temperature in the equation:

u = 1.2*e^(-.025*T)
u = viscosity in N*s/m^2

T = degree C

using

scipy.optimize.broyden1()

how would you use that to find the T when u=.001?

To use the broyden1 function, just give it the function that you want the root to be found and also an initial value. If you are only interested in solving for u=.001, you can just define a function that take T as an input. If you might want to change the value of u, partial might be a handy tool.

import scipy.optimize
import numpy as np
from functools import partial

def findtemp(T, u):
    return u - 1.2 * np.exp(-.025*T)

sol = scipy.optimize.broyden1(partial(findtemp, u=.001), 0)
print(sol)

gives me a value of 283.4828690696808 which is close to the theoretical value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM