equation

Solving a simultaneous equation through code

回眸只為那壹抹淺笑 提交于 2019-11-27 16:14:19
问题 This seems like an incredibly simple and silly question to ask, but everything I've found about it has been too complex for me to understand. I have these two very basic simultaneous equations: X = 2x + 2z Y = z - x Given that I know both X and Y, how would I go about finding x and z? It's very easy to do it by hand, but I have no idea how this would be done in code. 回答1: This seems like an incredibly simple and silly question to ask Not at all. This is a very good question, and it has

Algebra equation parser for java

送分小仙女□ 提交于 2019-11-27 14:00:41
I need a library to be able to parse an equation an give me the result giving the inputs. For example something like this: String equation = "x + y + z"; Map<String, Integer> vars = new HashMap<String, Integer>(); vars.add("x", 2); vars.add("y", 1), vars.add("z", 3); EquationSolver solver = new EquationSolver(equation, vars); int result = solver.getResult(); System.out.println("result: " + result); And evaluates to: 6 Is there any kind of library for java that can do that for me? Thanks You could make use of Java 1.6's scripting capabilities: import javax.script.*; import java.util.*; public

How can I solve equations in Python? [closed]

柔情痞子 提交于 2019-11-27 11:57:04
Let's say I have an equation: 2x + 6 = 12 With algebra we can see that x = 3 . How can I make a program in Python that can solve for x ? I'm new to programming, and I looked at eval() and exec() but I can't figure out how to make them do what I want. I do not want to use external libraries (e.g. SAGE), I want to do this in just plain Python. How about SymPy ? Their solver looks like what you need. Have a look at their source code if you want to build the library yourself… There are two ways to approach this problem: numerically and symbolically. To solve it numerically, you have to first

User input string equation, converted to an int answer C#

人走茶凉 提交于 2019-11-27 04:53:59
问题 Int answer; String equation = Console.ReadLine(); Console.writeLine("your equation is {0}", equation); How do I convert the string into a solvable equation? 回答1: Take a look at NCalc - Mathematical Expressions Evaluator for .NET It'll let you do this sort of thing: var inputString = "2 + 3 * 5"; Expression e = new Expression(inputString); var result = e.Evaluate(); 回答2: eval.js: package BLUEPIXY { class Math { static public function Evaluate(exp : String) : double { return eval(exp); } } }

Safely evaluate simple string equation

不羁的心 提交于 2019-11-26 21:25:51
问题 I'm writing a program in which an equation is inputted as a string, then evaluated. So far, I've come up with this: test_24_string = str(input("Enter your answer: ")) test_24 = eval(test_24_string) I need both a string version of this equation and an evaluated version. However, eval is a very dangerous function. Using int() doesn't work, though, because it's an equation. Is there a Python function that will evaluate a mathematical expression from a string, as if inputting a number? 回答1: One

Is it possible to get several solutions to an arbitrary equation in Matlab?

纵然是瞬间 提交于 2019-11-26 21:22:24
问题 Suppose I have a function f = @(x) myfun(x) ; I can use fzero to get the solution closest to a given x0 , but can I get all solutions in a specific area, for instance: -5 < x < 5 ? I.e. Is it possible to get a solution similar to the result of roots, but for non-polynomials? 回答1: Yes, you can. There's a nice submission on the file exchange that allows you to do exactly that. It works by approximating your curve by a Chebychev polynomial, and then finding all real roots of that polynomial. If

Math equations on the web

女生的网名这么多〃 提交于 2019-11-26 18:55:10
问题 How can I render Math equations on the web? I am already familiar with LaTeX's Math mode. 回答1: It turns out this is a bit of a pain. You can use MathML, but browser support is still iffy. If you are starting with latex you've got a few options for converting to html, but they'll all typically end up rendering the actual equations to images and inlining those. Nothings all that pretty (unless you resort to pdf or something). What's best will depend a bit on what sort of content, how many

How can I solve equations in Python? [closed]

偶尔善良 提交于 2019-11-26 18:08:09
问题 Let's say I have an equation: 2x + 6 = 12 With algebra we can see that x = 3 . How can I make a program in Python that can solve for x ? I'm new to programming, and I looked at eval() and exec() but I can't figure out how to make them do what I want. I do not want to use external libraries (e.g. SAGE), I want to do this in just plain Python. 回答1: How about SymPy? Their solver looks like what you need. Have a look at their source code if you want to build the library yourself… 回答2: There are

Algebra equation parser for java

北城余情 提交于 2019-11-26 16:34:11
问题 I need a library to be able to parse an equation an give me the result giving the inputs. For example something like this: String equation = "x + y + z"; Map<String, Integer> vars = new HashMap<String, Integer>(); vars.add("x", 2); vars.add("y", 1), vars.add("z", 3); EquationSolver solver = new EquationSolver(equation, vars); int result = solver.getResult(); System.out.println("result: " + result); And evaluates to: 6 Is there any kind of library for java that can do that for me? Thanks 回答1:

How to Solve Equations with java?

天涯浪子 提交于 2019-11-26 14:17:17
问题 I have three equations like the following ones: x + y + z = 100; x + y - z = 50; x - y - z = 10; How can I find the values of x, y, and z with Java? String equation1="x+y+z=100;"; String equation2="x+y-z=50;"; String equation3="x-y-z=10;"; int[] SolveEquations(equation1,equation2,equation3) { // to do // how to do? } Do you have any possible solutions or other common frameworks? 回答1: You can use determinant to calculate values of x y and z. Logic can be found out here http://www.intmath.com