symbolic-math

Solve for only certain variables with symbolic solver

怎甘沉沦 提交于 2019-12-10 18:01:52
问题 I am trying to solve a system of equations in MATLAB with 3 variables and 5 constants. Is it possible to solve for the three variables with solve while keeping the constants as symbolic and not replacing them with numerical values? 回答1: When you use the SOLVE function (from the Symbolic Toolbox) you can specify the variables you want to solve for. For example, let's say you have three equations with variables x , y , and z and constants a and b . The following will give you a structure S with

How to store Taylor series coefficients into an array in Matlab script

浪子不回头ぞ 提交于 2019-12-10 16:32:19
问题 This question is in the context of a .m script. I know how to get the Taylor series of a function, but I do not see any command that allows one to store the series' coefficients into an array – sym2poly does not seem to work. How does one store coefficients into an array? For example, this function: syms x f = 1/(x^2+4*x+9) How would we be able to get the Taylor coefficients? fntlr did not work. 回答1: Using your example, the symbolic taylor and coeffs functions can be used to obtain a vector

Sum of partial derivatives of a product over a symbolic number of variables

假如想象 提交于 2019-12-10 16:10:19
问题 I would like SymPy to evaluate an expression like the following: How would I define the symbols and the expression so that SymPy could handle it nicely? I would like to keep N as just a symbol, i.e. not make an actual finite list of x 's. I have tried various combinations of IndexedBase and Sum / Product , but didn't get it working right. 回答1: Ideally it would be this: x = IndexedBase("x") i, j, N = symbols("i j N") expr = Sum(Product(exp(-x[j]**2), (j, 1, N)).diff(x[i]), (i, 1, N)) So far

Interpreting error from computing Jordan form of 36-by-36 matrix

廉价感情. 提交于 2019-12-10 13:02:32
问题 I've been trying to compute the jordan normal form of a 36-by-36 matrix composed of only three distinct entries, 1 , 1/2 , and 0 . The matrix is a probability transition matrix so, given these entries, the matrix is obviously sparse. The issue I've been having is the following: whenever I try to compute [V, J] = jordan(A), or [V, J] = jordan(sym(A)), I get the following error message: Error using mupadmex Error in MuPAD command: Similarity matrix too large. Error in sym/mupadmexnout (line

Dealing with piecewise equations returned by sympy integrate

不羁岁月 提交于 2019-12-10 12:34:17
问题 In sympy I have an integral which returns a Piecewise object, e.g. In [2]: from sympy.abc import x,y,z In [3]: test = exp(-x**2/z**2) In [4]: itest = integrate(test,(x,0,oo)) In [5]: itest Out[5]: ⎧ ___ ⎪ ╲╱ π ⋅z │ ⎛ 1 ⎞│ π ⎪ ─────── for │periodic_argument⎜──────────────, ∞⎟│ ≤ ─ ⎪ 2 │ ⎜ 2 ⎟│ 2 ⎪ │ ⎝polar_lift (z) ⎠│ ⎪ ⎪∞ ⎪⌠ ⎨⎮ 2 ⎪⎮ -x ⎪⎮ ─── ⎪⎮ 2 ⎪⎮ z ⎪⎮ ℯ dx otherwise ⎪⌡ ⎪0 ⎩ I would like to extract just the first branch of this piecewise equation, in other words, I would like to be able to

Summation series using matlab

≡放荡痞女 提交于 2019-12-10 04:35:40
问题 When i write this in matlab syms x; f=x^3-cos(x); g=diff(f) it gives out put as g = 3*x^2+sin(x) Now I want to generate summation series as I google and found "symsum" command but it doesn't do my required task, when i write the following commands syms k symsum(k^2, 0, 10) symsum(1/k^2,1,Inf) it gives the out put as ans = 385 ans = pi^2/6 Can you guys guide me how can I genereate the series which produce output as so that when I give command diff(Sk); it should produce result as or something

How to solve matrix equation with sympy?

风格不统一 提交于 2019-12-09 18:08:29
问题 In sympy, given a matrix equation M * x + N * y = 0 (or more complicated..) how to solve this for x? (M,N = matrices, x,y = vectors) I tried this with normal symbols, but obviously this failed. Using MatrixSymbol was not working as well. Is there some way to do it, or is sympy not capable of doing it? 回答1: As MRocklin noted, MatrixExpressions don't support this yet, but noncommutative symbols do: In [13]: M, N, x, y = symbols('M N x y', commutative=False) In [15]: solve(M*x + N*y, x) Out[15]:

How to fix my simplification function for power rule (to make results easier to read) for a working Symbolic differentiation function in Racket?

与世无争的帅哥 提交于 2019-12-08 06:01:36
问题 This is my function for differentiation that works correctly. #lang racket (define (diff x expr) (if (not (list? expr)) (if (equal? x expr) 1 0) (let ( (operation (car expr)) (u (cadr expr)) (v (caddr expr))) (case operation ((+) (list '+ (diff x u) (diff x v))) ((-) (list '- (diff x u) (diff x v))) ((*) (list '+ (list '* u (diff x v)) (list '* v (diff x u)))) ((/) (list '/ (list '- (list '* v (diff x u)) (list '* u (diff x v))) (list '* v v))) ((^) (list '* v (list '* (list '^ u (- v 1))

How to solve symbolic equation with double coefficients in matlab?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 01:57:18
问题 I have quadratic equation 1/x = 1/(a-x) + 1/(3*a -x) I want to solve it in matlab: solve('1/x=1/(a-x)+1/(3*a-x)', 'x') ans = (4/3+1/3*7^(1/2))*a (4/3-1/3*7^(1/2))*a Is there any way to solve equation with float coefficient? Like ans = 2.215250437021530*a 0.451416229645136*a 回答1: Apparently, double(ans) should convert it for you. 回答2: I used eval() to get a double result from a symbolic expression 来源: https://stackoverflow.com/questions/881010/how-to-solve-symbolic-equation-with-double

How to use sympy.physics.quantum Commutator?

安稳与你 提交于 2019-12-07 17:31:13
问题 I want to work out some commutator manipulations and found this tool in sympy. It appears to work as expected (but the documentation is virtually non-existent or at least I found little, but see the comment by Dalton Bentley below), but I ran into the following problem. from sympy.physics.quantum import Commutator as Comm from sympy.physics.quantum import Operator A = Operator('A') B = Operator('B') C = Comm(Comm(Comm(A,B),A),B) D = Comm(Comm(Comm(A,B),B),A) E = (C-D).expand(commutator=true)