Algorithm which adapt (solve) the complex equations ( implicit function f(x,y) )

前端 未结 3 2010
傲寒
傲寒 2021-01-22 03:50

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 =         


        
3条回答
  •  忘掉有多难
    2021-01-22 04:11

    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)
    
    
    
    

    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.

提交回复
热议问题