symbolic-math

Printing syms / matlabFunction slow

送分小仙女□ 提交于 2019-12-01 17:45:11
I am having a lot of trouble trying to make symbolic substitution go faster - that is, substituting in for variables in a symbolic expression and getting out a double. I am creating a complicated function f, and calculating its jacobian df. This goes at a reasonable pace, and I can save it to a file just fine. But when I try to use matlabFunction or even disp or fprintf, the system hangs and is unable to proceed further (even when matlabFunction is set to unoptimized). This is a major problem as I need to be able to do reasonably fast substitution. The f vector is 24 elements, and the Jacobian

Numerical Integration over a Matrix of Functions, SymPy and SciPy

大兔子大兔子 提交于 2019-12-01 16:57:54
问题 From my SymPy output I have the matrix shown below, which I must integrate in 2D. Currently I am doing it element-wise as shown below. This method works but it gets too slow (for both sympy.mpmath.quad and scipy.integrate.dblquad ) for my real case (in which A and its functions are much bigger (see edit below): from sympy import Matrix, sin, cos import sympy import scipy sympy.var( 'x, t' ) A = Matrix([[(sin(2-0.1*x)*sin(t)*x+cos(2-0.1*x)*cos(t)*x)*cos(3-0.1*x)*cos(t)], [(cos(2-0.1*x)*sin(t)

Numerical Integration over a Matrix of Functions, SymPy and SciPy

五迷三道 提交于 2019-12-01 16:48:21
From my SymPy output I have the matrix shown below, which I must integrate in 2D. Currently I am doing it element-wise as shown below. This method works but it gets too slow (for both sympy.mpmath.quad and scipy.integrate.dblquad ) for my real case (in which A and its functions are much bigger (see edit below): from sympy import Matrix, sin, cos import sympy import scipy sympy.var( 'x, t' ) A = Matrix([[(sin(2-0.1*x)*sin(t)*x+cos(2-0.1*x)*cos(t)*x)*cos(3-0.1*x)*cos(t)], [(cos(2-0.1*x)*sin(t)*x+sin(2-0.1*x)*cos(t)*x)*sin(3-0.1*x)*cos(t)], [(cos(2-0.1*x)*sin(t)*x+cos(2-0.1*x)*sin(t)*x)*sin(3-0.1

Am I using a wrong numerical method?

房东的猫 提交于 2019-12-01 13:04:20
问题 This is the code: f = dsolve('D3y+12*Dy+y = 0 ,y(2) = 1 ,Dy(2) = 1, D2y(2) = -1'); feval(symengine, 'numeric::solve',strcat(char(f),'=1'),'t=-4..16','AllRealRoots') If I remove 'AllRealRoots' option it works fast and finds a solution, but when I enable the option Matlab does not finish for an hour. Am I using a wrong numerical method? 回答1: First, straight from the documentation for numeric::solve: If eqs is a non-polynomial/non-rational equation or a set or list containing such an equation,

Make sure MATLAB does not recalculate symbolic expression

孤者浪人 提交于 2019-12-01 11:39:43
I am building (my first...) MatLab program, it needs to differentiate an equations symbolically and then use this solution many many times (with different numeric inputs). I do not want it to recalculate the symbolic differentiation every time it needs to put in a new set of numeric values. This would probably greatly add to the time taken to run this program (which - given its nature, a numeric optimiser, will probably already be hours). My question is how can I structure my program such that it will not recalculate the symbolic differentiation? The class in question is: function [ result ] =

R: trouble making package Ryacas to work on Windows

耗尽温柔 提交于 2019-12-01 07:38:59
I am trying to use the package Ryacas in R . Here what is going on: > install.packages("Ryacas") --- Please select a CRAN mirror for use in this session --- trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/2.14/Ryacas_0.2-11.zip' Content type 'application/zip' length 263424 bytes (257 Kb) opened URL downloaded 257 Kb package ‘Ryacas’ successfully unpacked and MD5 sums checked The downloaded packages are in C:\Documents and Settings\yogcal\Local Settings\Temp\RtmpKeuu7m\downloaded_packages Then I try to load Ryacas : > library(Ryacas) Loading required package: XML C:\Program Files

Convert symbolic expressions to Python functions using SymPy

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 07:01:27
问题 I have a rather large symbolic function that is evaluated for different values of a parameter in a loop. In each iteration, after finding the expression of the function, partial derivatives are derived. Something like this: from sympy import diff, symbols,exp def lagrange_eqs(a): x,y,z= symbols('x y z') FUNC=x**2-2*x*y**2+z+a*exp(z) d_lgrng_1=diff(FUNC,x) d_lgrng_2=diff(FUNC,y) d_lgrng_3=diff(FUNC,z) return [d_lgrng_1,d_lgrng_2,d_lgrng_3] Next, I need to convert the output of this function to

How do I convert an anonymous function to a symbolic function in MATLAB?

与世无争的帅哥 提交于 2019-12-01 04:05:06
Say I have a anonymous function f = @(x) x^2 and I want to convert this to a symbolic function. Is there a built in command for that? You could just pass it to SYM: f = @(x) x^2; g = sym(f) But then most of the symbolic functions do that automatically when they receive a function handle ( subs , int , etc...) 来源: https://stackoverflow.com/questions/11322295/how-do-i-convert-an-anonymous-function-to-a-symbolic-function-in-matlab

Factoring polys in sympy

回眸只為那壹抹淺笑 提交于 2019-12-01 04:05:00
I'm doing a very simple probability calculations of getting subset of X, Y, Z from set of A-Z (with corresponding probabilities x, y, z). And because of very heavy formulas, in order to handle them, I'm trying to simplify (or collect or factor - I dont know the exact definition) these polynomial expressions using sympy . So.. having this (a very simple probability calculation expression of getting subset of X,Y,Z from set of A-Z with corresponding probabilities x, y, z) import sympy as sp x, y, z = sp.symbols('x y z') expression = ( x * (1 - x) * y * (1 - x - y) * z + x * (1 - x) * z * (1 - x

Factoring polys in sympy

我的未来我决定 提交于 2019-12-01 02:27:29
问题 I'm doing a very simple probability calculations of getting subset of X, Y, Z from set of A-Z (with corresponding probabilities x, y, z). And because of very heavy formulas, in order to handle them, I'm trying to simplify (or collect or factor - I dont know the exact definition) these polynomial expressions using sympy . So.. having this (a very simple probability calculation expression of getting subset of X,Y,Z from set of A-Z with corresponding probabilities x, y, z) import sympy as sp x,