Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The figure below shows a frequently used electric circuit called a \"voltage div

ID: 3762874 • Letter: T

Question

The figure below shows a frequently used electric circuit called a "voltage divider". The input to the circuit is the voltage v_i. The output is the voltage v_0. The output of a voltage divider is proportional to the input, and the constant of proportionality is called the "gain" of the circuit. The voltage divider is represented by the equation where G is the gain and R_1 and R_2 are the resistances of the two resistors that comprise the voltage divider. Manufacturing variations cause the actual resistance values to deviate from the nominal values, as described in Exercise P8.8. In turn, variations in the resistance values cause variations in the values of the gain of the voltage divider. We calculate the nominal value of the gain using the nominal resistance values and the actual value of the gain using actual resistance values. Write a program that contains two classes, VoltageDivider and Resistor. The Resistor class is described in Exercise P8.8. The VoltageDivider class should have two instance variables that are objects of the Resistor class. Provide a single constructor that accepts two Resistor objects, nominal values for their resistances, and the resistor tolerance. The class should provide public methods to get the nominal and actual values of the voltage divider's gain. Write a main method for the program that demonstrates that the class works properly by displaying nominal and actual gain for ten voltage dividers each consisting of 5 percent resistors having nominal values R_1 = 250 Ohm and R_2 = 750 Ohm.

Explanation / Answer


//Resistor.java
public class Resistor
{
   //instance variable resistance nominal value
    private double resistance;
          
    //Constructor to set resistance
    public Resistor(double r)
    {
        resistance = r;
    }

    //Returns the resistance
    public double getResistance()
    {
        return resistance;
    }  
}


-------------------------------------

//VoltageDivider.java
import java.util.Random;
public class VoltageDivider
{
  
   //instance variables
   private double tolerance;
   //declare tow resistor objects
   private Resistor r1;
   private Resistor r2;
  
   //Craete an instance of random class
   private Random rand=new Random();
  
   //Constructor that sets two resistors and tolerance
   public VoltageDivider(Resistor r1, Resistor r2, double tolerance)
   {
       this.r1=r1;
       this.r2=r2;
       this.tolerance=tolerance;
   }
      
  
   //Returns nominal resistance of R1
   public double getNominalR1()
   {
       return r1.getResistance();
   }
  
   //Returns nominal resistance of R2
   public double getNominalR2()
   {
       return r2.getResistance();
   }
  
   //Returns actual resistance of R1
   public double getActualR1()
   {
       //Get a random value between 0.0 to 1.0
       double r=rand.nextDouble();      
       //calculate acutal value of resistance of given tolerance
       return r1.getResistance()*(1+(2*r-1)*(tolerance/100));
      
   }
  
   //Returns actual resistance of R2
   public double getActualR2()
   {
       double r=rand.nextDouble();      
       //calculate acutal value of resistance of given tolerance
       return r2.getResistance()*(1+(2*r-1)*(tolerance/100));       
   }
  
   //Returns the nomial gain of the resistores
   public double getNominalGain()
   {          
       return r2.getResistance()/(r1.getResistance()+r2.getResistance());       
   }
  
   //Returns the actual gain of the resistores
   public double getActualGain()
   {          
       return getActualR2()/(getActualR1()+getActualR2());       
   }
      
}

--------------------------------------------


/**The java program that sets two resistance objects
* and construct an object voltage divider with tolernace
* and print ten trials of actual values of the resistance */
//Driver.java
public class Driver
{
   public static void main(String[] args)
   {
      
       //Create two instance of Resitace objects
       Resistor r1=new Resistor(750);
       Resistor r2=new Resistor(250);
      
       //set toleracne to 5 percent
       double tolerance=5;
       //number of trials is 10
       int n=10;
      
       //Create an instance of VoltageDivider class with resisor and tolerace
       VoltageDivider vd=new VoltageDivider(r1, r2, tolerance);
      
       System.out.printf("%-10s%-10s%-10s ","R1act","R2act","Gain(%)");
       //print ten values of resistors acutal value of R1 and R2 and percenta of gain ,G
       for (int i = 0; i < n; i++)
       {          
           System.out.printf("%-10.2f%-10.2f%-10.2f ",
                   vd.getActualR1(),vd.getActualR2(),
                   vd.getActualGain());
       }
      
      
      
   }
}


---------------------------------

Sample output:

R1act     R2act     Gain(%)
741.71    257.84    0.25    
758.91    259.48    0.24    
715.77    250.51    0.25    
725.80    249.11    0.25    
743.87    238.36    0.25    
726.46    252.86    0.24    
762.54    258.22    0.25    
719.07    238.29    0.26    
720.21    260.89    0.24    
723.14    238.57    0.25    

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote