Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-18-2008, 11:39 PM
Member
 
Join Date: Aug 2008
Posts: 4
kienph2004 is on a distinguished road
Solution for Newton-Raphson method
I have written my problem using Java language .
I post it to the Jav forum .
I hope that it may be useful for someone
Thanks to mr Norm because your answer that i must study java language programming to solve my problem (wrap hand).



/**
* @(#)Newtonlastest.java
*
* Newtonlastest application
*

* @version 1.00 2008/8/15
*/
package Iterative.Newton;
import java.io.*;
import java.text.DecimalFormat;
public class Newtonlastest {
public static void main(String[] args) throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//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: ");
double xold = Double.parseDouble(in.readLine());
iteration =0;
System.out.print("step x fx\n");
System.out.print("--------------------------------------------------------------------------\n");
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;
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pls Help me for Newton-Raphson. kienph2004 Advanced Java 1 08-15-2008 03:50 PM
Pls Help me for Newton-Raphson method by Java kienph2004 Advanced Java 3 08-13-2008 07:07 PM
solution for my project shkelqa AWT / Swing 4 05-29-2008 12:31 AM
solution for my project themburu Java Applets 4 05-21-2008 03:03 PM
Please need solution prithvi New To Java 4 04-22-2008 03:27 PM


All times are GMT +3. The time now is 09:52 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org