Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect expression evaluation #105

Open
cesar-ioc opened this issue Mar 23, 2020 · 1 comment
Open

Incorrect expression evaluation #105

cesar-ioc opened this issue Mar 23, 2020 · 1 comment

Comments

@cesar-ioc
Copy link

I'm trying to evaluate the following expression:

sin x - (0.02449*x^3)-(1.67049*x)+(64.85606+(0.33683*x^2))+(sin (2*x))

Using this code:

String equation = "sin x - (0.02449*x^3)-(1.67049*x)+(64.85606+(0.33683*x^2))+(sin (2*x))";

Expression exp = new ExpressionBuilder(equation)
					.variables("x")
					.build()
					.setVariable("x", 1);

System.out.println(exp.evaluate()); // prints 0.5364612580927792

But according to WolframAlpha the correct result is 65.2487
Here is the direct link to WolframAlpha

I'm using version 0.4.8

@shuvamc019
Copy link
Contributor

Using parentheses in the first sine function should give you the correct value.
"sin(x) - (0.02449x^3)-(1.67049x)+(64.85606+(0.33683x^2))+(sin (2x))"

The way that you have it written is slightly ambiguous and the parser is interpreting it as
"sin(x - (0.02449x^3)-(1.67049x)+(64.85606+(0.33683x^2))+(sin (2x)))"
where the entire expression is an argument of the sine function.

Using parentheses will clear up the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants