2

I'm trying to adapt some equations (implicit f(x,y)) in order to be able list the Y for corresponding X-Value.
The equations could be e.g. as follows:

y^2 = x^3 + 2x - 3xy
(X^2+y^2-1)^3-x^2y^3=0
X^3+y^3=3xy^2-x-1
X^3+y^2=6xy/sqrt(y/x)
cos(PI*Y) = cos(PI.X)


Below you can see the plotted equations:
enter image description here
Hint, I don't know, but maybe this can be helpful, the following applies:

Y^2 + X^2 =1  ==>  Y= sqrt(1-X^2)

The equations are to be adapt (substitution), so that they are expressed by X (not Y).
For y^2=x^3+2x-3xy by means of substitution results:

y1 = (-(-3x) - sqr((-3x)^2 - 4(-1)(x^3+2x)))/2*(-1)
y2 = (-(-3x) + sqr((-3x)^2 - 4(-1)(x^3+2x)))/2*(-1)


By means of adapted equations I will be able to vary X and get the corresponding Y.
See here the solution of Arkadiusz Raszeja-Solution for the equation y^2=x^3+2x-3xy

The solution of "Arkadiusz Raszeja" is for Quadratic equation, but I need an algorithm, so that e.g. all above equations can be solved.

var x,y;
for(var n=0; n<=10; n++) {
    x=n;
    y = (-(-3*x)-Math.sqrt(((-3*x)*(-3*x)) - 4*(-1)*((x*x*x)+2*x)))/(2*(-1));
    alert(y);
}

The above alert(y); will show for Y something like below list:

X= 1 ; Y=0.79
X=2 ; Y=1.58
X=3 ; Y=2.79
X=4 ; Y=4.39
X=5 ; Y=6.33
X=6 ; Y=8.57 
X=7 ; Y=11.12 
X=8 ; Y=13.92
X=9 ; Y=16.98
X=10 ; Y= 20.29


My question is how can I program an algorithm, which will adapt (solve) the equations like in above example?

(You can also use a JS library like math.js, but not a plot or graph library. The solution should be in javascript)
Thanks in advance.

Community
  • 1
  • 1
user3815508
  • 369
  • 4
  • 20
  • What is issue with using JavaScript at Question? – guest271314 Mar 28 '17 at 22:12
  • I agree, the problem would be almost the same in any programming langugage. Are you asking if there are any library that would do the job ? To me, this looks like formal calculus/symbolic calculus, and this is not what I call "a simple task" to program it. – LoneWanderer Mar 28 '17 at 22:14
  • I gave a look to this: http://mathjs.org/examples/algebra.js.html This contains basic stuff you may need. – LoneWanderer Mar 28 '17 at 22:17
  • For further reading, i would suggest : http://stackoverflow.com/questions/7540227/strategies-for-simplifying-math-expressions (mathjs.org algebra doc page redirects here ) (That was just my 2 min web research.) – LoneWanderer Mar 28 '17 at 22:21
  • Interesting question. @user3815508, I'd be intrigued to see what you done yourself thus far? Or are you literally at square 1, wondering how to begin? – fubar Mar 28 '17 at 22:27
  • @ guest271314 I mean the sloution should be in javascript :) @LoneWanderer: I know it's not easy, but doable! For example, see the Plotter: https://www.desmos.com/calculator/pi5ofejgt0 He's probably using a similar algorithm. – user3815508 Mar 28 '17 at 22:28
  • @fubar: I've been working on a plotter since January. Almost all parts are finished, only to be made "Implicit function". With the algorithm I have not yet started, because I still have no idea :) – user3815508 Mar 28 '17 at 22:43
  • @user3815508 - no worries. I'm not sure where to start at the moment either, but I'll follow the question with intrigue and see if anyone has any bright ideas. – fubar Mar 28 '17 at 22:45
  • source code of the site is obfuscated. But have you considered that maybe the developper only passes the equation via JSON to a dedicated server that has all the logic implemented in another language? the page then would only display the points according to a return JSON with a given sampling. see for instance : `\frac{1}{x^2+y}+y^3-2xy+x^{\frac{5}{y}}=0` (you can copy paste this into the equation box – LoneWanderer Mar 28 '17 at 22:47
  • Maybe! In any case, I will try tomorrow, maybe I have, or someone else a brilliant idea :) – user3815508 Mar 28 '17 at 22:57
  • According to some stuff grabbed in source code the plotter you mentionned (`"math/features/polynomialcoefficients","math/features/extractconditions","math/features/bounddomain","math/features/derivative","math/features/substitute","math/features/solve","math/features/analyze","math/features/analyzeFourFunction","math/features/analyzeScientific",`) I conclude that they have defined a full math symbolic evalutation library that checks for simple forms first and then goes for complex resolution second. Is it open source ? I can't tell tonight – LoneWanderer Mar 28 '17 at 23:01
  • Hello my friend! Do you have some max and min x'es to be checked? If so I can write few "numeric algotithms" to solve all you equasions. Now I have some time :) – Arkadiusz Raszeja Mar 30 '17 at 09:58
  • @Arkadiusz Raszeja: Hello, sorry, but I have seen your comment just now. E.g. for equation: (x^2+y^2-1)^3-x^2y^3=0 some x-y-values are as follows: { y0=1.24, x01=0.5, x02=-0.5; y1=1, x11=-1, x12=1; y2=0.5, x21=-1.14, x22=1.14; y3=0, x31=-1, x32=1; y4=-0.5, x41=-0.62, x42=0.62; y5=-1, x5=0; } Or see here https://www.desmos.com/calculator/pi5ofejgt0 to plot an equation. – user3815508 Mar 31 '17 at 08:53

3 Answers3

1

Hopefully I'm understanding your question correctly. Would nerdamer help? It can help solve algebraically up to a 3rd degree polynomial. The buildFunction method can be called to get a JS function which can be used for graphing. I use it in a somewhat similar manner on the project website in combination with function-plot.js

var solutions = nerdamer('y^2=x^3+2x-3x*y').solveFor('y');
//You'll get back two solutions since it's quadratic wrt to y
console.log(solutions.toString());
//You can then parse the solutions to native javascript function
var f = nerdamer(solutions[0]).buildFunction();
console.log(f.toString());

/* Evaluate */
var solutions = nerdamer('y^3*x^2=(x^2+y^2-1)').solveFor('y');
console.log(solutions.toString());
//You can then parse the solutions again to native javascript function
var f = nerdamer(solutions[0]);
var points = {};
for(var i=1; i<10; i++)
    points[i] = f.evaluate({x: i}).text();

console.log(points)
<script src="http://nerdamer.com/js/nerdamer.core.js"></script>
<script src="http://nerdamer.com/js/Algebra.js"></script>
<script src="http://nerdamer.com/js/Calculus.js"></script>
<script src="http://nerdamer.com/js/Solve.js"></script>

You could always just evaluate. This is slower than a pure JS function but it might be what you need. You'll have to probably use a try catch block for division by zero.

jiggzson
  • 515
  • 1
  • 4
  • 13
  • Thanks for your answer! See the Heart-Graphic: (x^2+y^2-1)-x^2*y^3=0 or x^3+y^2=(6xy/sqrt(xy)). Do have an idea how can I adapt (solve) such polynomials? because there is Y-Exponent greater than 2 or there is used an square by Y. – user3815508 Mar 29 '17 at 07:28
  • I'm not sure I understand the question. Are trying to find out if the max degree of one is greater than the other? – jiggzson Mar 29 '17 at 11:45
  • Are trying ... other? --> NO. I mean, if you have a complicated equation, then it will be failed. For the equation y^2=x^3+2x-3x*y is ok! But try to solve this equation y^3*x^2=(x^2+y^2-1) or these (x^2+y^2-1)-x^2*y^3=0. Sadly, then you will see that it fails (see above the equations or theirs charts). – user3815508 Mar 29 '17 at 13:09
  • I see what you mean. The problem lies with the buildFunction. It doesn't know what to do when it has complex values. I'm guessing you want to graph those. – jiggzson Mar 29 '17 at 13:14
  • Yes right. At the end I will plot (graph) it. Therefore all parameters must be expressed only by means of X. – user3815508 Mar 29 '17 at 13:30
  • I've updated the answer to use the evaluate method. The buildMethod has a bug and I'll track it down but for now this might be what you need. – jiggzson Mar 29 '17 at 13:43
  • I think it still doesn't work properly. E.g. for X=1 or X=-1 I expect Y=0 or for X=0.5; Y=1.24. See the plotted chart of 'y^3*x^2=(x^2+y^2-1)'. See here: https://jsfiddle.net/87ykocs8/5/ – user3815508 Mar 29 '17 at 15:24
  • Are you trying to implement your own plotter? [Function-plot.js](http://maurizzzio.github.io/function-plot/) already does this. Maybe you can look through the source code for hints if you're trying to implement your own. Or just use the existing library. See this [jsbin](http://jsbin.com/viyipayeyu/edit?html,js,output) – jiggzson Mar 31 '17 at 01:24
  • Yes. "Or just use the existing library." --> NO. I know this library. But I couldn't understand how he had done this. Thank you for your references and efforts. – user3815508 Mar 31 '17 at 08:39
1

I'd like to point out that this problem cannot be solved exactly in general. The cited solution for the quadratic case (y^2) can be extended to the cubic case and quartic case (there are a general complicated solutions). But there is a math theorem (from Galois theory) that states that there is no general solution for the quintic equation (and so on). In your case, maximum degree is 3, so you can use the cubic equation from wikipedia. For the heart graphic write: x^2*y^3 - y^2 -(x^2-1) = 0 and treat x as constant. For the sqrt case, get rid of it. Square both sides of equation, isolate y and you end up with a quartic equation on y, that you can solve using wikipedia's quartic equation knowledge.

Anyway, if you don't have a very strong reason to do this, don't do it, as the computer can solve this numerically for you. Standard approach is to calculate this implicitly, as in the plots you made.

I hope this helps.

Alex
  • 1,252
  • 7
  • 21
-1

There ia a possible solution for the general quintic equation, when you addapt the solutionmethod from Cardano for the general cubic equation and the solutionmethod from Ferrari for the general quartic equation.