Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Javascript find intersections given two functions

I am trying today to solve for the coordinates where functions intersect. I am using the nerdarmer library right now, but it only returns only one solution out of all the possible solutions. For example, I want the code below to print -1, 0, 1 but it only outputs 0. Another example is if I want to find intersections between y = 0 and sin(x), I want the output to be ..., (-2pi, 0), (-pi, 0), (pi, 0), (2pi, 0), (3pi, 0), ...

intersect("x^3", "x")
function intersect(f1, f2){
    var x = nerdamer.solve('f1', 'f2');
    console.log(x.toString());  
}

Is there any way to get all the possible solutions?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You've misunderstood the syntax of nerdamer.solve

The first argument is the formula or equation. The second argument is the variable to solve for. If the first argument is not an equation, it is assumed to be equal 0. In your case x^3=0. which only has the solution 0.

If you want to intersect the equations you will need to set them equal to each other in the first argument. And in the second argument just specify x. (or change it to suit your needs if required).

intersect("x^3", "x")
function intersect(f1, f2){
    var x = nerdamer.solve(f1+"="+f2, "x");
    console.log(x.toString());  //outputs [0,1,-1]
}

Edit:

In your example you also directly put the strings "f1" and "f2" into the solve function which seems to just solve f=0;

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda