牛顿定理解复杂方程--log

前两天需要解个高次复杂的函数方程 要精确到6位小数
用指定的first guess & 用牛顿定理要try n久 -- Newton method: Xn+1 = Xn - f(Xn)/(dy/dx|x=Xn)
没办法写个了简易的程序--非GUI界面 (1。用swing或者applet画个函数图像从图像上得到值显得没这个必要 2。要短时间内列出所有牛顿定理try的过程)

比如要求4X^3-42X^2-19X=28的根:

/**
 *  Note: the following solution calculates using full digits of a double number
 */

import java.text.DecimalFormat;

public class NewTonCA
{
  public static void main(String [] args)
  {
   
    String s = args[0];
    double d = Double.parseDouble(s),m=d;
    double f;
   
    DecimalFormat df = new DecimalFormat("#.000000"); //set num of decimal digits

    while(!df.format(m).equals(df.format(m-((4*Math.pow(m,3)-42*Math.pow(m,2)-19*m-28)/(12*Math.pow(m,2)-84*m-19)))))  //only compare first 6 decimal digits
   {
     f = m-((4*Math.pow(m,3)-42*Math.pow(m,2)-19*m-28)/(12*Math.pow(m,2)-84*m-19)); //Newton method
     m = f;   

     System.out.println(m+":-----------:"+f);} //output to screen with current Xn and value of Xn+1
   }
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值