java - Creating a method for finding the root(s) of an equation -



java - Creating a method for finding the root(s) of an equation -

i want create method calculates root of function of choice. far have:

private static int function(int n){ int root; for(int = 0; i<=100; i++){ /** want replace x(see below see equation) value i, untill equation(n) == 0 , utilize value , homecoming integer variable called 'root' **/ } homecoming root; }

for example, given 1 equation , using next lines in main:

int equation = x - 2; system.out.println("the root(s) of " + equation + " is/are: " + function(equation));

i've been trying diffrent ways of achieving this, got errors far. been working on couple of hours it's not i'm not doing efforts, it's dont have plenty knowledge create functional. :(

edited

given task:

exercise - function roots

in order determine roots of given function there's easy algorithm: create sequential values of function until find argument result 0.

build class 'roots' containing implementation of method of calculating roots . function investigate must utilize private method function(int n). don't forget documentation. test class these functions: f(n)=n2-8n+16 , f(n)=n4-77n3+1361n2+4637n+3198.

i'd create array list of floats containing coefficients, ordered power. i'd iterate on range of x values, -1000 1000 increments of 0.01, example. each iteration i'd sum coefficients times x elevated corresponding powerfulness , check if sum equal zero, or close 0 consider 0 ;).

that way manage solve linear , non linear equations "relatively little error".

java function root equation

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -