Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB.Net expression solver

VB.Net expression solver

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structuresbusinessregex
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krirk
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • K Krirk

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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 or y = 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

      K 1 Reply Last reply
      0
      • L Luc Pattyn

        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 or y = 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

        K Offline
        K Offline
        Krirk
        wrote on last edited by
        #3

        Thank you for your reply.It can help me a lot.

        L 1 Reply Last reply
        0
        • K Krirk

          Thank you for your reply.It can help me a lot.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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.


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups