1

I am building a WP8 app it is solving numerical analysis problems. For one step i need to parse entered function but I dont have any knowledge about parsing and I tried something else

I have a stackpanel with mathematical components (Sin(x),Cos(x),Tan(x),+,-,*...)

when user click any component

For example first Sin(x) then + and then Cos(x)

string yazılıdenklem =""; int xdegeri=Convert.ToInt32(Xtxt.Text);

private void Sin_Tapped(object sender, TappedRoutedEventArgs e)
    {

        yazılıdenklem=yazılıdenklem+"Math.Sin("+xdegeri.ToString()+")";

    }

 private void artı_Tapped(object sender, TappedRoutedEventArgs e)
    {

        yazılıdenklem = yazılıdenklem + "+";
    }
 private void Cos_Tapped(object sender, TappedRoutedEventArgs e)
    {

        yazılıdenklem = yazılıdenklem + "Math.Cos(" + xdegeri.ToString() + ")";
    }

End of choosing I having a string equation like : "Math.Sin(3)+Math.Cos(3)" can i transform this equation to any numerical form ? Can I get any result from this string eq. ? Thank you

OknAkdgn
  • 51
  • 9

1 Answers1

2

bcParser.NET is a safe eval() function to evaluate math formulas. bcParser.NET is a Math Parser Library for the .NET Platform. bcParser.NET parses and evaluates mathematical expressions given as strings at runtime.

MathParser.SetExpression("sin(3)+cos(3)");
double value = MathParser.getValueAsDouble();
Monitor
  • 342
  • 2
  • 13
  • I added bcParser dll and wrote my code like this `MathParser parser = new MathParser(); parser.SetVariable("sin(3)+cos(3)", 15); double result = parser.ValueAsDouble; Denklem.Text = result.ToString();` but it is not working it is saying `Additional information: sin(3)+cos(3) is not a valid variable name.` – OknAkdgn Jul 14 '14 at 17:13
  • It is worked there is just one mistake in code `parser.SetVariable` not working use parser.Expression instead. Thank you @JeevaMahendran – OknAkdgn Jul 14 '14 at 17:20
  • but bcParser is not free – OknAkdgn Jul 14 '14 at 23:05