[英]Derivative of the quadratic
我有功课来创建二次方公式类。 我已经找到了根源和区分的部分。 但是,最后一部分我遇到了问题:
**必须能够在任何特定点计算二次方的一阶导数的值。
不幸的是,我什至不知道这意味着什么,距离我学习微积分课程已有几十年了。 到目前为止,这是我的代码。
import static java.lang.Math.*;//math.pow
public class Quadratic
{
//instance variables
private double a;
private double b;
private double c;
private double discriminant = b * b - 4 * a * c;
//constructors
//default constructor
public Quadratic ()
{
//just put default numbers in y(x) = x^2 + x + 1
a = 1;
b = 1;
c = 1;
}
//constructor for abc
public Quadratic(double a, double b, double c)
{
this.a = a;
this.b = b;
this.c = c;
}
//users should be able to change / alter - gets and sets ...
///////////
//SETTERS//
///////////
//set a
public void setValue_a(double a)
{
this.a = a;
}
//set b
public void setValue_b(double b)
{
this.b = b;
}
//set c
public void setValue_c(double c)
{
this.c = c;
}
//set a b and c
public void setValue(double a, double b, double c)
{
this.a = a;
this.b = b;
this.c = c;
}
///////////
//GETTERS//
///////////
//return a
public double get_a()
{
return a;
}
//return b
public double get_b()
{
return b;
}
//return c
public double get_c()
{
return c;
}
public double getDescrim()
{
return (b * b - 4 * a * c);
}
//Returns a String detailing whether there are complex or real roots
public String isReal()
{
if (discriminant >= 1)
{
return "There are real roots.";
}
else
{
return "There are complex roots";
}
}
//Is the descriminant negative
public String isNegative()
{
if (discriminant < 0)
{
return "The descriminant is negative";
}
else
{
return "The descriminant is positive";
}
}
public double getRootX()
{
return (-b + Math.sqrt(b*b - 4*a*c)) / (2 * a);
}
public double getRootY()
{
return (-b - Math.sqrt(b*b - 4*a*c))/ (2*a);
}
//roots = (-b +- sqrt(b^2 - 4ac))/2a
public double returnRootsX()
{
System.out.println(-b);
return (-b + Math.sqrt(b*b - 4*a*c)) / (2 * a);
}
public double returnRootsY()
{
return (-b - Math.sqrt(b*b - 4*a*c))/ (2*a);
}
//toString...Print to String;
public String toString()
{
String str = "The Quadratic Formula Data:\na: " + a + "\nb: " + b + "\nc: " + c + "\n" + isReal() + "\nRoot 1: " + getRootX() + "\nRoot 2: " + getRootY()+
"\n" + isNegative() + "\n" + getDescrim();
return str;
}
}//end class
非常感谢您的帮助。 雷切尔
要在任何时候计算导数,您需要以下公式:
f'(x) = (f(x+d)-f(x))/d
d
应该很小但不能为零。 这是数值推导。
其他的方法是使用通式为的衍生物f(x)=ax^2+bx+c
在任何的衍生物x
是:
f'(x) = 2ax+b
导数是函数在某点上的增长率,请尝试一下:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.