Tuesday, 10 March 2015

Matrices in Java

Matrices in Java

Over the past two weeks I've been working on a series of Java classes which model different types of number matrices that I've been learning about in Advanced Higher Maths in school. This blog serves as a summary of my work and a description of all the code I've written. All the code snippets that follow are hosted by GitHub and all the formulas were made with a website called www.codecogs.com

Matrix Class



The class I've written above models a general Matrix, it has methods to model the most basic of matrix operations.  Lets take a closer look at the code (since my Javadoc comments aren't exactly descriptive!).

Instance variables. (lines  3, 4, 5)
The class has three instance variables; int rows, int columns and double[][] theMatrix. rows is a simple variable holds the number of rows in an instance of the class matrix. It is initialized in the constructor. columns is similar to  to rows, it is also initialized in the constructor and holds the number of columns in an instance of the class Matrix. I have made both of these the int type because they are both whole numbers. In fact I could have even made them unsigned int because the number of rows and columns should not be negative. rows and columns have their own getter methods but no setter. This is because there should be no reason to change the number of rows and columns once an instance of Matrix is created. rows and columns are used in methods to iterate though a matrix using for-loops. The last instance variable is theMatrix and it is of type double[][] which means that it is a two-dimensional array which holds components of type double. When I first wrote the program I made theMatrix an int array, but this caused me to run into problems later on when some of the methods involved fractions.

Constructor -  Matrix(int setRows, int setColumns) (lines 6-26)
The Matrix class has only one constructor and it takes two arguments, both of type int, setRows and setColumns. The constructor simply sets the values of the instance variables rows and columns to their corresponding arguments. Next  the constructor initializes the theMatrix variable. To do this it calls a method createMatrix() and puts its return value into the theMatrix variable.

createMatrix() (lines 17- 24)
This method takes no arguments. It uses the instance variables rows and columns, by calling their getter methods, to create a new two dimensional double[][] array. The array is then returned.

getter methods (lines 26 - 37)
There are getter methods for each of the instance variables; getMatrix() for theMatrix, getRows() for rows and getColumns() for columns. I haven't written Javadoc for these as they are very straight forward. Each method returns the value of the instance variable it corresponds to. Getters are important in java because they promote data hiding.

setAMatrixValue(int posX, int posY, double val) (lines 38 - 48)
This is a setter method for setting the value of one component of the array referenced by theMatrix. It simply uses the integer arguments posX and posY to access the right component and then sets the component equal to the double argument val.

getAMatrixValue(int Xpos, int Ypos) (lines 53 - 62)
This is a getter function which returns a value of a component of the array referenced by theMatrix which is defined by the arguments Xpos and Ypos.

multiplyMatrix(double aFactor) (lines 63 - 76)
This method uses two for-loops to iterate though all the components of the array referenced by theMatrix. It is able to iterate though every component without going out of bounds of the array by calling the getRows() and getColumns() methods in the Boolean-section of the for-loops. Once it reaches a component it simply sets the component equal to whatever it was before multiplied by the argument aFactor. It then moves to the next component. When all components have been visited the method is finished.

multiplyMatrix(double factor, double[][] mat) (lines 77 -93)
This method overloads the method multiplyMatrix(double aFactor) and allows the object that called the method to choose what matrix it is multiplying out. Apart from that it works the same way, using two for-loops to iterate though the matrix, mat, at each component it multiplies its value by the argument factor.

printAVal(int Xpos, int Ypos) (lines 95 - 103)
This method simply uses the System.out.println(String) method to print the value of a component defined by the arguments Xpos and Ypos.

matrixToString(double[][] aMatrix) (lines 113 - 126)
This method iterates though the array referenced by aMatrix and uses System.out.println(String) to output each component.

The Matrix class as a whole can't do very many complex things. This is because from a programming perspective I don't know what dimensions the matrix will be so I need to have more specific subclasses of Matrix before things start getting interesting.

SquareMatrix Class


The SquareMatrix class is a subclass of (extends) the Matrix class. Therefore it inherits all the methods which I have just specified. It is also able to do things which are exclusive to matrices which are square. For example it is able to transpose.

instance variables (line 3)
The SquareMatrix class does have one more instance variable of type integer. It is called order. The order of a square matrix is a measurement of how big it is, an order 2 square matrix would have 4 components, an order 3 matrix would have 9 components etc. Again, this could have been an unsigned int type since matrices do not have negative orders.  order also has a getter method of its own.

Constructor - SquareMatrix(int n) (lines 5- 14)
The constructor of SquareMatrix takes one argument of type int, n. The first thing it does is call the constructor of its superclass, Matrix. Passing the value n to  both of its arguments. This will create a Matrix object but since both the setRows and setColumns arguments are the same the array theMatrix will be square. Next it initializes the value of order to the argument n.

matrixTranspose(double [][] mat) (lines 15 - 31)
The transpose of a matrix is found by reflecting all the numbers in the leading edge.


The diagram above shows a matrix(A) and it's transpose(At).
The method takes one argument of type double[][] this corresponds to the matrix to be transposed. The first thing the method does is create a new double[][] array which has the same dimensions as the array referenced by theMatrix. However all the components are undefined at this point. This array is now referenced by the argument, mat. (line 22). Next, the method iterates though all the components of the array referenced by mat. (this is done with for-loops in the same way as previously) At every component it sets it equal to the return value of the getAMatrixValue(int, int) where the parameters are the opposite of the component location. We can think of the int variables declared in the for-loop header as co-ordinates of the components we are trying to access. This sets whatever value is in the component of location (x, y) to whatever component is in the array referenced by theMatrix with co-ordinate(y, x).
After each component has been written the method returns the array referenced by mat.

SquareMatrix doesn't have many methods right now but I've written it in such a way which will make it easy to add functionality as I continue to learn in school.

TwoByTwoMatrix Class



TwoByTwoMatrix is a subclass of (extends) SquareMatrix. So it inherits all the methods in the Matrix class and the SquareMatrix class. Since a square matrix of order two is quite a specific scenario I was able to code specifically to the components of the matrix. And since there is a set number of components in this kind of matrix I knew I wouldn't miss any out. This allowed me to program for much more complex operations.

Class Variables (line 3)
An identity matrix is specific to a particular square matrix. It is arranged such that only the value 1 exists along the leading edge and all the other values are 0.



The diagram above shows the identity matrix of a square matrix of order 2 (left)  and the identity matrix of a square matrix of order 3 (right).
Since the identity matrix is common to every instance of TwoByTwoMatrix then it can be made a class variable, hence given the static-type. Since the identity matrix is constant it can be made a constant variable, hence given the final-type. These types of variables are often written in block capitals, this is not a requirement its just good practice to do so to conform to common programming style.
The variable IDENTITY_MATRIX is of type double[][] and is initialized as soon as it is created. It is initialized to be equivalent to the matrix in the diagram above (left).

Constructor - TwoByTwoMatrix() (lines 5 - 11)
This constructor is very simple, it only calls the SquareMatrix() constructor with parameter 2. There are no variables to initialize and no methods to call.

determinant() (lines 68 -77)
The determinant of a matrix is a value which is used in other matrix calculations. In this program I will be using it to find the inverse matrix. The determinant of a square matrix of order 2 is found by multiplying the top left number and the bottom right number and then taking away the product of the top right number and the bottom left number. See diagram below, matrix(left) determinant(right).



the determinant() method first created a new double variable and then assigns it to the value created by the corresponding components in the formula. It uses the getAMatrixValue(int, int) to get the values stored in the components that correspond to a,b,c and d in the above equation. The determinant is then assigned to the variable determinant and returned by the method.


adjoint() (lines 78 -90)
The adjoint of a matrix is another piece of information which is used to calculate the inverse of that matrix. However, unlike the determinant, the adjoint represented as a matrix. To find the adjoint of a square matrix of order 2. You simply swap the top-left term and the bottom-right term and make the other two negative.
The adjoint() method creates a new double array with 4 components that are in a square shape. it then uses the getAMatrixValue(int,int) method to find out all the values that correspond to a,b,c and d on the above diagram and writes those values to the newly creates array referenced by adj in the order shown on the right. It then returns this matrix which is equivalent to the adjoint matrix of the array referenced by theMatrix.

doesInverseExist() (lines 34 - 50)
There are some matrix arrangements where no inverse exists, these kinds of matrices are referred to as singular. If the determinant of a matrix is equal to zero then it is singular and no inverse exists.
The method doesInverseExist() calls the determinant() method and if it's equal to 0 then the method will return false. If its not equal to zero then it will call the determinant() method again and if it's not equal to zero it will return true.

findInverse() (lines 14 - 33)
The inverse of a matrix is the matrix that when multiplied by the original matrix will produce the identity matrix for that order. It's rather like how (1/3)*(3) = 1 since 3 is the number and (1/3) is the inverse of 3. To find the inverse of the matrix you must first have the determinant of the matrix and the adjoint (or adjugate) of the matrix. I have written methods for both. The inverse of a matrix is equal to the adjoint matrix multiplied by (1/ the determinant).


The findInverse() method first needs to check if an inverse actually exists. It does this by evaluating the doesInverseExist() method in an if statement. If it evaluates to false then the method uses System.out.println(String) to tell the user that no inverse exists for the array referenced by theMatrix.
If it evaluates to true then the method will create a new double[][] array instance variable called inverseMatrix. Then, it will call the multiplyMatrix(int, double[][]) method passing the two arguments as (1 / determinant()) , (adjoint()). These correspond to the above formula. The return value that multiplyMatrix(int, double[])  produces is then assigned to the inverseMatrix local variable. Finally inverseMatrix is returned.

multiplyMatrices(double[][], double[][])
Multiplying two matrices together is not the same as multiplying an entire matrix by a factor. Therefore it requires a different method. Multiplying matrices together is done with the formula as follows:
The method multiplyMatrices(double[][], double[][]) first creates a new double[][] array of order 2. And then assigns each of its values to the corresponding components in the formula. The values a, b, c, d, e, f and g are found inside the arguments mat1 and mat2.



isOrthogonal(double[][])
Matrices are said to be orthogonal if their transverse multiplied by the original matrix is equal to the identity matrix for that order. the isOrthogonal(double[][]) method first creates a new double[][] array called trans. And, using the matrixTranspose(double[][]) method, it sets trans equal to the transpose of the array referenced by mat. Next, using the  multiplyMatrices(double[][], double[][]) method it evaluates if the returned product is equal to the identity matrix. The value of the identity matrix is stored in the array referenced by  IDENTITY_MATRIX declared at the beginning of the class. If the product is the identity matrix then the method returns true. If the product is not the identity matrix the method returns false.



ThreeByThreeMatrix Class


ThreeByThreeMatrix is a subclass of (extends) SquareMatrix. So it inherits all the methods in the Matrix class and the SquareMatrix class. Since ThreeByThreeMatrix also specifies the order of the square matrix it gets the same advantages as TwoByTwoMatrix in that I am now able to program for a specific circumstance.

Class Variables
Just like the TwoByTwoMatrix class square matrices of order three also have an identity matrix. And again it is declared static and final.

Constructor  - ThreeByThreeMatrix()
This constructor works exactly the same way as the constructor for TwoByTwoMatrix, except this time it passes 3 into the constructor of SquareMatrix instead of 2.

determinant()
To find the determinant of a square matrix of order 3 a more complex process is required than that of one with order 2.

In the above formula, the matrices enclosed in modulus operators signify the determinant of that matrix. Since I already have a method to calculate the determinant of a 2x2 matrix then I can use it to help calculate the determinant of this, bigger, matrix.
The determinant() method creates three instances of the TwoByTwoMatrix class and sets their values to the ones that correspond to the formula above. Once all the values have been set, the method calculates the determinant of each TwoByTwoMatrix. Then it returns whatever matrix value corresponds to a multiplied by the determinant of the first instance of TwoByTwoMatrix, minus whatever matrix value corresponds to b multiplied by the second instance of TwoByTwoMatrix, plus whatever value corresponds to c multiplied by the third instance of TwoByTwoMatrix.

findInverse()
This method works exactly the same way as the findInverse() method in the TwoByTwoMatrix class. Except, it is calling different determinant() and adjoint() methods. It is calling the ones within this class instead.

doesInverseExist()
Again, this works exactly the same way as it does in an instance of TwoByTwoMatrix.

adjoint()
The adjoint() method for the ThreeByThreeMatrix class is fairly complex. In maths at school we weren't actually given a formula for this, instead we used elementary row operations. But since this would be far more difficult to program I browsed the internet to find a more suitable solution.I found this page which illustrates a formulaic approach. Unfortunately, it is a little complicated. Below is my best attempt at a formula to define it.

Again, the modulus signs here mean the determinant of the matrix enclosed within them. So the adjoint of a square matrix of order three is made up of the determinant of nine square matrices of order 2 (center) with the signs on the right.
The adjoint() method is similar to the determiant() method in that it creates instances of the class TwoByTwoMatrix, assigns them values and then finds their determinant. Once it has found the determinant of each sub-matrix it then puts them into another double[][] array referenced by the variable detMat. Using two for-loops, each value in detMat is then multiplied by its corresponding sign in the matrix on the right and assigned into another double array referenced by the variable ans. ans is then returned.

By writing out all my thoughts about the classes that I've written there are a number of things that have been brought to my attention that I could improve on to make the program more consistent. Firstly, in most of the instances where I have used double[][] to reference a newly created matrix inside a method such as findInverse() or adjoint() I could have made these instances of an appropriate matrix class. The same can be said for identity matrices, they could be made an instance of an appropriate matrix class rather than a double[][] array. There even could have been a separate class all together just for identity matrices.
Another thing I could improve on is actually interacting with the program. When I was testing the program out I just used a class to create instances of the objects and call methods to check if they worked. I got all my feedback from the system-output window. A much better solution would be to become more familiar with the java.swing library to help me create an actual GUI to interact with the program.  These perhaps, are topics for another blog.

I liked this project because it not only challenged my knowledge of Java, but also my knowledge of maths. And with exams coming up soon I found it to be a very intuitive way to learn and memorize formula. I'm learning more about code everyday and I really enjoy being able to use it in a practical application such as this one.

Thanks for reading and until next time.



















Wednesday, 25 February 2015

Geometric Series in Java


Hi all.
I've just been using a website called www.compilejava.net to noodle around with some new Java that I've been learning during free periods at school. I was also revising geometric series for maths and decided to put the two together!

I came up with a programme which creates a class for handling geometric series and initialises a value for the first number in the series and the common ratio. Using knowledge from maths I was able to create a method within the class which assigns a value to each number in the series. The series being an array of integers.

Here is the code:

import java.lang.Math;

public class UI
{
  public static void main(String[] args)
  {
    GeometricSeries A = new GeometricSeries(1.0, 3.0);
    A.setGeometricSeries();
    A.printGeometricSeries();
   
  }
}

public class GeometricSeries
{
  private double[] intergerArray = new double[1000];
  private double firstTerm;
  private double commonRatio;
 
  public GeometricSeries(double a, double r)
  {
    this.firstTerm = a;
    this.commonRatio = r;
    intergerArray[0] = a;
  }
  public void setGeometricSeries()
  {
   for(int i = 1; i < 1000; i++)
   {
     if (intergerArray[i] == this.firstTerm)
     {}
     else
     {
     this.intergerArray[i] = (java.lang.Math.pow(((this.firstTerm * this.commonRatio)), (i - 1)));
     }
   }
   
  }
    public void printGeometricSeries()
    {
     for (int i = 1; i < 1000; i++)
        {
          System.out.println(this.intergerArray[i]);
        }
    }
   
  }

Just a quick programme to enforce my learning in both subjects. Nothing too fancy.
Thanks and until next time.

Monday, 5 January 2015

Building a Robotic Arm - Part 2

Building a Robotic Arm - Part 2

After a lot of trial and error I have decided to control the servos using a module that implements the PCA9685 chip. 
The board is in the post and is designed to control up to 12 servos, from an external power source. Communication between the board and the arduino will be done over I2C. I've chosen to use this board because it should lower the workload on the arduino and fix any power issues I've been having. Additionally it should also give me a chance to try using the I2C bus which I know I will be using in future projects. 

The electromagnet circuit is finished and working well. However I would like to increase the voltage across the magnet because its not quite as powerful as I would like it. Its wired up as follows 


The black and red wires are my 9V power source and the two blue wires protruding are the connections for the magnet. 

I have been working on the code for the photo-resistor and its calibration resistor and that is largely what the next post will be about. I'm still getting used to using interrupts in code and I'm learning all the time. 

Sorry this post is so short, I've been very busy in my personal life and haven't had much time for my projects of recent. Thanks and until next time.








Monday, 17 November 2014

Building a Robotic Arm

Building a Robotic Arm

Following the fun I had with Project Splendabot (http://goo.gl/pZrTXB). I decided to get into a more meaty robotics project. I want to create a robotic system that is capable of moving steel balls on a track from one place to another. Servo powered arms had always been attractive to me but were always just too expensive. I found that cheap 9g servos that are available to be shipped from china, coupled with a cheap electromagnet it should be able to move steel balls provided all goes well. I found a 3D printable frame for a 9g servo robotic arm on Thingiverse (http://goo.gl/B4tocR) it looked promising but the 3D printers we have at school are unable to produce this kind of mechanical accuracy. I got in touch with 3DPrintMan 3D printing solutions they agreed to print the product. The accuracy and the finish is fantastic! After a touch up with a rotary tool I was ready to test out the arm. 





I found the design had stability issues, so using meccano I modified some of the weak areas and it's now mechanically sound. 
Electronics 
The electromagnet is rated at 9V which which is not available from the arduino so instead the arduino will be switching a transistor on which will allow current to flow from a nine volt battery. After watching this video I started to understand how it would be arranged. 
I need a way for the arm to know when a ball is ready to be picked up, for this I will be using an LDR, the resistance of an LDR increases as the light level decreases. If I couple this with a variable resistor in a voltage divider circuit then I can change the value of the variable resistor to calibrate the background light level. When the LDR is covered the logic level should change which can be harnessed in arduino code. 
The next problem I encountered was power requirements.  As you may have guessed a little arduino didn't have quite enough juice to drive four servos and a switching circuit for the electromagnet and power the voltage divider. I had to modify an old 5V 2A DC charger to get the right amount of power.
Code
My plan for the arduino code is to use a hardware interrupt (great video on those here) to tell the servos to move to a specified location (using the servo.h library) once the arm is lined up the electromagnet circuit will turn on, the ball will be picked up and moved to another predesignated position. The position the ball will be moved to will not be changeable on-the-fly and the arm will have no idea of knowing if it has picked up a ball or not.
I have made a start on the coding for this and hope to have it finished by next week. Its easily the most complex arduino program I have written to date.




This will be a multi-part project but I hope to have another update out as soon as possible. Its been great to learn about the different areas vital to robotic design and I look forward to making the code work how I want it to. If you live in the UK and are looking tor a 3D printing service to give you an accurate product at reasonable prices I would encourage you to check out 3DPrintMan. 
http://www.3dprintman.co.uk/
Thanks and until next time.





Sunday, 12 October 2014

First circuit board design project - part 2

Part Two

After quite some time to get used to eagle and understand it a little better I've managed to revise the schematic from part one and also get started on the board layout.





Instead of laying out the pins in long rows like in the first schematic I've decided to instead put the pins in groups of three. You can see that on a nano breakout board the pins are arranged in groups as well. It's also much easier to find parts for in Eagle, which does in fact make a huge difference. I also realized that the board footprint for male pin headers is exactly the same as that for female headers. That one had me stumped for a while. I'm now also using an arduino pro mini template. This means I now have exact measurements for the dimensions of the pro mini, this will be very useful when it comes to laying out the board. I also changed all the LEDs resistors and caps to be the 0805 size. This is a common size used in board design and will be easy to find components for, unfortunately surface mount soldering is difficult at the best of times and this will make the components smaller and even harder to deal with. I also added an extra two A6 and A7 female headers, these are connected together in series. I added them because depending on which pro mini you are using, the analogue pins A7 and A6 may be in different locations. In the board layout below you can see the two different locations commonly used by the pins.



I made a start at laying out the board, I'm still learning and this draft has errors. I found it really interesting but also frustrating. Its so great this board project is actually coming together and if I can keep this momentum up I plan to actually have it manufactured and it will be for sale on tindie.com . If you haven't heard of tindie its a website where independent hardware developers can sell products. Check it out.



Anyway, that's all for this update. I've got more Eagle tutorials to watch! Thanks and until next time.

Thursday, 2 October 2014

First circuit board design project - part 1

Part One 

As an arduino enthusiast a particular arduino pro mini has caught my attention recently. For those that don't know what the pro mini is, it's a very small and typically low cost arduino. It is an attractive board to me since I like projects to be compact and yet still functional. However during the prototyping stages of a project using the pro mini can be very fiddly so I would like to create a pro mini expansion board. The board would not be unlike the expansion boards available for arduino nano. (see below)

As you can see the board isn't particularly complex so this will make a nice first design project for me. However I do plan on making this my own a little, for example the arduino pro mini does not have a USB to UART converter chip on board, I suppose you could blame this on the small form factor of the board. Instead, every time the user wishes to flash new code onto the board they must use a USB to UART converter board. Such can be seen below.


The chip used on this particular conversion board is the CP2102 by a company called Silicon Labs. There are also other chips which do this conversion function such as the FTDI FT232RL, which is built into my arduino nano or ATMELs very own ATmega16U2 which is used on the original arduino boards. Another example is the CH340G which is occasionally used in Chinese "knock off" arduino boards this also does the same conversion job no hastle.


The board pictured above is manufactured by Haoyu electronics, after some rooting around online I was able to acquire a schematic for that particular board. This was useful since many of these CP2102 converters are similar I now have a much better idea of how I need to lay out the UART section of my board.

Additionally the board should be able to receive power from the USB port, and of course perform the "breakout" function. Below is a rough draft schematic I have come up with so far. Please bear in mind this is my first endeavor with both circuit design and eagle so it is a little messy and I'm still skeptical as to whether or not it will work but it's a start never the less

Thanks for reading, this will be a multi-part project and I shall keep updating as I continue to revise my design and learn more about hardware design. Thanks and until next time.








Sunday, 24 August 2014

Console Based - Angular Motion Modeling

 Console Based - Angular Motion Modeling



This week in my physics class I was learning about angular motion and the various equations associated with it. So, I thought it might make a fun project to make some code that integrates everything I've learned, so far. I chose to do this because I wanted to use object oriented programming in a project as well as wanting to learn how to do more complex calculations in C++ (such as square root ect) and I also wanted to get a feel for how to arrange equations in code. 

Angular motion is very similar to regular motion in the manner that the equations of motion can be used if there is a constant acceleration. So I wrote down all the equations that I wanted to include in the program.



These equations can also be rearranged to find any of the values included but I haven't bothered writing the rearrangements down. 


The code 

In all my other console-based projects everything I've written has all been in one .cpp file but since I have created a class I wanted to spread declarations and definitions over different files. We will look  at that after what is in the "main()" function.



 The first part of the code is nothing special, nine different "float" variables are created and the user is given the opportunity to assign each of them a value. I chose to use "float" variables rather than integers because otherwise numbers wouldn't be allowed to be decimal at all and that isn't much use with circle equations, or many equations for that matter! If the user doesn't know the value of one of the variables they are told to assign it the value "-1" I thought this would be a good choice for a unknown variable because these numbers will not become negative (I know some are vector quantities but I am not associating direction with this particular program).


Next, a for loop is created. The reason for this will become clear after we have looked at the class functions. Inside the for loop an instance of the class "angular_motion" called k is created and all the values from the initialization step are passed to the constructor, known or not. Now the program tests which variables are "known" and which are set to -1. If a variable is set to -1 then the corresponding function is called from the "angular_motion" class. The return value of the function is then assigned to the variable. If that variable no longer equals -1, after the function has been called then is is printed to the screen. This process is repeated on all the variables 3 times though for reasons I will explain shortly. (note in the photo not all the if statements are included but this does happen to all the  variables).


angular_motion class

All the declarations for the angular_motion class are kept in a separate header file (angular_motion.h) the code looks like so.

The class has 9 different functions, of type float, and a constructor. It has 10 different float variables, the extra one being pi all stored in the private section. The constructor, in the definition, takes all of the variables from the "main()" function and copies them to the corresponding variable in the class. Since there is no scope between class variables and functions the "OBT_" (OBT just means obtain) functions do not need to take in variables. Lets take a closer look at one of the functions, as defined in the "angular_motion.cpp" file.



Above is the definition of the "OBT_ang_vel_i()" function which can use a possibility of three different equations to set the return value to the initial angular velocity. Each equation is a variation of what I was shown on paper at the start of this post. To choose what equation to use the program has to look at what variables it knows (ie, what variables aren't equal to -1). We can see this being done in the evaluations of each if statement. For example to use the first equation listed (u = v -at) the program must know the value of v (final angular velocity), a(angular acceleration) and t(time).
If the program doesn't know enough variables to do any of the equations then it simply returns the value -1 and the program will work out the others. Since there is a for loop it will come back to the function after hopefully knowing other variables and should be able to complete an equation.



Here's another function definition. If the program "knows" the value of "radius" then the equation area = pi*radius^2 is carried out but if not the program will continue to learn the other values (hopefully one of them is radius) and will come back to the area function and be able to "complete" it.

Downloads

I liked this project because it was more challenging than the others I have attempted and required me to use OOP, which is a habit I would like to get into for future programs. I used different files in one program for the first time, I used the header file <math.h> for the first time, I used classes outside of practice for the first time too.


The source files are available for download here.  Thanks and until next time.