Encuentra la normal en un punto dado de la curva

Dada una curva [y = x(A – x)] , la tarea es encontrar la normal en un punto dado (x, y) en esa curva, donde A es un número entero y x, y también cualquier número entero.

Ejemplos:  

Input: A = 2, x = 2, y = 0
Output: 2y = x - 2
Since y = x(2 - x)
      y = 2x - x^2 differentiate it with respect to x
      dy/dx = 2 - 2x  put x = 2, y = 0 in this equation
      dy/dx = 2 - 2* 2 = -2
      equation  => (Y - 0 ) = ((-1/-2))*( Y - 2)
                => 2y = x -2

Input: A = 3, x = 4, y = 5
Output: Not possible
Point is not on that curve 

Enfoque: Primero necesitamos encontrar que el punto dado está en esa curva o no si el punto está en esa curva entonces:  

  1. Necesitamos diferenciar esa ecuación en ese punto. No pienses demasiado en la diferenciación de esta ecuación si analizas y encuentras que dy/dx siempre se convierte en A – 2x.
  2. Ponga x, y en dy/dx.
  3. La ecuación de la normalidad es Y – y = -(1/( dy/dx )) * (X – x).

A continuación se muestra la implementación del enfoque anterior: 
 

C++

// C++ program for find curve
// at given point
#include <bits/stdc++.h>
using namespace std;
 
// function for find normal
void findNormal(int A, int x, int y)
{
    // differentiate given equation
    int dif = A - x * 2;
 
    // check that point on the curve or not
    if (y == (2 * x - x * x)) {
 
        // if differentiate is negative
        if (dif < 0)
            cout << 0 - dif << "y = "
                 << "x" << (0 - x) + (y * dif);
 
        else if (dif > 0)
 
            // differentiate is positive
            cout << dif << "y = "
                 << "-x+" << x + dif * y;
 
        // differentiate  is zero
        else
            cout << "x = " << x;
    }
 
    // other wise normal not found
    else
        cout << "Not possible";
}
 
// Driver code
int main()
{
    // declare variable
    int A = 2, x = 2, y = 0;
 
    // call function findNormal
    findNormal(A, x, y);
    return 0;
}

Java

// Java program for find curve
// at given point
 
import java.io.*;
 
class GFG {
 
// function for find normal
static void findNormal(int A, int x, int y)
{
    // differentiate given equation
    int dif = A - x * 2;
 
    // check that point on the curve or not
    if (y == (2 * x - x * x)) {
 
        // if differentiate is negative
        if (dif < 0)
            System.out.print( (0 - dif) + "y = "
                + "x" +((0 - x) + (y * dif)));
 
        else if (dif > 0)
 
            // differentiate is positive
            System.out.print( dif + "y = "
                + "-x+" + (x + dif * y));
 
        // differentiate is zero
        else
            System.out.print( "x = " +x);
    }
 
    // other wise normal not found
    else
        System.out.println( "Not possible");
}
 
       // Driver code
    public static void main (String[] args) {
        // declare variable
    int A = 2, x = 2, y = 0;
 
    // call function findNormal
    findNormal(A, x, y);;
    }
}
// This Code is contributed by inder_verma..

Python3

# Python 3 program for find curve
# at given point
 
# function for find normal
def findNormal(A, x, y):
     
    # differentiate given equation
    dif = A - x * 2
 
    # check that point on the curve or not
    if (y == (2 * x - x * x)):
         
        # if differentiate is negative
        if (dif < 0):
            print(0 - dif, "y =", "x",
                 (0 - x) + (y * dif))
 
        elif (dif > 0):
             
            # differentiate is positive
            print(dif, "y =", "- x +",
                        x + dif * y)
 
        # differentiate is zero
        else:
            print("x =", x)
 
    # other wise normal not found
    else:
        print("Not possible")
 
# Driver code
if __name__ == '__main__':
     
    # declare variable
    A = 2
    x = 2
    y = 0
 
    # call function findNormal
    findNormal(A, x, y)
     
# This code is contributed By
# Surendra_Gangwar

C#

// C# program for find curve
// at given point
using System;
 
class GFG
{
     
// function for find normal
static void findNormal(int A,
                       int x, int y)
{
    // differentiate given equation
    int dif = A - x * 2;
 
    // check that point on
    // the curve or not
    if (y == (2 * x - x * x))
    {
 
        // if differentiate is negative
        if (dif < 0)
            Console.Write((0 - dif) + "y = " +
                   "x" + ((0 - x) + (y * dif)));
 
        else if (dif > 0)
 
            // differentiate is positive
            Console.Write(dif + "y = " +
                          "-x + " + (x + dif * y));
 
        // differentiate is zero
        else
            Console.Write("x = " + x);
    }
 
    // other wise normal not found
    else
        Console.WriteLine("Not possible");
}
 
// Driver code
static public void Main ()
{
    // declare variable
    int A = 2, x = 2, y = 0;
     
    // call function findNormal
    findNormal(A, x, y);
}
}
 
// This code is contributed by ajit

PHP

<?php
// PHP program for find curve
// at given point
 
// function for find normal
function findNormal($A, $x, $y)
{
    // differentiate given equation
    $dif = $A - $x * 2;
 
    // check that point on the
    // curve or not
    if ($y == (2 * $x - $x * $x))
    {
 
        // if differentiate is negative
        if ($dif < 0)
            echo (0 - $dif), "y = ",
                 "x" , (0 - $x) + ($y * $dif);
 
        else if ($dif > 0)
 
            // differentiate is positive
            echo $dif , "y = ",
                 "-x+" ,( $x + $dif * $y);
 
        // differentiate is zero
        else
            echo "x = " , $x;
    }
 
    // other wise normal not found
    else
        echo "Not possible";
}
 
// Driver code
 
// declare variable
$A = 2;
$x = 2;
$y = 0;
 
// call function findNormal
findNormal($A, $x, $y);
 
// This code is contributed by ajit
?>

Javascript

<script>
    // Javascript program for find curve at given point
     
    // function for find normal
    function findNormal(A, x, y)
    {
        // differentiate given equation
        let dif = A - x * 2;
 
        // check that point on
        // the curve or not
        if (y == (2 * x - x * x))
        {
 
            // if differentiate is negative
            if (dif < 0)
                document.write((0 - dif) + "y = " +
                       "x" + ((0 - x) + (y * dif)));
 
            else if (dif > 0)
 
                // differentiate is positive
                document.write(dif + "y = " +
                              "-x + " + (x + dif * y));
 
            // differentiate is zero
            else
                document.write("x = " + x);
        }
 
        // other wise normal not found
        else
            document.write("Not possible");
    }
     
    // declare variable
    let A = 2, x = 2, y = 0;
       
    // call function findNormal
    findNormal(A, x, y);
     
</script>
Producción: 

2y = x-2

 

Complejidad de tiempo: O (1), ya que no estamos usando ningún bucle.

Espacio auxiliar: O (1), ya que no estamos usando ningún espacio adicional.

Publicación traducida automáticamente

Artículo escrito por Rajput-Ji y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *