symbolic-math

question about solving system of equations using symbolic math

左心房为你撑大大i 提交于 2019-12-25 01:14:52
问题 I want to use symbolic symbol to solve a system of linear equation. So I prepare the following code. A=[1,2;3,4]; % syms x x=sym('x_%d',[2 1]); eqn=A*x==[1;2]; result=solve(eqn,x) Interestingly, it works, but when I read the variable result, it gives a 1X1 struct with x_1 and x_2 are 1X1 sym. But what I expect get should be 2 real values, why? Could someone explain it? Remark: do not want to use A^-1*[1;2] to obtain the answer. 回答1: If you set the output to single variable solve returns a

Arithmetical operations on equations symbolicaly in R without yacas

筅森魡賤 提交于 2019-12-24 23:21:25
问题 I have equations defined like f<-"x^2" and g<-"y^2" . I want to obtain equation z like z<-(x^2)*(y^2) . 'Class(f)', 'class(g)' and 'class(z)' values doesn`t matter for me. I tried this: > f<-"x^2" > g<-"y^2" > z<-f*g I got: Error in f * g : non-numeric argument to binary operator<br/> I tried multiplying f<-expression(f) and g<-expression(g) with no result. I tried also: > f<-function(x) x^2 > g<-function(y) y^2 > z<-function(x,y) f*g > z<-parse(text=z) I got: Error in as.character(x) :

Matlab: How do I convert multivariable symbolic expression to a function that fminsearch can use?

你说的曾经没有我的故事 提交于 2019-12-24 15:02:17
问题 I have a multivariable symbolic expression say c = x^2 +y^2 + z^2 using matlabFunction(c) returns ans = @(x,y,z)x.^2+y.^2+z.^2 I can't input this into fminsearch (because it has multiple scalar inputs right?). How can I change the format of the output so it takes something that fminsearch actually allows, something like @(x)x(1)^2+x(2)^2+x(3)^2 It is feasible to do this manually for 3 variables but not for hundreds. The errors look something like if it helps: Error using symengine?makeFhandle

Use more “natural” form to manipulate piecewise step functions in Matlab MuPAD?

我怕爱的太早我们不能终老 提交于 2019-12-24 14:53:14
问题 I have the unit step function: u0:= piecewise([-infinity < t and t < 0,0],[0 < t and t < infinity,1]): Now I want to plot it at some point: T:=1:; plot(u0|t=t-T/2); This works. But when I use a more natural expression: T:=1:; plot(u0(t-T/2)); it simply plots the original unshifted step function. Is there any way to use the more simpler form when plotting the modified step function? 回答1: I believe the reason that what you call the "more natural form" doesn't work, is because u0 has not been

Boolean operation with symbol in Sympy

烂漫一生 提交于 2019-12-24 14:33:00
问题 Boolean operation of a Boolean variable on a symbol produces TypeError , but the reverse has no problem: >>> from sympy import * >>> x = Symbol('x', bool=True) >>> x ^ True Not(x) >>> True ^ x Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> True ^ x TypeError: unsupported operand type(s) for ^: 'bool' and 'Symbol' I can do try-catch: try : print True ^ x except TypeError: print x ^ True Not(x) But, for my present task, it is impossible to implement this with try

The roots of the characteristic polynomial and the eigenvalues are not the same

时光毁灭记忆、已成空白 提交于 2019-12-24 07:53:48
问题 This is matrix B B = [1 2 0 ; 2 4 6 ; 0 6 5] The result of eig(B) is: {-2.2240, 1.5109, 10.7131} and the characteristic polynomial of B by this link is syms x polyB = charpoly(B,x) x^3 - 10*x^2 - 11*x + 36 but the answer of solve(polyB) is 133/(9*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) + ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3) + 10/3 (3^(1/2)*(133/(9*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) - ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3))*i)/2 - 133/(18*(3^(1/2)*5492^(1/2)*(i/3) + 1009

More than one module for lambdify in sympy

三世轮回 提交于 2019-12-23 10:28:28
问题 I am trying to make lambdify understand to expect more than one type of input using the modules keyword argument. According to the source code of lambdify (http://docs.sympy.org/dev/_modules/sympy/utilities/lambdify.html), this can be done by using lists of the arguments, but i am not able to do so. import sympy from sympy import lambdify x,y=sympy.symbols('x y') from sympy.parsing.sympy_parser import parse_expr func=lambdify(x,parse_expr(exp(x)),modules=["numpy","sympy"]) func(array([3,4]))

More than one module for lambdify in sympy

被刻印的时光 ゝ 提交于 2019-12-23 10:26:24
问题 I am trying to make lambdify understand to expect more than one type of input using the modules keyword argument. According to the source code of lambdify (http://docs.sympy.org/dev/_modules/sympy/utilities/lambdify.html), this can be done by using lists of the arguments, but i am not able to do so. import sympy from sympy import lambdify x,y=sympy.symbols('x y') from sympy.parsing.sympy_parser import parse_expr func=lambdify(x,parse_expr(exp(x)),modules=["numpy","sympy"]) func(array([3,4]))

Computation of symbolic eigenvalues with sympy

被刻印的时光 ゝ 提交于 2019-12-23 09:37:43
问题 I'm trying to compute eigenvalues of a symbolic complex matrix M of size 3x3 . In some cases, eigenvals() works perfectly. For example, the following code: import sympy as sp kx = sp.symbols('kx') x = 0. M = sp.Matrix([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]) M[0, 0] = 1. M[0, 1] = 2./3. M[0, 2] = 2./3. M[1, 0] = sp.exp(1j*kx) * 1./6. + x M[1, 1] = sp.exp(1j*kx) * 2./3. M[1, 2] = sp.exp(1j*kx) * -1./3. M[2, 0] = sp.exp(-1j*kx) * 1./6. M[2, 1] = sp.exp(-1j*kx) * -1./3. M[2, 2] = sp.exp(-1j

Using the Pochhammer Symbol in Matlab

旧时模样 提交于 2019-12-22 11:06:31
问题 I've tried to use a script that evaluates the Pochhammer symbol (rising factorial) in Matlab, but it fails to evaluate pochhammer(x,n) whenever x is a negative number even though the expression is valid when x is negative (Wolfram Alpha and Mathematica give answers for Pochhammer(-3,2) ). Can anyone help me get pochhammer working in Matlab for negative arguments? 回答1: I assume that you're referring to this Pochhammer function. Note that pochhammer (not capitalized) is part of MuPAD, which is