symbolic-math

How to access symbolic expression based on arithmetic operators MATLAB

故事扮演 提交于 2019-12-04 21:17:53
The symbolic expression below is one example out of many expressions expr = x + (x/z)*log(C + x/y); for the above expression I need to solve as below STEP 1: var1 = x/y % accessing expression one operation at a time result1 = applySomeFunction(var1) STEP 2: var2 = var1+C result2 = someConstantValue*result1+ applySomeFunction(var2); STEP 3: var3 = log(var2) result3 = someConstantValue*result2 + applySomeFunction2(var3); Step4: var4 = var3*x result4 = someConstantValue*result3 + applySomeFunction2(var34); . . . until the end of expression. Is there a way to extract and access symbolic

substitute the derivative of a function in a symbolic expression

二次信任 提交于 2019-12-04 10:51:06
I have the same question as here . In Matlab the derivative of a function can be represented symbolically as >> syms t >> syms x(t) >> diff(x,t) ans(t) = D(x)(t) But how can I substitute in an expression if, say, I know the derivative. >> subs(ans,D(x)(t),3) Error: ()-indexing must appear last in an index expression. Let's work through an example: syms t x(t) y f = x^2+y dfdt = diff(f,t) % returns 2*D(x)(t)*x(t) dxdt = diff(x,t) % returns D(x)(t) subs(dfdt,dxdt,3) which returns the 6*x(t) . The key is that D(x)(t) is just the printed representation of the derivative with respect to time, not

Factor sympy expression to matrix coefficients?

六眼飞鱼酱① 提交于 2019-12-04 10:39:39
I have tried to be diligent in looking through documentation and am coming up empty. I am trying to factor or eliminate terms in a expression to matrix form. My problem appears to differ from polynomial factoring (as I plan to implement a function phi(x,y,z) = a_1 + a_2*x + a_3*y + a_4*z ) import sympy from sympy import symbols, pprint from sympy.solvers import solve phi_1, phi_2, x, a_1, a_2, L = symbols("phi_1, phi_2, x, a_1, a_2, L") #Linear Interpolation function: phi(x) phi = a_1 + a_2*x #Solve for coefficients (a_1, a_2) with BC's: phi(x) @ x=0, x=L shape_coeffs = solve([Eq(phi_1, phi)

Computer algebra for Clojure

删除回忆录丶 提交于 2019-12-04 10:17:01
问题 Short version: I am interested in some Clojure code which will allow me to specify the transformations of x (e.g. permutations, rotations) under which the value of a function f(x) is invariant, so that I can efficiently generate a sequence of x's that satisfy r = f(x). Is there some development in computer algebra for Clojure? For (a trivial) example (defn #^{:domain #{3 4 7} :range #{0,1,2} :invariance-group :full} f [x] (- x x)) I could call (preimage f #{0}) and it would efficiently return

Simplifying a very long symbolic expression by automatically introducing temporal variables or in any other way

北城以北 提交于 2019-12-04 05:39:14
After attempting to solve a symbolic math problem, I got an expression with about 17000 characters. I am using the symbolic toolbox for Matlab, but I am open to any suggestion (Mathematica, whatever). For obvious reasons, I won't copy-paste the expression straight into the question. Here is a link instead . Running the Matlab commands simplify and simple , and even attempts to collect didn't improve the situation (Some got it worse). But I am wondering, I don't care if the expression is evaluated in steps, with temporal parameters. Something like: z1 = a^2*y1; %Now the expression can be

How to simplify logarithm of exponent in sympy?

六月ゝ 毕业季﹏ 提交于 2019-12-03 18:11:44
问题 When I type import sympy as sp x = sp.Symbol('x') sp.simplify(sp.log(sp.exp(x))) I obtain log(e^x) Instead of x . I know that "there are no guarantees" on this function. Question. Is there some specific simplification (through series expansion or whatsoever) to convert logarithm of exponent into identity function? 回答1: You have to set x to real type and your code will work: import sympy as sp x = sp.Symbol('x', real=True) print(sp.simplify(sp.log(sp.exp(x)))) Output: x . For complex x result

Solving systems of equations in R

感情迁移 提交于 2019-12-03 12:38:16
问题 Solving an equation symbolically can be achieved in R using the Ryacas library. For example library(Ryacas) yacas("Solve(x/(1+x) == a, x)") gives expression(list(x == a/(1 - a))) Does anybody know how to (symbolically) solve a system of equations? Thank you. 回答1: Well, i use the excellent python library, sympy , for symbolic computation. Using sympy , solving systems of equations straightforward: >>> from sympy import * >>> x,y = symbols('x y') >>> solve([Eq(x + 5*y, 2), Eq(-3*x + 6*y, 15)],

Computer algebra for Clojure

爱⌒轻易说出口 提交于 2019-12-03 05:17:10
Short version: I am interested in some Clojure code which will allow me to specify the transformations of x (e.g. permutations, rotations) under which the value of a function f(x) is invariant, so that I can efficiently generate a sequence of x's that satisfy r = f(x). Is there some development in computer algebra for Clojure? For (a trivial) example (defn #^{:domain #{3 4 7} :range #{0,1,2} :invariance-group :full} f [x] (- x x)) I could call (preimage f #{0}) and it would efficiently return #{3 4 7}. Naturally, it would also be able to annotate the codomain correctly. Any suggestions? Longer

Haskell library like SymPy? [closed]

随声附和 提交于 2019-12-03 04:46:34
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I need to manipulate expressions like 1 + sqrt(3) and do basic arithmetic like addition, subtraction, and division. I'd like the result to be in some sort of canonical form so that it can be used as a key in a map. Turning 1 + sqrt(3) into a float is not feasible due to roundoff problems. I used SymPy for this

Solving systems of equations in R

百般思念 提交于 2019-12-03 02:58:22
Solving an equation symbolically can be achieved in R using the Ryacas library. For example library(Ryacas) yacas("Solve(x/(1+x) == a, x)") gives expression(list(x == a/(1 - a))) Does anybody know how to (symbolically) solve a system of equations? Thank you. doug Well, i use the excellent python library, sympy , for symbolic computation. Using sympy , solving systems of equations straightforward: >>> from sympy import * >>> x,y = symbols('x y') >>> solve([Eq(x + 5*y, 2), Eq(-3*x + 6*y, 15)], [x, y]) {y: 1, x: -3} So that's how to solve a system of equations using symbolic algebra, except