sympy

python: changing symbol variable and assign numerical value

最后都变了- 提交于 2021-01-24 07:25:46
问题 In order to calculate derivatives and other expressions I used the sympy package and said that T = sy.Symbol('T') now that I have calculated the right expression: E= -T**2*F_deriv_T(T,rho) where def F_deriv_rho(T,rho): ret = 0 for n in range(5): for m in range(4): inner= c[n,m]*g_rho_deriv_rho_np*g_T_np ret += inner return ret that looks like this: F_deriv_rho: [0.0 7.76971e-5*T 0.0001553942*T**2*rho T*(-5.14488e-5*log(rho) - 5.14488e-5)*log(T) + T*(1.22574e-5*log(rho)+1.22574e-5)*log(T) + T*

python: changing symbol variable and assign numerical value

霸气de小男生 提交于 2021-01-24 07:23:50
问题 In order to calculate derivatives and other expressions I used the sympy package and said that T = sy.Symbol('T') now that I have calculated the right expression: E= -T**2*F_deriv_T(T,rho) where def F_deriv_rho(T,rho): ret = 0 for n in range(5): for m in range(4): inner= c[n,m]*g_rho_deriv_rho_np*g_T_np ret += inner return ret that looks like this: F_deriv_rho: [0.0 7.76971e-5*T 0.0001553942*T**2*rho T*(-5.14488e-5*log(rho) - 5.14488e-5)*log(T) + T*(1.22574e-5*log(rho)+1.22574e-5)*log(T) + T*

Sum of a list of SymPy matrices

☆樱花仙子☆ 提交于 2021-01-01 07:07:13
问题 My python list contains sympy matrix object, and I need to sum them all. If all list elements are just symbols, then using built-in sum function in python works fine. import sympy as sp x = sp.symbols('x') ls = [x, x+1, x**2] print(sum(ls)) >>> x**2 + 2*x + 1 But for the elements of matrix type, sum function looks not working. import sympy as sp ls = [sp.eye(2), sp.eye(2)*5, sp.eye(2)*3] print(sum(ls)) >>> TypeError: cannot add <class 'sympy.matrices.dense.MutableDenseMatrix'> and <class 'int

Sum of a list of SymPy matrices

空扰寡人 提交于 2021-01-01 07:06:09
问题 My python list contains sympy matrix object, and I need to sum them all. If all list elements are just symbols, then using built-in sum function in python works fine. import sympy as sp x = sp.symbols('x') ls = [x, x+1, x**2] print(sum(ls)) >>> x**2 + 2*x + 1 But for the elements of matrix type, sum function looks not working. import sympy as sp ls = [sp.eye(2), sp.eye(2)*5, sp.eye(2)*3] print(sum(ls)) >>> TypeError: cannot add <class 'sympy.matrices.dense.MutableDenseMatrix'> and <class 'int

DiracDelta not giving correct result

大兔子大兔子 提交于 2020-12-30 02:22:05
问题 I have to use dirac delta in a complicated integral and was hoping to see how it works with a simple case but it returns the wrong answer. Any clue what I did wrong in the following? from sympy import DiracDelta from scipy import integrate def f(x): return x*DiracDelta(x-1) b, err = integrate.quad(f, 0, 5) print b This returns 0.0 while it shouldn't. 回答1: It seems sympy functions are not compatible with scipy integrate. One needs to use sympy integrate. The following gives the correct answer

BERT可以上几年级了?Seq2Seq“硬刚”小学数学应用题

眉间皱痕 提交于 2020-12-28 08:03:37
©PaperWeekly 原创 · 作者| 苏剑林 单位|追一科技 研究方向|NLP、神经网络 ▲“鸡兔同笼”的那些年 “盈亏问题”、“年龄问题”、“植树问题”、“牛吃草问题”、“利润问题”...,小学阶段你是否曾被各种花样的数学应用题折磨过呢?没关系,现在机器学习模型也可以帮助我们去解答应用题了,来看看它可以上几年级了? 本文将给出一个求解小学数学应用题(Math Word Problem)的 baseline,基于ape210k 数据集 [1] 训练,直接用 Seq2Seq 模型生成可执行的数学表达式,最终 Large 版本的模型能达到 73%+ 的准确率,高于 ape210k 论文所报告的结果。 所谓“硬刚”,指的是没有对表达式做特别的转换,也没有通过模板处理,就直接生成跟人类做法相近的可读表达式。 数据处理 这里我们先观察一下 ape210k 数据集的情况: { "id": "254761", "segmented_text": "小 王 要 将 150 千 克 含 药 量 20% 的 农 药 稀 释 成 含 药 量 5% 的 药 水 . 需 要 加 水 多 少 千 克 ?", "original_text": "小王要将150千克含药量20%的农药稀释成含药量5%的药水.需要加水多少千克?", "ans": "450", "equation": "x=150*20%/5%

How to proof with Sympy that a given Cartesian equation can be written as a given polar equation

扶醉桌前 提交于 2020-12-26 10:47:33
问题 i have an assignment on sympy and am struggling with the following question: "Prove with the help of Sympy that 4*(x 2 + y 2 -ax) 3 = 27 a 2 (x 2 +y 2 ) 2 can be written using r = 4a*cos(theta/3) 3 ". I have tried to substitute x = r*cos(theta) and y = r*sin(theta) . Then I tried sp.solveset(eq, r) but I only got a very longset of {}, nothing like the given polar equation. Does anyone know how to do this (I can use sympy and numpy)? 回答1: The following code builds the equation from its left

How to proof with Sympy that a given Cartesian equation can be written as a given polar equation

给你一囗甜甜゛ 提交于 2020-12-26 10:38:48
问题 i have an assignment on sympy and am struggling with the following question: "Prove with the help of Sympy that 4*(x 2 + y 2 -ax) 3 = 27 a 2 (x 2 +y 2 ) 2 can be written using r = 4a*cos(theta/3) 3 ". I have tried to substitute x = r*cos(theta) and y = r*sin(theta) . Then I tried sp.solveset(eq, r) but I only got a very longset of {}, nothing like the given polar equation. Does anyone know how to do this (I can use sympy and numpy)? 回答1: The following code builds the equation from its left

How can I compute the area of intersection of two polygons with sympy?

爱⌒轻易说出口 提交于 2020-12-13 03:40:56
问题 How can I compute the area of intersection of two polygons with sympy? Given are two polygons in sympy (sympy.geometry.polygon.Polygon) I'm new to python and sympy, so I don't have any code to show. I tried learning it from documentation but I'm confused at the moment. Can someone help? Thanks in advance 回答1: SymPy will calculate intersections of lines and points but does not calculate regions of overlap. I would recommend looking elsewhere. 来源: https://stackoverflow.com/questions/61415068

How can I compute the area of intersection of two polygons with sympy?

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-13 03:39:41
问题 How can I compute the area of intersection of two polygons with sympy? Given are two polygons in sympy (sympy.geometry.polygon.Polygon) I'm new to python and sympy, so I don't have any code to show. I tried learning it from documentation but I'm confused at the moment. Can someone help? Thanks in advance 回答1: SymPy will calculate intersections of lines and points but does not calculate regions of overlap. I would recommend looking elsewhere. 来源: https://stackoverflow.com/questions/61415068