Jump to content




Solve for X function


  • You cannot reply to this topic
4 replies to this topic

#1 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 10 May 2017 - 05:42 PM

This function solves any algebraic equation where you need to solve for a single variable (x)

pastebin get bs4QNDyS solve

Syntax:
solve("2*x-4","4*x+3","x")
--First argument is the left part of the equation
--Second argument is the right part.
--Third is the name of the variable to do math with.
--This function supports adding functions like math.sqrt or math.sin

strsolve("2x(3-x) = 8x - math.sqrt(8)")
--First argument is a full equation
--Second argument can be a variable name, but defaults to "x"
--This too can have functions like math.sqrt

Give me some credit, or PM me, if you want to use this for your programs. Or don't. I won't find out...or eat you
This function might not be 100% accurate if you get irrational answers (off by a billionth or something), or is unsolvable. It does its best to detect that, though.

#2 apemanzilla

  • Members
  • 1,421 posts

Posted 11 May 2017 - 01:32 PM

Hmm....
Posted Image

Edited by apemanzilla, 11 May 2017 - 01:38 PM.


#3 Emma

  • Members
  • 216 posts
  • Locationtmpim

Posted 12 May 2017 - 03:35 AM

I broke it :)
Spoiler

Edit; very nice work tho, for not crafted functions specially designed to thwart your algorithm it works pretty well :)
Basically it doesn't like inflection points very much, at all

Edited by Incinirate, 12 May 2017 - 03:40 AM.


#4 Emma

  • Members
  • 216 posts
  • Locationtmpim

Posted 13 May 2017 - 03:22 AM

View Postapemanzilla, on 11 May 2017 - 01:32 PM, said:

Hmm....
Posted Image

@EldidiStroyrr also this happens bc the loadstring turns into -2^2=-4 which lua sees as -(2^2)=-4

Edited by Incinirate, 13 May 2017 - 03:22 AM.


#5 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 27 May 2017 - 12:14 AM

Shite. I wonder how I could fix it. How does my CASIO calculator do it...?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users