假设我们有一条类似y = x(A-x)的曲线,我们必须找到该曲线上给定点(x,y)的法线。这里A是整数,x和y也是整数。
为了解决这个问题,我们检查给定点是否在曲线上,如果是,则找到该曲线的微分,因此将是-
$$\ frac {\ text {d} y} {\ text {d} x} = A-2x $$
然后将x和y放入dy / dx,然后使用该方程式找到法线-
$$Yy =-\ lgroup \ frac {\ text {d} x} {\ text {d} y} \ rgroup * \ lgroup Xx \ rgroup $$
#include<iostream>
using namespace std;
void getNormal(int A, int x, int y) {
int differentiation = A - x * 2;
if (y == (2 * x - x * x)) {
if (differentiation < 0)
cout << 0 - differentiation << "y = " << "x" << (0 - x) + (y * differentiation);
else if (differentiation > 0)
cout << differentiation << "y = " << "-x+" << x + differentiation * y;
else
cout << "x = " << x;
}
else
cout << "Not possible";
}
int main() {
int A = 5, x = 2, y = 0;
cout << "Equation of normal is: ";
getNormal(A, x, y);
}输出结果
Equation of normal is: 1y = -x+2