mathematical-expressions

Evaluating a mathematical expression without eval() on Python3

倾然丶 夕夏残阳落幕 提交于 2021-02-07 14:14:56
问题 I'm working on a "copy-paste calculator" that detects any mathematical expressions copied to the system clipboard, evaluates them and copies the answer to the clipboard ready to be pasted. However, while the code uses the eval()-function, I'm not terribly concerned considering the user normally knows what they are copying. That being said, I want to find a better way without giving the calculations a handicap (= eg. removing the ability to calculate multiplications or exponents). Here's the

Non-commutative sympify (or simplify)

情到浓时终转凉″ 提交于 2021-02-06 09:28:09
问题 I would like to be able to simplify mathematical expressions from a string in Python. There are several "commutative" ways of doing it. Is there a non-commutative function for that? I know that sympify from sympy can do some non-commutative jobs, here you have an example: from sympy import * x=Symbol('x',commutative=False) y=Symbol('y',commutative=False) print sympify(3*x*y - y*x - 2*x*y) it will print x y -y x, however if we apply sympify to the string, that is, print sympify('3*x*y - y*x -

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

What is the difference between Mathematica Rules and the objects returned by GraphEdit?

会有一股神秘感。 提交于 2019-12-24 12:00:34
问题 This is actually a two-fold question. First: as someone coming from an OO programming background, I find Mathematica's use of lists as the basis of everything a bit annoying. So here is how a mathematica programmer (as far as I can tell) might define a graph: graph={{1, 2, 3, 4, 5}, {1->2, 2->4, 4->4, 4->5}}; and then the programmer would just have to remember that graph[[1]] refers to the list of vertices and graph[[2]] refers to the list of edges (in this case defined as a set of rules.) So

Tornado plot in R

余生长醉 提交于 2019-12-24 01:27:56
问题 I am trying to make a tornado plot (a.k.a. sensitivity graph) in R. The goal is to visualize the effect of a 10% increase and 10% decrease in some variables. So far I have gotten this result This is the code I am using: # Tornado plot data <- matrix(c(-0.02,0.02,-0.01,0.01,-0.03,0.02,-0.01,0.04), ncol = 4) rownames(data) <- c('+10%','-10%') # Amount of change in variables colnames(data) <- c('V_bar', 'alpha', 'rho','xi') # Names of variables x <- seq(-0.04,0.04, length=10) # For plotting '%'

Evaluating Mathematical Expressions using Lua

*爱你&永不变心* 提交于 2019-12-19 19:58:13
问题 In my previous question I was looking for a way of evaulating complex mathematical expressions in C, most of the suggestions required implementing some type of parser. However one answer, suggested using Lua for evaluating the expression. I am interested in this approach but I don't know anything about Lua. Can some one with experience in Lua shed some light? Specifically what I'd like to know is Which API if any does Lua provide that can evaluate mathematical expressions passed in as a

How to create a notebook with a properly formatted expression

∥☆過路亽.° 提交于 2019-12-19 10:03:02
问题 I have a Mathematica expression generated by another program, which I would like to open in a notebook, properly formatted. For instance, the other program generates this: Plot[{Exp[x],Interpolation[Table[{k/5,Exp[(k-1/2)/5]},{k,0,5}], InterpolationOrder->0][x]},{x,0,1},Filling->{1->{{2},{Yellow,Orange}}}, PlotLabel->Style["Formatting",Blue,FontFamily->"Courier"]] The text is written into a file, crudely suffixed ".nb", and launched, and the expression opens in a notebook without formatting.

How to create a notebook with a properly formatted expression

假装没事ソ 提交于 2019-12-19 10:01:48
问题 I have a Mathematica expression generated by another program, which I would like to open in a notebook, properly formatted. For instance, the other program generates this: Plot[{Exp[x],Interpolation[Table[{k/5,Exp[(k-1/2)/5]},{k,0,5}], InterpolationOrder->0][x]},{x,0,1},Filling->{1->{{2},{Yellow,Orange}}}, PlotLabel->Style["Formatting",Blue,FontFamily->"Courier"]] The text is written into a file, crudely suffixed ".nb", and launched, and the expression opens in a notebook without formatting.

Calculating opacity value mathematically

痞子三分冷 提交于 2019-12-18 10:55:18
问题 How is opacity calculated mathematically? There is opacity value in Photoshop, CSS etc. Actually this opacity is the transparent behavior of a layer. That we all know. But how is it calculated mathematically? Is there any equation to calculate opacity? By setting opacity value what is happening there? Take the case of plain color layers: Layer 1 (Foreground Layer) and Layer 2 (background layer) Layer 1 is red (say color value A ) and Layer 2 is white (say color value B ). When we set opacity

Avoid Overflow when Calculating π by Evaluating a Series Using 16-bit Arithmetic?

时间秒杀一切 提交于 2019-12-13 12:25:33
问题 I'm trying to write a program that calculates decimal digits of π to 1000 digits or more. To practice low-level programming for fun, the final program will be written in assembly, on a 8-bit CPU that has no multiplication or division, and only performs 16-bit additions. To ease the implementation, it's desirable to be able to use only 16-bit unsigned integer operations, and use an iterative algorithm. Speed is not a major concern. And fast multiplication and division is beyond the scope of