简体   繁体   English

二次导数

[英]Derivative of the quadratic

I have homework to create a Quadratic formula class. 我有功课来创建二次方公式类。 I have the parts figured out for the roots and the Discriminate. 我已经找到了根源和区分的部分。 However, the last part I'm having problems with : 但是,最后一部分我遇到了问题:

**must be able to compute the value of the first derivative of the quadratic at any specific point. **必须能够在任何特定点计算二次方的一阶导数的值。

Unfortunately I don't even know what that means, it has been decades since I've taken a calculus course. 不幸的是,我什至不知道这意味着什么,距离我学习微积分课程已有几十年了。 Here is my code so far. 到目前为止,这是我的代码。

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

Thank you SO MUCH for helping. 非常感谢您的帮助。 Rachel 雷切尔

To calculate the derivative at any point You need this formula: 要在任何时候计算导数,您需要以下公式:

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

Where d should be very small but not zero. d应该很小但不能为零。 This is numerical derivation. 这是数值推导。

Other way is to use the general formula for derivative of f(x)=ax^2+bx+c The derivative at any x is: 其他的方法是使用通式为的衍生物f(x)=ax^2+bx+c在任何的衍生物x是:

f'(x) = 2ax+b

Derivative is rate of increase of function at some point, have some fun with it :) 导数是函数在某点上的增长率,请尝试一下:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM