假设我们有一条曲线,例如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} y} {\ text {d} x} \ rgroup * \ lgroup Xx \ rgroup $$
#include<iostream> using namespace std; void getTangent(int A, int x, int y) { int differentiation = A - x * 2; if (y == (2 * x - x * x)) { if (differentiation < 0) cout << "y = " << differentiation << "x" << (x * differentiation) + (y); else if (differentiation > 0) cout << "y = " << differentiation << "x+" << -x * differentiation + y; else cout << "Not possible"; } } int main() { int A = 2, x = 2, y = 0; cout << "Equation of tangent is: "; getTangent(A, x, y); }
输出结果
Equation of tangent is: y = -2x-4