二次型的导数

时间:2015-02-24 14:05:52

标签: java formula equation quadratic derivative

我有作业来创建一个二次公式类。我找到了根源和判别的部分。但是,最后一部分我遇到了问题:

**必须能够计算任何特定点的二次方程的一阶导数的值。

不幸的是,我甚至不知道这意味着什么,自从我学习了微积分课以来已经有几十年了。到目前为止,这是我的代码。

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

非常感谢您的帮助。 拉结

1 个答案:

答案 0 :(得分:2)

要计算任何点的导数你需要这个公式:

f'(x) = (f(x+d)-f(x))/d

d应该非常小而不是零。这是数字推导。

其他方式是使用f(x)=ax^2+bx+c的导数的通用公式 任何x的衍生物是:

f'(x) = 2ax+b

导数是某个时刻功能增加的速度,有一些乐趣:)