Python sympy.ln函数代码示例 您所在的位置:网站首页 lnx怎么输入 Python sympy.ln函数代码示例

Python sympy.ln函数代码示例

2024-03-30 14:59| 来源: 网络整理| 查看: 265

本文整理汇总了Python中sympy.ln函数的典型用法代码示例。如果您正苦于以下问题:Python ln函数的具体用法?Python ln怎么用?Python ln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_1 def test_add_1(): assert Order(x + x) == Order(x) assert Order(3 * x - 2 * x ** 2) == Order(x) assert Order(1 + x) == Order(1, x) assert Order(1 + 1 / x) == Order(1 / x) assert Order(ln(x) + 1 / ln(x)) == Order(ln(x)) assert Order(exp(1 / x) + x) == Order(exp(1 / x)) assert Order(exp(1 / x) + 1 / x ** 20) == Order(exp(1 / x))开发者ID:smichr,项目名称:sympy,代码行数:8,代码来源:test_order.py 示例2: test_ansi_math1_codegen def test_ansi_math1_codegen(): # not included: log10 from sympy import acos, asin, atan, ceiling, cos, cosh, floor, log, ln, \ sin, sinh, sqrt, tan, tanh, N x = symbols('x') name_expr = [ ("test_fabs", abs(x)), ("test_acos", acos(x)), ("test_asin", asin(x)), ("test_atan", atan(x)), ("test_ceil", ceiling(x)), ("test_cos", cos(x)), ("test_cosh", cosh(x)), ("test_floor", floor(x)), ("test_log", log(x)), ("test_ln", ln(x)), ("test_sin", sin(x)), ("test_sinh", sinh(x)), ("test_sqrt", sqrt(x)), ("test_tan", tan(x)), ("test_tanh", tanh(x)), ] numerical_tests = [] for name, expr in name_expr: for xval in 0.2, 0.5, 0.8: expected = N(expr.subs(x, xval)) numerical_tests.append((name, (xval,), expected, 1e-14)) run_cc_test("ansi_math1", name_expr, numerical_tests)开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:28,代码来源:test_codegen_c_cc.py 示例3: test_intrinsic_math1_codegen def test_intrinsic_math1_codegen(): # not included: log10 from sympy import acos, asin, atan, ceiling, cos, cosh, floor, log, ln, \ sin, sinh, sqrt, tan, tanh, N x = symbols('x') name_expr = [ ("test_fabs", abs(x)), ("test_acos", acos(x)), ("test_asin", asin(x)), ("test_atan", atan(x)), ("test_cos", cos(x)), ("test_cosh", cosh(x)), ("test_log", log(x)), ("test_ln", ln(x)), ("test_sin", sin(x)), ("test_sinh", sinh(x)), ("test_sqrt", sqrt(x)), ("test_tan", tan(x)), ("test_tanh", tanh(x)), ] numerical_tests = [] for name, expr in name_expr: for xval in 0.2, 0.5, 0.8: expected = N(expr.subs(x, xval)) numerical_tests.append((name, (xval,), expected, 1e-14)) for lang, commands in valid_lang_commands: if lang == "C": name_expr_C = [("test_floor", floor(x)), ("test_ceil", ceiling(x))] else: name_expr_C = [] run_test("intrinsic_math1", name_expr + name_expr_C, numerical_tests, lang, commands)开发者ID:Aang,项目名称:sympy,代码行数:31,代码来源:test_codegen.py 示例4: eta_fil def eta_fil(self, x, V_app, apprx=(0, 0, 0, 0)): m_eff = self.m_r * const.electron_mass mpmath.mp.dps = 20 x0 = Symbol('x0') # eta_fil x1 = Symbol('x1') # eta_ac x2 = Symbol('x2') # eta_hop x3 = Symbol('x3') # V_tunnel f0 = const.Boltzmann * self.T / (1 - self.alpha) / const.elementary_charge / self.z * \ ln(self.A_fil/self.A_ac*(exp(- self.alpha * const.elementary_charge * self.z / const.Boltzmann / self.T * x0) - 1) + 1) - x1# eta_ac = f(eta_fil) x1 = f(x0) f1 = x*2*const.Boltzmann*self.T/self.a/self.z/const.elementary_charge*\ asinh(self.j_0et/self.j_0hop*(exp(- self.alpha * const.elementary_charge * self.z / const.Boltzmann / self.T * x0) - 1)) - x2# eta_hop = f(eta_fil) f2 = x1 - x0 + x2 - x3 f3 = -V_app + ((self.C * 3 * sqrt(2 * m_eff * ((4+x3/2)*const.elementary_charge)) / 2 / x * (const.elementary_charge / const.Planck)**2 * \ exp(- 4 * const.pi * x / const.Planck * sqrt(2 * m_eff * ((4+x3/2)*const.elementary_charge))) * self.A_fil*x3) + (self.j_0et*self.A_fil*(exp(-self.alpha*const.elementary_charge*self.z*x0/const.Boltzmann/self.T) - 1))) * (self.R_el + self.R_S + self.rho_fil*(self.L - x) / self.A_fil) \ + x3 eta_fil, eta_ac, eta_hop, V_tunnel = nsolve((f0, f1, f2, f3), [x0, x1, x2, x3], apprx) eta_fil = np.real(np.complex128(eta_fil)) eta_ac = np.real(np.complex128(eta_ac)) eta_hop = np.real(np.complex128(eta_hop)) V_tunnel = np.real(np.complex128(V_tunnel)) current = ((self.C * 3 * sqrt(2 * m_eff * ((4+V_tunnel)*const.elementary_charge)) / 2 / x * (const.elementary_charge / const.Planck)**2 * \ exp(- 4 * const.pi * x / const.Planck * sqrt(2 * m_eff * ((4+V_tunnel)*const.elementary_charge))) * self.A_fil*V_tunnel) + (self.j_0et*self.A_fil*(exp(-self.alpha*const.elementary_charge*self.z*eta_fil/const.Boltzmann/self.T) - 1))) print(eta_fil, eta_ac, eta_hop, V_tunnel) # print(eta_ac - eta_fil + eta_hop - V_tunnel) return eta_fil, eta_ac, eta_hop, V_tunnel, current开发者ID:KrepakVitaly,项目名称:nanotech,代码行数:31,代码来源:main.py 示例5: test_solve_relation_for_derivatives def test_solve_relation_for_derivatives(): from sympy import symbols, Function, ln x, y = symbols("x, y") f = symbols("f", cls=Function)(x, y) relation = ln(x * y + f) - f subsd = {x: 2, y: 1} diff_wrt = {x: 2, y: 1} df, df_err = solve_relation_for_derivatives( relation, {x: 2, y: 1}, f, {((x, 0), (y, 0)): 1.0}, diff_wrt, verbose=True, abstol=1e-8 ) assert abs(df[((x, 1), (y, 0))] - 0.46594127238) < 1e-8 assert abs(df[((x, 0), (y, 1))] - 0.9318825447699826) < 1e-8 assert abs(df[((x, 1), (y, 1))] + 0.17057414955751987) < 1e-8 assert abs(df[((x, 2), (y, 1))] - 0.37120710736327495) < 1e-8 x, y = symbols("x, y") # x_arg, y_arg = symbols('x_arg, y_arg') g = symbols("g", cls=Function)(x, y) # (x_arg, y_arg) relation = x ** 2 + y ** 2 - g # Circle subsd = {x: 1.0, y: 0.0} initial_guess_func_vals = {((x, 0),): 0.5} diff_wrt = {x: 1} dg, dg_err = solve_relation_for_derivatives( relation, subsd, g, initial_guess_func_vals, diff_wrt, verbose=True, abstol=1e-7 ) assert abs(dg[((x, 1),)] - 2.0) < 1e-7开发者ID:bjodah,项目名称:mdiosvcor,代码行数:27,代码来源:root_finding.py 示例6: test_general_symbolic def test_general_symbolic(self): a, b, c, d, e, x = syp.symbols('a,b,c,d,e,x') # natural log function y = a*syp.ln(b*x**c + d)+e phys = self.phys phys['pore.item1'] = 0.16e-14 phys['pore.item2'] = 4 phys['pore.item3'] = 1.4 phys['pore.item4'] = 0.133 phys['pore.item5'] = -5.1e-14 phys.add_model(propname='pore.source1', model=pm.generic_source_term.natural_logarithm, A1='pore.item1', A2='pore.item2', A3='pore.item3', A4='pore.item4', A5='pore.item5', X='pore.mole_fraction', regen_mode='normal') arg_map=collections.OrderedDict([('a', 'pore.item1'), ('b', 'pore.item2'), ('c', 'pore.item3'), ('d', 'pore.item4'), ('e', 'pore.item5'), ('x', 'pore.mole_fraction')]) phys.add_model(propname='pore.general', model=op.models.physics.generic_source_term.general_symbolic, eqn=y, arg_map=arg_map, regen_mode='normal') assert np.allclose(phys['pore.source1.rate'], phys['pore.general.rate']) assert np.allclose(phys['pore.source1.S1'], phys['pore.general.S1']) assert np.allclose(phys['pore.source1.S2'], phys['pore.general.S2'])开发者ID:PMEAL,项目名称:OpenPNM,代码行数:32,代码来源:GenericSourceTermTest.py 示例7: euro_call_exact def euro_call_exact(S, K, T, r, sigma): # S: spot price # K: strike price # T: time to maturity # r: interest rate # sigma: volatility of underlying asset N = systats.Normal(0.0, 1.0) d1 = (sy.ln(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) d2 = (sy.ln(S / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) call = S * N.cdf(d1) - K * sy.exp(-r * T) * N.cdf(d2) return call开发者ID:aschleg,项目名称:Finance_with_Python,代码行数:16,代码来源:black_scholes_exact.py 示例8: exact_put_option_price def exact_put_option_price(S, K, T, r, sigma): #S: spot price #K: strike price #T: time to maturity #r: interest rate #sigma: volatility of underlying asset N = systats.Normal(0.0, 1.0) d1 = (sy.ln(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) d2 = (sy.ln(S / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) put_price = K * sy.exp(-r * T) * N.cdf(-d2) - S * N.cdf(-d1) return put_price开发者ID:aschleg,项目名称:Finance_with_Python,代码行数:16,代码来源:put_call_exact.py 示例9: exact_euro_put_div def exact_euro_put_div(S, K, T, r, q, sigma): # S: spot price # K: strike price # T: time to maturity # r: interest rate # q: rate of continuous dividend paying asset # sigma: volatility of underlying asset N = systats.Normal(0.0, 1.0) d1 = (sy.ln(S / K) + (r - q + 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) d2 = (sy.ln(S / K) + (r - q - 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) put = K * sy.exp(-r * T) * N.cdf(-d2) - S * sy.exp(-q * T) * N.cdf(-d1) return put开发者ID:aschleg,项目名称:Finance_with_Python,代码行数:17,代码来源:black_scholes_exact.py 示例10: getJeffreysPrior def getJeffreysPrior(rv): """ Uses SymPy to determine the Jeffreys prior of a random variable analytically. Args: rv: SymPy RandomSymbol, corresponding to a probability distribution Returns: list: List containing Jeffreys prior in symbolic form and corresponding lambda function Example: rate = Symbol('rate', positive=True) rv = stats.Exponential('exponential', rate) print getJeffreysPrior(rv) >>> (1/rate, ) """ # get support of random variable support = rv._sorted_args[0].distribution.set # get list of free parameters parameters = list(rv._sorted_args[0].distribution.free_symbols) x = abc.x # symbolic probability density function symPDF = density(rv)(x) # compute Fisher information matrix dim = len(parameters) G = Matrix.zeros(dim, dim) func = summation if support.is_iterable else integrate for i in range(0, dim): for j in range(0, dim): G[i, j] = func(simplify(symPDF * diff(ln(symPDF), parameters[i]) * diff(ln(symPDF), parameters[j])), (x, support.inf, support.sup)) # symbolic Jeffreys prior symJeff = simplify(sqrt(G.det())) # return symbolic Jeffreys prior and corresponding lambda function return symJeff, lambdify(parameters, symJeff, 'numpy')开发者ID:christophmark,项目名称:bayesloop,代码行数:45,代码来源:jeffreys.py 示例11: get_functions def get_functions(var): # Denne generator laver alle spørgsmålene. yield exp(a*var) yield ln(a*var) yield a*(var**4) yield a/(var**4) yield sqrt(1+(var**4)) yield (1+var)**a yield exp(a*var**2)开发者ID:sci2u,项目名称:api,代码行数:9,代码来源:skabelon.py 示例12: euro_vanilla_exact def euro_vanilla_exact(S, K, T, r, sigma, option="call"): # S: spot price # K: strike price # T: time to maturity # r: interest rate # sigma: volatility of underlying asset N = systats.Normal(0.0, 1.0) d1 = (sy.ln(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) d2 = (sy.ln(S / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * sy.sqrt(T)) if option == "call": result = S * N.cdf(d1) - K * sy.exp(-r * T) * N.cdf(d2) if option == "put": result = K * sy.exp(-r * T) * N.cdf(-d2) - S * N.cdf(-d1) return result开发者ID:aschleg,项目名称:Finance_with_Python,代码行数:19,代码来源:black_scholes_exact.py 示例13: test_ansi_math1_codegen def test_ansi_math1_codegen(): # not included: log10 from sympy import (acos, asin, atan, ceiling, cos, cosh, floor, log, ln, sin, sinh, sqrt, tan, tanh, Abs) x = symbols('x') name_expr = [ ("test_fabs", Abs(x)), ("test_acos", acos(x)), ("test_asin", asin(x)), ("test_atan", atan(x)), ("test_ceil", ceiling(x)), ("test_cos", cos(x)), ("test_cosh", cosh(x)), ("test_floor", floor(x)), ("test_log", log(x)), ("test_ln", ln(x)), ("test_sin", sin(x)), ("test_sinh", sinh(x)), ("test_sqrt", sqrt(x)), ("test_tan", tan(x)), ("test_tanh", tanh(x)), ] result = codegen(name_expr, "C89", "file", header=False, empty=False) assert result[0][0] == "file.c" assert result[0][1] == ( '#include "file.h"\n#include \n' 'double test_fabs(double x) {\n double test_fabs_result;\n test_fabs_result = fabs(x);\n return test_fabs_result;\n}\n' 'double test_acos(double x) {\n double test_acos_result;\n test_acos_result = acos(x);\n return test_acos_result;\n}\n' 'double test_asin(double x) {\n double test_asin_result;\n test_asin_result = asin(x);\n return test_asin_result;\n}\n' 'double test_atan(double x) {\n double test_atan_result;\n test_atan_result = atan(x);\n return test_atan_result;\n}\n' 'double test_ceil(double x) {\n double test_ceil_result;\n test_ceil_result = ceil(x);\n return test_ceil_result;\n}\n' 'double test_cos(double x) {\n double test_cos_result;\n test_cos_result = cos(x);\n return test_cos_result;\n}\n' 'double test_cosh(double x) {\n double test_cosh_result;\n test_cosh_result = cosh(x);\n return test_cosh_result;\n}\n' 'double test_floor(double x) {\n double test_floor_result;\n test_floor_result = floor(x);\n return test_floor_result;\n}\n' 'double test_log(double x) {\n double test_log_result;\n test_log_result = log(x);\n return test_log_result;\n}\n' 'double test_ln(double x) {\n double test_ln_result;\n test_ln_result = log(x);\n return test_ln_result;\n}\n' 'double test_sin(double x) {\n double test_sin_result;\n test_sin_result = sin(x);\n return test_sin_result;\n}\n' 'double test_sinh(double x) {\n double test_sinh_result;\n test_sinh_result = sinh(x);\n return test_sinh_result;\n}\n' 'double test_sqrt(double x) {\n double test_sqrt_result;\n test_sqrt_result = sqrt(x);\n return test_sqrt_result;\n}\n' 'double test_tan(double x) {\n double test_tan_result;\n test_tan_result = tan(x);\n return test_tan_result;\n}\n' 'double test_tanh(double x) {\n double test_tanh_result;\n test_tanh_result = tanh(x);\n return test_tanh_result;\n}\n' ) assert result[1][0] == "file.h" assert result[1][1] == ( '#ifndef PROJECT__FILE__H\n#define PROJECT__FILE__H\n' 'double test_fabs(double x);\ndouble test_acos(double x);\n' 'double test_asin(double x);\ndouble test_atan(double x);\n' 'double test_ceil(double x);\ndouble test_cos(double x);\n' 'double test_cosh(double x);\ndouble test_floor(double x);\n' 'double test_log(double x);\ndouble test_ln(double x);\n' 'double test_sin(double x);\ndouble test_sinh(double x);\n' 'double test_sqrt(double x);\ndouble test_tan(double x);\n' 'double test_tanh(double x);\n#endif\n' )开发者ID:chiranthsiddappa,项目名称:sympy,代码行数:54,代码来源:test_codegen.py 示例14: test_ansi_math1_codegen def test_ansi_math1_codegen(): # not included: log10 from sympy import acos, asin, atan, ceiling, cos, cosh, floor, log, ln, sin, sinh, sqrt, tan, tanh, N, Abs x = symbols("x") name_expr = [ ("test_fabs", Abs(x)), ("test_acos", acos(x)), ("test_asin", asin(x)), ("test_atan", atan(x)), ("test_ceil", ceiling(x)), ("test_cos", cos(x)), ("test_cosh", cosh(x)), ("test_floor", floor(x)), ("test_log", log(x)), ("test_ln", ln(x)), ("test_sin", sin(x)), ("test_sinh", sinh(x)), ("test_sqrt", sqrt(x)), ("test_tan", tan(x)), ("test_tanh", tanh(x)), ] result = codegen(name_expr, "C", "file", header=False, empty=False) assert result[0][0] == "file.c" assert result[0][1] == ( '#include "file.h"\n#include \n' "double test_fabs(double x) {\n return fabs(x);\n}\n" "double test_acos(double x) {\n return acos(x);\n}\n" "double test_asin(double x) {\n return asin(x);\n}\n" "double test_atan(double x) {\n return atan(x);\n}\n" "double test_ceil(double x) {\n return ceil(x);\n}\n" "double test_cos(double x) {\n return cos(x);\n}\n" "double test_cosh(double x) {\n return cosh(x);\n}\n" "double test_floor(double x) {\n return floor(x);\n}\n" "double test_log(double x) {\n return log(x);\n}\n" "double test_ln(double x) {\n return log(x);\n}\n" "double test_sin(double x) {\n return sin(x);\n}\n" "double test_sinh(double x) {\n return sinh(x);\n}\n" "double test_sqrt(double x) {\n return sqrt(x);\n}\n" "double test_tan(double x) {\n return tan(x);\n}\n" "double test_tanh(double x) {\n return tanh(x);\n}\n" ) assert result[1][0] == "file.h" assert result[1][1] == ( "#ifndef PROJECT__FILE__H\n#define PROJECT__FILE__H\n" "double test_fabs(double x);\ndouble test_acos(double x);\n" "double test_asin(double x);\ndouble test_atan(double x);\n" "double test_ceil(double x);\ndouble test_cos(double x);\n" "double test_cosh(double x);\ndouble test_floor(double x);\n" "double test_log(double x);\ndouble test_ln(double x);\n" "double test_sin(double x);\ndouble test_sinh(double x);\n" "double test_sqrt(double x);\ndouble test_tan(double x);\n" "double test_tanh(double x);\n#endif\n" )开发者ID:Jerryy,项目名称:sympy,代码行数:54,代码来源:test_codegen.py 示例15: natural_logarithm_sym def natural_logarithm_sym(target, X, A1='', A2='', A3='', A4='', A5=''): r""" Calculates the rate, as well as slope and intercept of the following function at the given value of *x*: .. math:: rate = A_{1} Ln( A_{2} x^{ A_{3} }+ A_{4})+ A_{5} Parameters ---------- A1 -> A5 : string The dictionary keys on the target object containing the coefficients values to be used in the source term model X : string or float/int or array/list The dictionary key on the target objecxt containing the the quantity of interest Returns ------- A dictionary containing the following three items: **'rate'** - The value of the source term function at the given X. **'S1'** - The slope of the source term function at the given X. **'S2'** - The intercept of the source term function at the given X. The slope and intercept provide a linearized source term equation about the current value of X as follow: .. math:: rate = S_{1} X + S_{2} """ A = _parse_args(target=target, key=A1, default=1.0) B = _parse_args(target=target, key=A2, default=1.0) C = _parse_args(target=target, key=A3, default=1.0) D = _parse_args(target=target, key=A4, default=1.0) E = _parse_args(target=target, key=A5, default=0.0) X = target[X] # Symbols used in symbolic function a, b, c, d, e, x = _syp.symbols('a,b,c,d,e,x') # Equation y = a*_syp.ln(b*x**c + d) + e # Callable functions r, s1, s2 = _build_func(eq=y, a=a, b=b, c=c, d=d, e=e, x=x) # Values r_val = r(A, B, C, D, E, X) s1_val = s1(A, B, C, D, E, X) s2_val = s2(A, B, C, D, E, X) values = {'S1': s1_val, 'S2': s2_val, 'rate': r_val} return values开发者ID:PMEAL,项目名称:OpenPNM,代码行数:53,代码来源:generic_source_term.py

注:本文中的sympy.ln函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有