symbolic-math

sympy: Collect symbols for matrix coefficients?

﹥>﹥吖頭↗ 提交于 2019-12-12 09:05:12
问题 I am trying to factor an expression, and separate coefficients to matrix form, such that: Closely related to Factor sympy expression to matrix coefficients?, where Wild symbols are used with match(form) to determine coefficients for its matrix form. However, I am unable to get the match(form) method to work for the following. Why does match(form) method fail? What are clean alternatives to accomplish this? #Linear Interpolation function: V(x) v_1, theta_1, v_2, theta_2, x, L = symbols("v_1,

Solving nonlinear minimization equations symbolically in matlab

£可爱£侵袭症+ 提交于 2019-12-12 02:39:47
问题 I have a large underdetermined equation system for which I search an unique solution in respect of any given constraints. I simplified my problem into the following one: x²-4=0, y²-9=0, x*y=myMin, x+y=myMin. What is the best way to implement this in Matlab symbolically, so that it returns x=2 y=-3 I'm searching something like syms x y S=solve(... x²-4==0,... y²-9==0,... x*y==myMin,... x+y==myMin); 回答1: I do not know how specify the min as a function command to solve . But here's an approach

How to convert Mupad symbol 'I' {sqrt(-1)} to 'i' in matlab

扶醉桌前 提交于 2019-12-11 20:13:02
问题 I am trying to evaluate this integral in matlab matlab is treating 'ans' as a symbol because of 'I'. How to convert this 'I' into 'i' so that ans becomes a complex number. much appreciated! 回答1: The symbolic math toolbox has an overloaded double function that can be used to convert from sym to double representation (if the expression is a symbolic constant or is a constant expression). For example: ans_sym = vpa(1+1*i); ans_double = double(ans_sym); Look here for more information: http://www

If the input expression contains a symbolic variable, use the VPA function instead?

六月ゝ 毕业季﹏ 提交于 2019-12-11 19:19:41
问题 Im tring to substract the diagonal values with eigval and store the new value in the matrix Diagonal : CovarianceMatrix=[8 -3 1;2 1 0;3 4 5]; Col=3; Row=3; store=1; syms eigval; for loop1= Col:-1:1 Rw=1; syms eigval; for loop2= 1:Row if Rw==loop1 Diagonal= (CovarianceMatrix(Rw,loop1)-eigval); Fix_Diagonal_2(loop2,store)=sym(Diagonal); else Diagonal= CovarianceMatrix(Rw,loop1); Fix_Diagonal_2(loop2,store)=Diagonal; end Rw=Rw+1; loop1=loop1-1; if loop1==0 loop1=3; end end store=store+1; end But

Matlab wont shorten answer after format short

感情迁移 提交于 2019-12-11 14:03:26
问题 I'm trying to get matlab to shorten the answer into scientific notation but it continues to display long numbers. Here is my matlab script: syms E; kb=8.617e-5; %eV/k h=4.136e-15; %eV*s Ts=5760; %k q=1; %ev c=3.0e8; %m/s theta_s=atan(7e8/1.5e11); %rad format short Il_per_area = (q*pi/2)*(1-cos(2*theta_s))*int(((2/h^3*c^2)*E^2)/(exp(E/(kb*Ts-1))),E) This is the result matlab gave me: Il_per_area = (52508430427297951419542428146127404493579145286547868195529063488882991519987*exp(

Possible to have logical operations (e.g. `ndarray.__eq__`) not return `bool` in NumPy?

天涯浪子 提交于 2019-12-11 14:01:35
问题 Question What's the most elegant way to have NumPy not always force np.equal / np.ndarray.__eq__ return arrays of type bool , especially when dtype=object ? Problem Project issue: https://github.com/RobotLocomotion/drake/issues/8315 We're presently using NumPy in a project, and we have symbolic scalars that we're using in the arrays. We define __eq__ to return a formula - here's a simple class that kinda reflects it: import numpy as np class Custom(object): def __init__(self, value): self

“Unable to prove `expr` literally…” error when trying to compare a symbol inside a function

那年仲夏 提交于 2019-12-11 13:09:28
问题 I just started learning MATLAB and I'm trying to normalize a bump function given by function b = bump(x) region1 = abs(x) < 1 b(region1) = (exp(-1./(1 - x(region1).^2))) region2 = abs(x) >= 1 b(region2) = 0 end To do this, I need to divide by the definite integral from -1 to 1. However, when I input syms x; int(bump(x), -1, 1) I get a long error message, which says Error using symengine (line 58) Unable to prove 'abs(x) < 1' literally. To test the statement mathematically, use isAlways. Error

Matlab - “Could not extract differential variables to solve for” in dsolve

醉酒当歌 提交于 2019-12-11 12:25:05
问题 I am trying to solve a RLC circuit as a symbolic differential equation in MATLAB using dsolve , the equation being U(t) = L*Q''(t) + R*Q'(t) + (1/C)*Q(t) with the initial conditions Q(0) = 0 Q'(0) = 0 and U(t) = 10*sin(2*t) L = 1 R = 0 C = 1/4 While this works ... When I implement it explicitly (and using strings) as Q = dsolve('D2Q(t) + 4*Q(t) = 10*sin(2*t)', 'DQ(0)=0, Q(0)=0'); Q = simplify(Q); I'll get Q = 5 sin(2 t) 5 t cos(2 t) ---------- - ------------ 4 2 which is correct. ... this

How to convert symbolic expressions to vectorized functions in MATLAB?

爷,独闯天下 提交于 2019-12-11 10:38:18
问题 Can MatLab convert something like syms t real 2*t^2+5*t+6 to 2.*t.^2+5.*t+6 automatically? Example syms t real a=2; v=int(a,t); Now v=2*t so I want to convert it to v=2.*t . 回答1: If you have a string , you can do the replacing with regexprep: >> str = '2*t^2+5*t+6-3/t' str = 2*t^2+5*t+6-3/t >> str = regexprep(str, '([\*\^\/])', '.$1') str = 2.*t.^2+5.*t+6-3./t As you see, this changes all occurrences of * , ^ or / to their dotted versions. If the string may already contain some dotted

How to check if a SymPy expression has analytical integral

谁都会走 提交于 2019-12-11 09:08:46
问题 I want to solve my other question here so I need sympy to return an error whenever there is no analytical/symbolic solution for and integral. For example if I try : from sympy import * init_printing(use_unicode=False, wrap_line=False, no_global=True) x = Symbol('x') integrate(1/cos(x**2), x) It just [pretty] prints the integral itself without solving and/or giving an error about not being able to solve it! P.S. I have also asked this question here on Reddit. 回答1: A "symbolic" solution always