VB.Net expression solver
-
I want to find some solution that can solve expression like this (98.83*(a1^3))-(89127*a1)-53480000 = 0 a1 ^ 3 = cos(a1) / (279 ^ 2) - 0.30293 I want to know value of a1 - The expression have a1 variable. - a1 can has more than one time in expression. - a1 can in left side and right side. I searched by uses keywords "expression solver" then I found many solutions but they aren't match my requirements many solution can find result of expression e.g 2 ^ 5 + (300 * 4) by use stack,prefix,postfix but I not found a solution that can find variable value. if you have any solution even it isn't use vb.net please help me. or may be you suggest me to use other keywords for search actually I don't know what a keyword i should use because my English skill isn't well.
-
I want to find some solution that can solve expression like this (98.83*(a1^3))-(89127*a1)-53480000 = 0 a1 ^ 3 = cos(a1) / (279 ^ 2) - 0.30293 I want to know value of a1 - The expression have a1 variable. - a1 can has more than one time in expression. - a1 can in left side and right side. I searched by uses keywords "expression solver" then I found many solutions but they aren't match my requirements many solution can find result of expression e.g 2 ^ 5 + (300 * 4) by use stack,prefix,postfix but I not found a solution that can find variable value. if you have any solution even it isn't use vb.net please help me. or may be you suggest me to use other keywords for search actually I don't know what a keyword i should use because my English skill isn't well.
Hi, seems to me you need two things: 1. some code that evaluates an expression such as
y = (98.83*(a1^3))-(89127*a1)-53480000
ory = a1 ^ 3 - cos(a1) / (279 ^ 2) + 0.30293
for a specific value of a1 2. some code that finds the zeroes of y(a1), i.e. those values of a1 for which y effectively becomes zero. You can do 1. the lazy way by editing it into a source file, i.e. make a specific program. Or you need a parser + expression evaluator, which have been handled in several CP articles. You can do 2. using a simple algorithm, I would suggest "Newton-Raphson" which basically says: for a given approximation x to the solution, x - y(x)/y'(x) is a better approximation. Here y' is the derivative, which you can obtain in two ways: - you could come up with its analytical form and add it to the source code as suchl or you could do it symbolically by writing a parser + derivative generator, I don't recall having seen one on CP yet. - and you could approximate y'(x) by calculating y(x) and y(x+dx) and setting y'(x)=(y(x+dx)-y(x))/dx which may be a good enough approximation for small dx. Warning: if you come up with an arbitrary expression in a1, there could be zero, one, two, or any number of solutions. Since iterative approaches need an initial guess, they tend to converge (at best) to one or a few of the solutions, there is no easy way to find all solutions. Warning2: Newton-Raphson may not converge at all, if your initial guess is far away from a real solution but close to a local minimum/maximum, it may just move and stay there. Warning3: you will need defensive programming to protect yourself against overflow, underflow, zero divide, and non-convergence. There are some web sites that solve simple equations for you, and even tell you how they do it. I don't remember having seen solutions for trig equations. quadratics[^] Newton[^] :)Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a questi
-
Hi, seems to me you need two things: 1. some code that evaluates an expression such as
y = (98.83*(a1^3))-(89127*a1)-53480000
ory = a1 ^ 3 - cos(a1) / (279 ^ 2) + 0.30293
for a specific value of a1 2. some code that finds the zeroes of y(a1), i.e. those values of a1 for which y effectively becomes zero. You can do 1. the lazy way by editing it into a source file, i.e. make a specific program. Or you need a parser + expression evaluator, which have been handled in several CP articles. You can do 2. using a simple algorithm, I would suggest "Newton-Raphson" which basically says: for a given approximation x to the solution, x - y(x)/y'(x) is a better approximation. Here y' is the derivative, which you can obtain in two ways: - you could come up with its analytical form and add it to the source code as suchl or you could do it symbolically by writing a parser + derivative generator, I don't recall having seen one on CP yet. - and you could approximate y'(x) by calculating y(x) and y(x+dx) and setting y'(x)=(y(x+dx)-y(x))/dx which may be a good enough approximation for small dx. Warning: if you come up with an arbitrary expression in a1, there could be zero, one, two, or any number of solutions. Since iterative approaches need an initial guess, they tend to converge (at best) to one or a few of the solutions, there is no easy way to find all solutions. Warning2: Newton-Raphson may not converge at all, if your initial guess is far away from a real solution but close to a local minimum/maximum, it may just move and stay there. Warning3: you will need defensive programming to protect yourself against overflow, underflow, zero divide, and non-convergence. There are some web sites that solve simple equations for you, and even tell you how they do it. I don't remember having seen solutions for trig equations. quadratics[^] Newton[^] :)Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a questi
-
you're welcome. :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.