equation

Solving a Variable Equation defined by the User

给你一囗甜甜゛ 提交于 2019-12-04 08:38:39
问题 Answers in C, Python, C++ or Javascript would be very much appreciated. I've read a few books, done all the examples. Now I'd like to write a simple program. But, I already ran into the following roadblock: My intention is to take an equation from the user and save it in a variable, For example: -3*X+4 or pow(2,(sin(cos(x))/5)) > [In valid C Math syntax] And then calculate the given expression for a certain X-Value. Something like this: printf("%g", UserFunction(3.2)) // Input 3.2 for X in

How to solve a set of Linear equations?

时光毁灭记忆、已成空白 提交于 2019-12-04 06:35:41
问题 I need to solve a system of linear equations: aQ + bP = c dQ + eP = f Where: a ~ N(100;10) b ~ N(-1;0.1) c ~ N(10;1) d ~ N(10;0.1) e ~ N(100;10) f ~ N(10;0.1) So far I have written: a <- rnorm(100, mean=100, sd=10) b <- rnorm(100, mean=-1, sd=0.1) c <- rnorm(100, mean=10, sd=1) d <- rnorm(100, mean=10, sd=0.1) e <- rnorm(100, mean=100, sd=10) f <- rnorm(100, mean=10, sd=0.1) P <- vector() Q <- vector() for (i in 1:100) { coefs <- matrix(c(a[i],d[i],b[i],e[i]),2,2) ys <- array(c(c,f),2) solve

Solve Quadratic Equation in C++

陌路散爱 提交于 2019-12-04 05:17:34
I am trying to write a function in C++ that solves for X using the quadratic equation. This is what I have written initially, which seems to work as long as there are no complex numbers for an answer: float solution1 = (float)(-1.0 * b) + (sqrt((b * b) - (4 * a * c))); solution1 = solution1 / (2*a); cout << "Solution 1: " << solution1 << endl; float solution2 = (float)(-b) - (sqrt((b*b) - (4 * a * c))); solution2 = solution2 / (2*a); cout << "Solution 2: " << solution2; If, for example, I use the equation: x^2 - x - 6, I get the solution 3, -2 correctly. My question is how would I account for

Mathjax not working in Ajax based web page

点点圈 提交于 2019-12-04 05:09:24
I'm using Mathjax to display equations in a web application done in PHP/Ajax. The equations are rendered correctly when the page is loaded first.In the same page, when user clicks a button, an ajax code works to fetch some data from database and display it on the same page.But, there the equations are not displaying correctly, instead the latex code is shown as such.But if i refresh the page, then the equations are rendered correctly.How can i solve this issue? Davide Cervone See the MathJax documentation on modifying math on the page for details. 来源: https://stackoverflow.com/questions

Find roots of a function a x^n + bx - c = 0 where n isn't an integer with Numpy?

放肆的年华 提交于 2019-12-04 04:23:31
I'm writing a program in python and in it I need to find the roots of a function that is: a*x^n + b*x -c = 0 where a and b are constants that are calculated earlier in the program but there are several thousand of them. I need to repeat this equation twice for all values of a and b once with n = 77/27 and once with n = 3 . How can i do this in python? I checked numpy.roots(p) and that would work for when n = 3 I think. But for n = 77/27 how would I be able to do that? I think your beast choice is scipy.optimize.brentq() : def f(x, n, a, b, c): return a * x**n + b * x - c print scipy.optimize

ValueError: math domain error - Quadratic Equation (Python)

核能气质少年 提交于 2019-12-04 04:02:10
问题 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

Equations for 2 variable Linear Regression

a 夏天 提交于 2019-12-03 22:17:10
We are using a programming language that does not have a linear regression function in it. We have already implemented a single variable linear equation: y = Ax + B and have simply calculated the A and B coefficents from the data using a solution similar to this Stack Overflow answer . I know this problem gets geometrically harder as variables are added, but for our purposes, we only need to add one more: z = Ax + By + C Does anyone have the closed form equations, or code in any language that can solve for A, B and C given an array of x, y, and z's? so you have three linear equations k = aX1 +

How to solve Linear Diophantine equations in programming?

谁说胖子不能爱 提交于 2019-12-03 14:04:49
问题 I have read about Linear Diophantine equations such as ax+by=c are called diophantine equations and give an integer solution only if gcd(a,b) divides c . These equations are of great importance in programming contests. I was just searching the Internet, when I came across this problem. I think its a variation of diophantine equations. Problem : I have two persons,Person X and Person Y both are standing in the middle of a rope. Person X can jump either A or B units to the left or right in one

JavaScript equation solver library

时光总嘲笑我的痴心妄想 提交于 2019-12-03 11:21:31
Is there a JavaScript library or function that will solve equations for variables? Such as 9 = 3 + x and solve for x. But it should also solve more advanced equations that include sine, cosine, and tangent. You can approximate the solution by doing what excel calls "Goal Seek" - testing values for x until both sides of the equation approximately match. You can do this by splitting the equation by the "=" sign, replacing each occurence of x with a value, eval ing both sides, and determining if the difference falls below a certain threshold. While relatively simple, there are flaws to this

Convert Expression from a Textbox to Math Expression in Code Behind [duplicate]

*爱你&永不变心* 提交于 2019-12-03 10:04:05
Possible Duplicate: I need a fast runtime expression parser How do I make it that when someone types in x*y^z in a textbox on my page to calculate that equation in the code behind and get the result? .NET does not have a built-in function for evaluating arbitrary strings. However, an open source .NET library named NCalc does. NCalc is a mathematical expressions evaluator in .NET. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions. Greg Answer from operators as strings by user https://stackoverflow.com/users/1670022/matt-crouch :