symbolic-math

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

依然范特西╮ 提交于 2019-12-01 00:57:52
问题 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? 回答1: 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

Turn user input string into mathematical function

只愿长相守 提交于 2019-12-01 00:06:14
For the purposes of what I want to do I need to take a user input as a string and convert it into an unevaluated function. For example, if the user input was "x^2*sin(x)" I would need a function that took a double input x and returned Math.Pow(x, 2)*Math.Sin(x) I need the function, I can't pass in a value for x and I will be calling the function many times (hundreds possibly) so I can't parse the string each time I am making a calculation. How would I implement this? I take it from the question Convert a string into mathematical equation? that there is not a standard way to do this. But I am a

How do I make a function from a symbolic expression in MATLAB?

北战南征 提交于 2019-11-30 20:12:39
How can I make a function from a symbolic expression? For example, I have the following: syms beta n1,n2,m,aa= Constants u = sqrt(n2-beta^2); w = sqrt(beta^2-n1); a = tan(u)/w+tanh(w)/u; b = tanh(u)/w; f = (a+b)*cos(aa*u+m*pi)+a-b*sin(aa*u+m*pi); %# The main expression If I want to use f in a special program to find its zeroes, how can I convert f to a function? Or, what should I do to find the zeroes of f and such nested expressions? You have a couple of options... Option #1: Automatically generate a function If you have version 4.9 (R2007b+) or later of the Symbolic Toolbox you can convert a

Derivatives in C/C++?

本小妞迷上赌 提交于 2019-11-30 12:37:03
问题 I have some expressions such as x^2+y^2 that I'd like to use for some math calculations. One of the things I'd like to do is to take partial derivatives of the expressions. So if f(x,y) = x^2 + y^2 then the partial of f with respect to x would be 2x , the partial with respect to y would be 2y . I wrote a dinky function using a finite differences method but I'm running into lots of problems with floating point precision. For example, I end up with 1.99234 instead of 2 . Are there any libraries

How do I make a function from a symbolic expression in MATLAB?

被刻印的时光 ゝ 提交于 2019-11-30 04:14:01
问题 How can I make a function from a symbolic expression? For example, I have the following: syms beta n1,n2,m,aa= Constants u = sqrt(n2-beta^2); w = sqrt(beta^2-n1); a = tan(u)/w+tanh(w)/u; b = tanh(u)/w; f = (a+b)*cos(aa*u+m*pi)+a-b*sin(aa*u+m*pi); %# The main expression If I want to use f in a special program to find its zeroes, how can I convert f to a function? Or, what should I do to find the zeroes of f and such nested expressions? 回答1: You have a couple of options... Option #1:

What is symbolic computation?

我的梦境 提交于 2019-11-30 03:41:57
According to wiki : In mathematics and computer science, computer algebra, also called symbolic computation or algebraic computation is a scientific area that refers to the study and development of algorithms and software for manipulating mathematical expressions and other mathematical objects Does symbolic computation focus on symbol manipulation and computation? Lisp program is written in the form of an AST with atoms as leaves. Lisp is said to be language for symbolic computing. Does it mean that in symbolic computation, it is: all about symbols (symbols are atoms or non-atom expressions in

Derivatives in C/C++?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 03:09:18
I have some expressions such as x^2+y^2 that I'd like to use for some math calculations. One of the things I'd like to do is to take partial derivatives of the expressions. So if f(x,y) = x^2 + y^2 then the partial of f with respect to x would be 2x , the partial with respect to y would be 2y . I wrote a dinky function using a finite differences method but I'm running into lots of problems with floating point precision. For example, I end up with 1.99234 instead of 2 . Are there any libraries that support symbolic differentiation? Any other suggestions? I've implemented such libraries in

How to have MATLAB display answer in decimals with e instead of fractions

若如初见. 提交于 2019-11-29 16:33:40
So im using MATLAB to calculate the coefficient of an equation and it keeps displaying fractions as the constants instead of decimal form like xxe-x My code is below bt = 0.03175; bpzt = 0.0078; ht = 0.003; w = 50; % frequency in Hz pnic = 8908; % density of nickel Enic = 200e9; % Young's modulus of nic L = 0.3048; % Length of canitlever beam in m syms hn inertia = (1/12)*bt*ht^3 + (1/2)*bpzt*ht^2*hn - (1/2)*bpzt*ht*hn^2 + (2/3)*bpzt*hn^3 area = (bt*ht - 2*hn*bt + 2*bpzt*hn); You are using the symbolic math toolbox. You have to convert any symbolic variable back to a numerical one. Use double

How to simplify logarithm of exponent in sympy?

百般思念 提交于 2019-11-29 16:17:14
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? 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 of this formula is not always is equal to x . Example is here . If you want to force the simplification,

How to implement a derivative of a symbolic function by a 'symfun' in Matlab?

◇◆丶佛笑我妖孽 提交于 2019-11-29 14:34:40
Here is my Matlab program: syms x(t) t; f = x^2 + 5; And the result of f : f(t) = x(t)^2 + 5 Both f and x are of class symfun in Matlab. I want the result of df/dx, which is equal to 2*x(t) . I tried this in Matlab: diff(f, x); and got the following errors: Error using mupadmex Error in MuPAD command: The variable is invalid. [stdlib::diff] Error in sym/diff (line 57) R = mupadmex('symobj::diff', S.s, x.s, int2str(n)); How can df/dx be obtained in Matlab? In newer versions of Matlab (I'm using R2014b) the error message is clearer: Error using sym/diff (line 26) All arguments, except for the