[英]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.