equation

Verify Mathematical Equation c++ [closed]

大城市里の小女人 提交于 2019-12-02 13:03:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I am currently trying to build a very simple compiler. I have created a function that converts a mathematical equation in infix notation to RPN using the shunting-yard algorithm however I have encountered a problem. I did not include error checking in my conversion function so I was

How to calculate an equation in a string, python

不想你离开。 提交于 2019-12-02 07:06:12
So i have a variable that is function = '(2*1)+3' how would i get it out of string form and claculate the answer? i tried using float() int(float()) but im not sure if thats for numbers only or not. I've written this a couple times, and every time it seems that I lose the code... A very simple (and "safe") calculator can be created using ast : import ast import operator _OP_MAP = { ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, ast.Div: operator.div, ast.Invert: operator.neg, } class Calc(ast.NodeVisitor): def visit_BinOp(self, node): left = self.visit(node.left) right =

Python equation parser

非 Y 不嫁゛ 提交于 2019-12-02 05:56:51
问题 I'm writing a program which needs a user input for an polynomial function of x. I'm using Tkinter and python 2.5. I have a parser method which so far takes the inputted equation and splits it into terms without dropping the signs. I want to take each term and parse it to get a tuple of the (coefficient, degree). For example, -2x^3 returns (-2,3). I can then add these to an array and manipulate them accordingly in the program. Is there a way or standard module that can do this? Here is the

Postfix to Infix conversation [closed]

折月煮酒 提交于 2019-12-02 04:08:37
I can not solve this expression from postfix to infix. Please help me to understand in detail 5 x y - / x y + 3 ^ 7 / + postfix to infix: 5 x y - / x y + 3 ^ 7 / + STEP 5 x y - / A) 5xy-/ = 5 (x-y)/ = (5 / (x-y)) x y + B) x y + = (x + y) (x+y) 3 ^ B.1) (x + y) 3 ^ = ((x + y) ^ 3 ) Now, (5 / (x-y)) ((x + y) ^ 3 ) 7 / + = (5 / (x-y)) (((x + y) ^ 3 )/7 ) + = (5 / (x-y)) + (((x + y) ^ 3 )/7 ) POSTFIX and PREFIX are expression in which no brackets are used. Precedence of operator are decided in order of there appearance in expression, So to evaluate expression no need to search next operation to

Does objective-c follow the order of operations (Bedmas)?

二次信任 提交于 2019-12-02 00:42:22
问题 I'm just wondering, because the app I built does a pretty long equation, and the result is a different than when it's done on an Excel spreadsheet, where I got the equation. The difference gets higher the higher the input numbers are. Here is the equation that I entered in xcode: 360 * num1 * num3 * (1 - powf(14.9 / num1, 0.286)) (num1 and num3 are the input numbers). Here is the Excel calculation: =360*R9*R11*(1-((R10/R9)^0.286)) ( R9 is equal to num1 , and R11 is equal to num3 and R10 is 14

Does objective-c follow the order of operations (Bedmas)?

自作多情 提交于 2019-12-01 21:10:49
I'm just wondering, because the app I built does a pretty long equation, and the result is a different than when it's done on an Excel spreadsheet, where I got the equation. The difference gets higher the higher the input numbers are. Here is the equation that I entered in xcode: 360 * num1 * num3 * (1 - powf(14.9 / num1, 0.286)) (num1 and num3 are the input numbers). Here is the Excel calculation: =360*R9*R11*(1-((R10/R9)^0.286)) ( R9 is equal to num1 , and R11 is equal to num3 and R10 is 14.9) I don't see a difference in the equations, but if you do, please point it out. My quess it one of

ValueError: math domain error - Quadratic Equation (Python)

隐身守侯 提交于 2019-12-01 18:40:38
I'm very new to python programming and to this site. I'm currently working on a problem and can't seem to understand the error. import math # Problem number 5. A5 = 5 B5 = 0 C5 = 6.5 # Root1 x9 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) # Root2 x10 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) # Print solution print() print('Problem #5') print('Root 1: ',x9) print('Root 2: ',x10) I get this after i run it: x9 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) ValueError: math domain error I did the problem on paper and got an answer for both... If you got an answer, it must have been a complex number

php calculate formula in string [duplicate]

帅比萌擦擦* 提交于 2019-12-01 13:55:27
This question already has an answer here: How to evaluate formula passed as string in PHP? 2 answers So I have formula as string $comm = "(a x 5% - 2%)"; I want it to be $comm = $a * 5/100 * (1-2/100); How can I do this in php? Stuart Wakefield To do this the right way, reliably and safely, from scratch, you will need to perform: Lexical analysis, this involves pattern matching the input with tokens: (a x 5% - 2%) would become something like the following chain of tokens: openparen variable multiply integer percent minus integer percent closeparen Syntax analysis, this involves taking those

php calculate formula in string [duplicate]

微笑、不失礼 提交于 2019-12-01 13:20:00
问题 This question already has answers here : How to evaluate formula passed as string in PHP? (2 answers) Closed 6 years ago . So I have formula as string $comm = "(a x 5% - 2%)"; I want it to be $comm = $a * 5/100 * (1-2/100); How can I do this in php? 回答1: To do this the right way, reliably and safely, from scratch, you will need to perform: Lexical analysis, this involves pattern matching the input with tokens: (a x 5% - 2%) would become something like the following chain of tokens: openparen

How to calculate an equation in a string, python

白昼怎懂夜的黑 提交于 2019-12-01 12:39:16
问题 So i have a variable that is function = '(2*1)+3' how would i get it out of string form and claculate the answer? i tried using float() int(float()) but im not sure if thats for numbers only or not. 回答1: I've written this a couple times, and every time it seems that I lose the code... A very simple (and "safe") calculator can be created using ast : import ast import operator _OP_MAP = { ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, ast.Div: operator.div, ast.Invert: