Tuesday, June 28, 2011

Application of thermodynamics in electrical engineering

Thermodynamics-
Thermodynamics is the study of energy conversion between heat and mechanical work, and subsequently the macroscopic variables such as temperature, volume and pressure. Thermodynamics is the branch of science or physics that studies various forms of energies and their conversion from one form to the other like electrical energy to mechanical energy, heat to electrical, chemical to mechanical, wind to electrical etc.

Historically, thermodynamics developed out of a need to increase the efficiency of early steam engines, particularly through the work of French physicist Nicolas Léonard Sadi Carnot (1824) who believed that engine efficiency was the key that could help France win the Napoleonic Wars. The first to give a concise definition of the subject was Scottish physicist William Thomson who in 1854 stated that:
Thermo-dynamics is the subject of the relation of heat to forces acting between contiguous parts of bodies, and the relation of heat to electrical agency.
Introduction-
The starting point for most thermodynamic considerations are the laws of thermodynamics, which postulate that energy can be exchanged between physical systems as heat or work. They also postulate the existence of a quantity named entropy, which can be defined for any isolated system that is in thermodynamic equilibrium.[8]
In thermodynamics, interactions between large ensembles of objects are studied and categorized. Central to this are the concepts of system and surroundings. A system is composed of particles, whose average motions define its properties, which in turn are related to one another through equations of state. Properties can be combined to express internal energy and thermodynamic potentials, which are useful for determining conditions for equilibrium and spontaneous processes.
With these tools, thermodynamics can be used to describe how systems respond to changes in their environment. This can be applied to a wide variety of topics in science and engineering, such as engines, phase transitions, chemical reactions, transport phenomena, and even black holes. The results of thermodynamics are essential for other fields of physics and for chemistry, chemical engineering, aerospace engineering, mechanical engineering, cell biology, biomedical engineering, materials science, and economics, to name a few.



Application of thermodynamics in electrical engineering-
1.Temperature measurement using NTC thermistors
2. Thermal considerations in using semiconductorsUse of heat sinks. Use of forced air.
3. Use of LM339 temperature sensitive diode, design of gain and offset circuitry to interface with analog to digital converter spanning range of 0.0 to 5.0 Volts, use of 4051 analog multiplexer under control of printer port to make up to eight measurements.
4. Running NTC thermistor in self heat mode to detect air movement and as fluid detector.
1. Temperature measurement using NTC thermistors
One of the easiest ways to measure temperature is to use a Wheatstone bridge (see drawing below). In a normal operation of the bridge, R3 is a variable resistor or a potentiometer. We will zero the bridge at 25°C using the potentiometer installed at R3 position. Next we will record the voltage versus temperature reading of the bridge. You will find that this is very linear, especially in the range of 0°C to 70°C. In this manner the output voltage would be a good indicator of temperature.
R 1 / R3 = R2 / Rt Þ condition of bridge being in balance @ 25°C
Where:
R1 = 250W, R2 =1000 W, R3 = 2500W, Rt = 10,000W.
The bridge voltage in circuit diagram (1) is now easily calculated using the formula below:
Vb = [ R3 / (R1 + R3) ] - [ Rt / (R2 + Rt) ] Vs eqn 3
Where:
1. Vs = Source Voltage = 7.55 volt DC Max
2. Vb = Bridge Voltage
Now: using the equation 3 (eqn 3) and the resistance versus temperature curve for NTC thermistor we can accurately predict the voltage at any temperature or vice versa.
This is very accurate and repeatable since the bridge aids linearize the NTC effect.
As an example:
(EX) Predict the voltage drop at temperature of 40°C
(A) At 40°C R t = 5282Ω, from Ametherm curves.
Using eqn 3, Vb = í[2500/(2500+250)] - [ 5282/(5282 + 1000)]ý (7.55v) = 0.5154
Refer to chart #1: T= 39°C Þ 0.519V and T= 38°C = 0.482V
Interpolating to the tenth of °C we will have (0.519) - (0.482) / 10 =0.0037
Therefore if we subtract 0.519-0.0037 = 0.5153 =38.9°C
Although our target was for 40°C, this was done to illustrate the effect of selecting a part, which has a tolerance of ± 2.2°C.

Calender program in C++

#include
using namespace std;
#include "stdlib.h"
void main ()

{
int year=1;
int yearstart=0;
int century=0;
int monthstart=0;
int endofweek=0;
int monthdays[]= {31,28,31,30,31,30,31,31,30,31,30,31};
int dayon[]= {1,1,1,1,1,1,1,1,1,1,1,1};
int month;
int currentyear;
int currentmonth;
int daysincalendaryearpriortocalendarmonth;
int daysinwholeyearssince1800;
int totalnumdays;
int daysinmonth;
int numblankdays=0;
int day;
int start;
int startday;


cout<<"Enter a year between 1800 & 2100 for the calendar you wish to produce"<>year;

if (year<1800 || year>2100)
cout<<"not a valid year"<>month;

if (month<0 || month>12)
cout<<"not a valid month"<
if (month ==1)
cout<<" january,"<<" "< if (month ==2)
cout<<" february,"<<" "< if (month ==3)
cout<<" march,"<<" "< if (month ==4)
cout<<" april,"<<" "< if (month ==5)
cout<<" may,"<<" "< if (month ==6)
cout<<" june,"<<" "< if (month ==7)
cout<<" july,"<<" "< if (month ==8)
cout<<" august,"<<" "< if (month ==9)
cout<<" september,"<<" "< if (month ==10)
cout<<" october,"<<" "< if (month ==11)
cout<<" november,"<<" "< if (month ==12)
cout<<" december,"<<" "<
cout<<"Sun"<<" "<<"Mon"<<" "<<"Tue"<<" "<<"Wed"<<" "<<"Thu"<<" "<<"Fri"<<" "<<"Sat"<
if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
daysinmonth=31;

if (month==4 || month==6 || month==9 || month==11)
daysinmonth=30;

if (month==2 & ((year % 400==0) || (year %4==0 && year % 100 !=0)))
daysinmonth=29;

if (month==2 & ((year % 400!=0) || (year %4!=0 && year % 100 ==0)))
daysinmonth=28;

//find start day

// steps 4-7 get total number of days algorithm
//step 4
while (currentyear {
//step 5
if ((year % 400==0) || (year %4==0 && year % 100 !=0))

daysinwholeyearssince1800 += 366;
else
daysinwholeyearssince1800 += 365;

Saturday, June 25, 2011



                                         

Assignment

Object oriented programming


Que-1-
Abstract class's can have a constructor, but you cannot access it through the object, since you cannot instantiate abstract class. To access the constructor create a sub class and extend the abstract class which is having the constructor. Example public abstract class AbstractExample { public AbstractExample(){ System.out.println("In AbstractExample()"); } } public class Test extends AbstractExample{ public static void main(String args[]){ Test obj=new Test(); } } If interface & abstract class have same methods and those methods contain no implementation, which one would you prefer? Obviously one should ideally go for an interface, as we can only extend one class.
Because abstract classes should never be instantiated, it is important to correctly define their constructors. It is also important to ensure that the functionality of your abstract class is correct and easily extended. If you define a protected constructor in an abstract class, the base class can perform initialization tasks when instances of a derived class are created. An internal constructor prevents the abstract class from being used as the base class of types that are not in the same assembly as the abstract class. Constructors with public or protected internal visibility are for types that can be instantiated. Abstract types can never be instantiated.
Que-2-
#include<conio.h>
#include<iostream.h>

#include<stdlib.h>


int main()
{

    int *ptr,i,n;
    clrscr();

    cout<<"Enter the no of elements:";
    Cin<<&n;

    ptr=(int *)malloc(sizeof(int)*n);
    if(ptr==NULL)

    {
        Cout<<"Not enough memory";

        exit(1);
    }

    for(i=0; i<n; i++)
    {

        cout<<"Enter  element : "<<i+1;
        cin<<&ptr[i];

    }
    cout<<"Array in original order\n";

    for(i=0; i<n; i++)
    {

        Cout<<"\n"<<ptr[i]);
    }

    cout<<"Array in reverse order\n";
    for(i=n-1; i>=0; i--)

    {
        Cout<<ptr[i]);

    }
    getch();

    return 0;
}


Que-3-
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int search_name(const string find_name[], const string in_name, int size1);
// Function to search for an inputted student name in the name[] array

int main()
{
               int size, *test1, *test2, *test3, score1, score2, score3, choice2;
               char choice, dummy;
               string *name, student, find_student;
               ifstream infile;
               ofstream outfile;

               cout << "hello\n";

               infile.open("scores.txt");
               if (infile.fail())
               {
                               cout << "Cannot open data file\nProgram halted\n\n";
                               exit(1);
               }

                               infile >> size;

                               test1 = new int[size];
                               test2 = new int[size];
                               test3 = new int[size];
                               name = new string[size];

                               for (int i = 0; i < size; i++)
                               {
                                              infile >> student >> score1 >> score2 >> score3;
                                              name[i] = student;
                                              test1[i] = score1;
                                              test2[i] = score2;
                                              test3[i] = score3;
                               }

               do
               {
                               system("cls");
                               cout << "Welcome to Test Score 2000\n\n\n"
                                               << "Please choose from the following:\n\n"
                                              << "A.  Display all student scores for a single test\n"
                                              << "B.  Display all scores and an average for a single student\n"
                                              << "C.  Display class average for each test along with the highest and lowest score\n"
                                              << "Q.  End Program\n\n"
                                              << "<=SELECTION=> ";
                               cin >> choice;
                               choice = toupper(choice);

                               switch (choice)
                               {
                                              case 'A':
                                                             {
                                                                            do
                                                                            {
                                                                                            system("cls");
                                                                                            cout << "Please input which test scores you would like to view - 1, 2, or 3.\n"
                                                                                                            << "Input 0 to return to main menu ==> ";
                                                                                            cin >> choice2;
              
                                                                                            switch (choice2)
                                                                                            {
                                                                                                           case 1:
                                                                                                                          {
                                                                                                                                         
cout << "\nTest " << choice2 << endl
                                                                                                                                                         << "========================================\n";
                                                                                                                                         
for (int i = 0; i < size; i++)
                                                                                                                                                        
{
                                                                                                                                                                       
cout << name[i] << "\t\t" << test1[i] << endl << endl;
                                             
                                                                                                           }
                                                                                                                                         
cout << "\n\nHit Enter to continue....";
                                                                                                                                          cin.ignore(100,'\n');
                                                                                                                                          cin.get(dummy);

break;
}
                                                                           
case 2:
                                                             {
                                                                                                                                         
cout << "\nTest " << choice2 << endl
                                                                                                                                                          << "========================================\n";


                                                                                                                                         
for (int i = 0; i < size; i++)
                                                                                                                                          {
                                                                                                                                                         cout << name[i] << "\t\t" << test2[i] << endl << endl;
                                                                                                                                          }

                                                                                                                                         
cout << "\n\nHit Enter to continue....";
                                                                                                                                          cin.ignore(100,'\n');
                                                                                                                                          cin.get(dummy);
                                             
                               break;
                                                                                                                          }
              
                                                                                                          
case 3:
                                                                                                           {
               cout << "\nTest " << choice2 << endl
                                                                                                                                                          << "========================================\n";
               for (int i = 0; i < size; i++)
                                                                                                                                          {
                                                                                                                                                         cout << name[i] << "\t\t" << test3[i] << endl << endl;
                                                                                                                                          }
               cout << "\n\nHit Enter to continue....";
                                                                                                                                          cin.ignore(100,'\n');
                                                                                                                                          cin.get(dummy);
                               break;
                                                                                                                          }

                               case 0:
               break;
              
               default:
                                                                                            {
               cout << "\nIncorrect input, please try again!\n";
               out << "\n\nHit Enter to continue....";
                                                                                                                          cin.ignore(100,'\n');
               cin.get(dummy);
                                                                                                                          }
                                                                                            }
                                                                                           
                                                                            } while (choice2 != 0);
                                                             }
                                                             break;
                                             
                                              case 'B':
                                                             {
                                                                            do
                                                                            {
                                                                                            system("cls");
                                                                                            int i;
               cout << "Please choose from the following students or input QQQ to return:\n\n";

               for (int num = 0; num < size; num++)
                                              {
               cout << name[num] << endl;
                                                                                            }
               cout << "\n==> ";
                               cin >> find_student;
                               i = search_name(name, find_student, size);
                                                                           
                                                                                            if (i < 0)
                               cout << "Name not found, please try again!\n";
                                                                                                           else
                                                                                            {
                               cout << "\nStudent\tTest 1\tTest 2\tTest 3\tAverage\n"
                                                                                                                           << "======================================="
                                                                                                                           << endl << name[i] << "\t" << test1[i] << "\t" << test2[i]
                                                                                                                            << "\t" << test3[i] << "\t" << ((test1[i] + test2[i] + test3[i]) / 3) << endl << endl;
                                                                                            }
                                                                            cout << "\n\nHit Enter to continue....";
                                                                            cin.ignore(100,'\n');
                                                                            cin.get(dummy);
                                                                            } while (find_student != "QQQ" || find_student != "qqq");
                                                             }
                                                             break;

                                              case 'C':
                                                             {
                                                                            system("cls");
                                                                            int average1 = 0, average2 = 0, average3 = 0, hinum1, lownum1, hinum2, lownum2, hinum3, lownum3, max1 = 0, max2 = 0, max3 = 0,
                                                                                            min1 = 100, min2 = 100, min3 = 100;
                                                                            for (int i = 0; i < size; i++)
                                                                            {
                                                                                            average1 += test1[i];
                                                                                            average2 += test2[i];
                                                                                            average3 += test3[i];
                                                                                            hinum1 = test1[i];
                                                                                            hinum2 = test2[i];
                                                                                            hinum3 = test3[i];
                                                                                            lownum1 = test1[i];
                                                                                            lownum2 = test2[i];
                                                                                            lownum3 = test3[i];

                                                                                            if (hinum1 > max1)
                                                                                                           max1 = hinum1;
                                                                                            if (hinum2 > max2)
                                                                                                           max2 =hinum2;
                                                                                            if (hinum3 > max3)
                                                                                                           max3 = hinum3;
                                                                                            if (lownum1 < min1)
                                                                                                           min1 = lownum1;
                                                                                            if (lownum2 < min2)
                                                                                                           min2 = lownum2;
                                                                                            if (lownum3 < min3)
                                                                                                           min3 = lownum3;
                                                                            }

                                                                            cout << "\nTest\tAverage\t\tHigh Score\tLow Score\n"
                                                                                             << "=================================================\n"
                                                                                             << "1\t" << (average1 / size) << "\t\t" << max1 << "\t\t" << min1 << endl
                                                                                             << "2\t" << (average2 / size) << "\t\t" << max2 << "\t\t" << min2 << endl
                                                                                             << "3\t" << (average3 / size) << "\t\t" << max3 << "\t\t" << min3 << endl << endl;
                                                             }
                                                             cout << "\n\nHit Enter to continue....";
                                                             cin.ignore(100,'\n');
                                                             cin.get(dummy);
                                                             break;
                               }
               }while (choice != 'Q');

               return 0;
}

int search_name(const string find_name[], const string in_name, int size1)
{
               int index = 0, not_found = -1;

               while (in_name != find_name[index] && index <= size1)
                               index++;

               if (in_name != find_name[index] && index > size1)
                               return not_found;
               else
                               return index;
}

Que-4-
Many programs have little need for memory management; they use a fixed amount of memory, or simply consume it until they exit. The best that can be done for such programs is to stay out of their way. Other programs, including most C++ programs, are much less deterministic, and their performance can be profoundly affected by the memory management policy they run under. Unfortunately, the memory management facilities provided by many system vendors have failed to keep pace with growth in program size and dynamic memory usage.
Because C++ code is naturally organized by class, a common response to this failure is to overload member operator new for individual classes. In addition to being tedious to implement and maintain, however, this piece-meal approach can actually hurt performance in large systems. For example, applied to a tree-node class, it forces nodes of each tree to share pages with nodes of other (probably unrelated) trees, rather than with related data. Furthermore, it tends to fragment memory by keeping large, mostly empty blocks dedicated to each class. The result can be a quick new/delete cycle that accidentally causes virtual memory thrashing. At best, the approach interferes with system-wide tuning efforts.
For ex.-
  class Heap {
   protected:
    virtual ~Heap();
   public:
    virtual void* allocate(size_t) = 0;
    static Heap& whatHeap(void*);
  };
(The static member function whatHeap(void*) is discussed later.) Heap's abstract interface is simple enough. Given a global Heap pointer, the regular global operator new can use it:

  extern Heap* __global_heap;

  inline void*
  operator new(size_t sz)
    { return ::__global_heap->allocate(sz); }
Inline dispatching makes it fast. It's general too; we can use the Heap interface to implement the placement operator new, providing access to any private heap:
  inline void*
  operator new(size_t size, Heap& heap
    { return heap.allocate(size); }
What kind of implementations might we define for the Heap interface? Of course the first must be a general purpose memory allocator, class HeapAny. (HeapAny is the memory manager described in detail in the second half of this article.) The global heap pointer, used by the regular operator new defined above, is initialized to refer to an instance of class HeapAny:
  extern class HeapAny __THE_global_heap;
  Heap* __global_heap = &__THE_global_heap;
Users, too, can instantiate class HeapAny to make a private heap:
  HeapAny& myheap = *new HeapAny;
and allocate storage from it, using the placement operator new:
  MyType* mine = new(myheap) MyType;
As promised, deletion is the same as always:
  delete mine;
Now we have the basis for a memory management architecture. It seems that all we need to do is provide an appropriate implementation of class Heap for any policy we might want. As usual, life is not so simple.
Que-6-
Here are two possible solutions that define why How do the following two statements differ in operation?
cin>>c;
cin.get(c);

declare first and last to be quite large:
char first[256], last[256];
cin.getline(first, sizeof(first));
cin.getline(last, sizeof(last));
Or, in the Standard Template Library (STL) there is a string class that helps with this sitution a lot:
string first, last;
getline(cin,first);
getline(cin, last);