have a java program that have evaluate thefunction,calculate the derivative and roots haw can i demonstrate numerical methods to solve the runge kutta method.
This ma functiuon
package Iterative.Newton;
import java.io.*;
import java.text.DecimalFormat;
public class Newtonlastest {
public static void main(String[] args) throws Exception{
//Format to display with six decimal places
DecimalFormat root = new DecimalFormat("####0.000000");
//Format to display with seven decimal places
DecimalFormat rootseven = new DecimalFormat("####0.0000000");
//This is the const to select delta
final double select_delta = 0.5;
double xnew;
double fxold;
double fdashxold;
double absfxnew;
int iteration;
System.out.print("Enter the initial approximation for the root: ");
iteration =0;
System.out.print("step x fx\n");
System.out.print("--------------------…
do
{
// determine f(xold) and f·xold)
fxold = func(xold);
// printf temp result
System.out.print( "\n");
System.out.print( iteration );
System.out.print( " " + root.format(xold) );
System.out.print( " " + rootseven.format(fxold) );
iteration = iteration + 1;
//fdashxold = derivative_func(xold);

//if calculate by approximate derivative then comment above line, and uncomment below line
fdashxold = appro_derivative(xold, select_delta);
xnew = xold - (fxold/fdashxold);
absfxnew = func(xnew);
if(absfxnew < 0)
{
absfxnew = -absfxnew;
}
xold = xnew;

// check for convergence using the criterion |f(x)| < 0.000001
}
while (absfxnew > 0.000001);
System.out.println("\n");
System.out.print( iteration );
System.out.print(" " + root.format(xold) );
System.out.print( " "+ rootseven.format(func(xold)) );
System.out.println();
System.out.print("\nroot to six decimal places is :");
System.out.print(root.format(xnew));

}
public static double func(double x)
{

return (0.66 *pow_int(x, 5) - 8.7 *pow_int(x, 4) + 42 *pow_int(x, 3) - 90 *x *x + 80 *x -24);
}

public static double derivative_func(double x)
{
return (3.3 *pow_int(x, 4) - 34.8 *pow_int(x, 3) + 126 *pow_int(x, 2) - 180 *x + 80);
}

public static double appro_derivative(double x, double delta)
{
return (func(x+delta) - func(x))/delta;
}
public static double pow_int(double x, int n)
{
double result = 1;
int i;

for(i = 0; i < n; i++)
{
result *= x;
}
return result;
}
}

haw can i they want me to run the program using three nonl linear functions/equations of my chooice using three different starting points then diplay the function,values of n,f(x),xn,f'(xn),Xn+1 as the solution converges also to display the roots ,if found,or a message indicating nonconvergence,a singularity,or iteration limit
So can someone tell me if i have been doing the right thing and what do i lack and how cn i go on to do the rest?

Start work with the base linear function

f(x)=x for [-1.0,+1.0] with step 0.1

. Create a class (for example Equation extends java.lang.Object) with constructor and methods. Results print only to console. This is not a joke.
See you later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.