Pregunta

I have an equation like this:

a = b(x-c)^d-e(x-f)^g 

a, b, c, d, e, f and g are known numbers that changes. x is unknown.

I would like to find x. How can I do this with C# code?

¿Fue útil?

Solución

a, b, c, d, e, f and g are known numbers that changes

So, do you know values and want to find values of x that fit the equation? Or are you trying to come up with an equation in terms of those variables? I'm pretty sure there's no closed-form equation for x based on that formula.

If you know the values of a,b,c,d,e,f,and g, then you can use a root-finding algorithm to find values of x.

First reorder your equation to

b(x-c)^d-e(x-f)^g - a = 0

Then use a root-finding algorithm.

The Newton Method and Secant Method are fairly easy to codify, and you can probably find existing C# implementations online.

Otros consejos

NCalc could do what you need.

The link is here: http://ncalc.codeplex.com/.

Example functionality

  Expression e = new Expression("2 + 3 * 5");
  Debug.Assert(17 == e.Evaluate());
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top