-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Our class represents an object called complex function which defined as follows:
Left field- type function which means it could be a Polynom, a Monom or a complex function as well.
Right field- type function which means it could be a Polynom, a Monom or a complex function as well.
Op- type operation -Enum that could be one of the following only-
-
Plus- addition
-
Times- multiplication
-
Divid- division
-
Max- gets the maximum between left side value and right side value
-
Min- gets the minimum between left side value and right side value
-
Comp- Function composition
-
None- gets the left side value only
-
Error- technically is a valid operation but cannot but applied on a complex function -throws exception.
cf is a complex function object, f is a function, x is a double, s is a String and obj is an object in this example:
-
cf.f(x)- returns the complex function's value within the given x according to the operations as defined above.
-
cf.mul/comp/div/etc.(f)- builds a new complex function which it's left side is cf old structure, it's right side is f's copy and it's operation is the operation specified. cf now points this new Complex function created.
-
cf.toString – returns a string represents the complex function structure from top to bottom and left to right.
-
cf.initFromString(s)-returns a pointer to the function the string represents- could be a complex function or a polynom. monom is not an option since every monom is a polynom. cf is not affected by this action.
-
cf.copy- deep copy. returns a pointer to a logically similar complex function as cf.
-
cf.equals(obj)- in case obj is a function, cf is logically compered to obj (suppose to return true if equal for every value in the X axis, false otherwise). this method is very tricky since we cannot check every value in the scale. in our program we decided to check 1000 random values in addition to the range (-2,2). our method allows 2 unequal values to cover cases of holes in one function which is being compared to an equal but continues function, for example (x) and (x^2/x) are equal in our method. This compare can of course fail since we don't check every value. Statistically it has high odds to succeed but not 100% of the time.
we have some constuctures which gets different parameters and creat complex function accordingly.
-
string , function1, function2- the string represents the operation, if not spelled right throws exception. function1's copy becomes the left and function2's copy becomes the right.
-
operation, function1, function2- operation becomes the main operation between left and right. function1's copy becomes the left and function2's copy becomes the right.
-
function- function's copy becomes the left, right gets null, and the operation becomes none.
Function GUI is an object that has one field which is an array list of functions.
Function GUI implements 'functions' class which extends collection. the collection we chose to use is java’s array list.
-
initFromFile- this method gets a file path that containes number of functions and addes those functions to the array list.
-
saveToFile- gets a name for the file we want to create and prints to the file all of the functions in our list. One function in every line.
-
paint (Auxiliary method) - this method gets a function and draws it to a GUI window according the parameters the method got.
-
drawFunctions- there are two drawFunctions methods that have the same goal, which is to draw each function in the collection. Each method has a different way to get the parameters for the GUI window such as height, width, rx (X axis range) ,ry (Y axis range) and resolution. The first gets real parameters and draws accordingly. And the second gets the parameters from a json file calles "GUI_params.json".
output: 0) java.awt.Color[r=38,g=154,b=229] f(x)=plus(-X^4+2.4X^2+3.1,0.1X^5-1.2999999999999998X+5.0)
- java.awt.Color[r=191,g=119,b=244] f(x)=plus(div(X+1.0,mul(mul(X+3.0,X-2.0),X-4.0)),2.0)
- java.awt.Color[r=83,g=36,b=214] f(x)=div(plus(-X^4+2.4X^2+3.1,0.1X^5-1.2999999999999998X+5.0),-X^4+2.4X^2+3.1)
- java.awt.Color[r=251,g=154,b=143] f(x)=-X^4+2.4X^2+3.1
- java.awt.Color[r=239,g=85,b=112] f(x)=0.1X^5-1.2999999999999998X+5.0
- java.awt.Color[r=123,g=11,b=97] f(x)=max(max(max(max(plus(-X^4+2.4X^2+3.1,0.1X^5-1.2999999999999998X+5.0),plus(div(X+1.0,mul(mul(X+3.0,X-2.0),X-4.0)),2.0)),div(plus(-X^4+2.4X^2+3.1,0.1X^5-1.2999999999999998X+5.0),-X^4+2.4X^2+3.1)),-X^4+2.4X^2+3.1),0.1X^5-1.2999999999999998X+5.0)
- java.awt.Color[r=105,g=2,b=85] f(x)=min(min(min(min(plus(-X^4+2.4X^2+3.1,0.1X^5-1.2999999999999998X+5.0),plus(div(X+1.0,mul(mul(X+3.0,X-2.0),X-4.0)),2.0)),div(plus(-X^4+2.4X^2+3.1,0.1X^5-1.2999999999999998X+5.0),-X^4+2.4X^2+3.1)),-X^4+2.4X^2+3.1),0.1X^5-1.2999999999999998X+5.0)
java doc