数值分析实验 插值法

  • E0_631944
    了解作者
  • 6.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-31 12:11
    上传日期
数值分析实验 插值法 java版 import java.awt.*; import java.awt.event.*; import java.util.StringTokenizer; import javax.swing.Box; class chazhifa extends Frame implements ActionListener { TextArea area, result, result2; Button butt, butt2, butt3; Label lab, lab3; Box box1, box2, box3, box4, box5, box6, box7; TextField field, field2; chazhifa() { super("插值法:"); area = new TextArea(5, 34); result = new TextArea(4, 8); result.setEditable(false); result2 = new TextArea(4, 8); result2.setEditable(false); butt = new Button("拉格朗日插值:"); butt3 = new Button("牛顿插值:"); butt2 = new Button("清除"); field = new TextField(5); field2 = new TextField(5); lab = new Label("依次输入xi和yi的值:"); lab3 = new Label("输入n和x:"); box2 = Box.createHorizontalBox(); box1 = Box.createVerticalBox(); box3 = Box.createHorizontalBox(); box4 = Box.createHorizontalBox(); box5 = Box.createHorizontalBox(); box6 = Box.createHorizontalBox(); box7 = Box.createVerticalBox(); setLayout(new FlowLayout()); box2.add(lab3); box2.add(field); box2.add(field2); box2.add(butt2); box3.add(lab); box4.add(area); box5.add(butt); box5.add(butt3); box6.add(result); box6.add(result2); box7.add(Box.createVerticalStrut(6)); box7.add(box2); box7.add(Box.createVerticalStrut(5)); box7.add(box3); box7.add(Box.createVerticalStrut(5)); box7.add(box4); box7.add(Box.createVerticalStrut(5)); box7.add(box5); box7.add(Box.createVerticalStrut(5)); box7.add(box6); box7.add(Box.createVerticalStrut(5)); add(box7); butt.addActionListener(this); butt2.addActionListener(this); butt3.addActionListener(this); validate(); setBounds(200, 200, 300, 330); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
插值法.zip
  • 插值法
  • .project
    385B
  • src
  • chazhi.java
    3.9KB
  • .classpath
    232B
  • bin
  • chazhifa.class
    4.5KB
  • chazhi.class
    421B
  • chazhifa$1.class
    607B
内容介绍
import java.awt.*; import java.awt.event.*; import java.util.StringTokenizer; import javax.swing.Box; class chazhifa extends Frame implements ActionListener { TextArea area, result, result2; Button butt, butt2, butt3; Label lab, lab3; Box box1, box2, box3, box4, box5, box6, box7; TextField field, field2; chazhifa() { super("插值法:"); area = new TextArea(5, 34); result = new TextArea(4, 8); result.setEditable(false); result2 = new TextArea(4, 8); result2.setEditable(false); butt = new Button("拉格朗日插值:"); butt3 = new Button("牛顿插值:"); butt2 = new Button("清除"); field = new TextField(5); field2 = new TextField(5); lab = new Label("依次输入xi和yi的值:"); lab3 = new Label("输入n和x:"); box2 = Box.createHorizontalBox(); box1 = Box.createVerticalBox(); box3 = Box.createHorizontalBox(); box4 = Box.createHorizontalBox(); box5 = Box.createHorizontalBox(); box6 = Box.createHorizontalBox(); box7 = Box.createVerticalBox(); setLayout(new FlowLayout()); box2.add(lab3); box2.add(field); box2.add(field2); box2.add(butt2); box3.add(lab); box4.add(area); box5.add(butt); box5.add(butt3); box6.add(result); box6.add(result2); box7.add(Box.createVerticalStrut(6)); box7.add(box2); box7.add(Box.createVerticalStrut(5)); box7.add(box3); box7.add(Box.createVerticalStrut(5)); box7.add(box4); box7.add(Box.createVerticalStrut(5)); box7.add(box5); box7.add(Box.createVerticalStrut(5)); box7.add(box6); box7.add(Box.createVerticalStrut(5)); add(box7); butt.addActionListener(this); butt2.addActionListener(this); butt3.addActionListener(this); validate(); setBounds(200, 200, 300, 330); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public void actionPerformed(ActionEvent e) { String sa = area.getText().trim(); String sn = field.getText().trim(); String sx = field2.getText().trim(); int n = Integer.parseInt(sn); float xx = Float.parseFloat(sx); StringTokenizer fenxi = new StringTokenizer(sa, "#\n"); float x[] = new float[n + 1]; float y[] = new float[n + 1]; int i = 0, j = 0, flag = 1, k; float temp, lk = 1, sumln = 0, b = 1, nn = 0; float t[] = new float[n]; float f[] = new float[n + 1]; while (fenxi.hasMoreTokens()) { String str = fenxi.nextToken(); StringTokenizer fenxi2 = new StringTokenizer(str, " "); while (fenxi2.hasMoreTokens()) { String str2 = fenxi2.nextToken(); temp = Float.parseFloat(str2); if (flag == 1) { x[i] = temp; i++; } if (i == (n + 1)) { flag = 0; i = 0; continue; } if (flag == 0) { y[j] = temp; j++; } if (j == (n + 1)) { flag = 1; j = 0; continue; } } } if (e.getSource() == butt) { for (k = 0; k <= n; k++) { for (i = 0; i <= n; i++) { if (i != k) lk *= ((xx - x[i]) / (x[k] - x[i])); } sumln += (lk * y[k]); lk = 1; } result.setText("Ln(" + xx + ")=\n" + sumln); } if (e.getSource() == butt2) { area.setText(null); field.setText(null); field2.setText(null); result.setText(null); result2.setText(null); } if (e.getSource() == butt3) { f[0] = y[0]; for (k = 1; k <= n; k++) { for (i = 0; i < n - k + 1; i++) t[i] = (y[i + 1] - y[i]) / (x[i + k] - x[i]); f[k] = t[0]; for (i = 0; i < n - k + 1; i++) y[i] = t[i]; } nn = f[0]; for (i = 1; i <= n; i++) { b = f[i]; for (j = 0; j <= i - 1; j++) b *= (xx - x[j]); nn += b; } result2.setText("Nn(" + xx + ")=\n" + nn); } }// action } public class chazhi { public static void main(String[] args) { chazhifa cha = new chazhifa(); } } /* x: 0.5635 * 0.56160 0.56280 0.56401 0.56521#0.82741 0.82659 0.82577 0.82495 */
评论
    相关推荐
    • ETL:适用于JavaETL Framwork
      ETL 适用于JavaETL Framwork
    • 贪吃蛇Java源码
      public class GreedSnake implements KeyListener { JFrame mainFrame; Canvas paintCanvas; JLabel labelScore;//计分牌 SnakeModel snakeModel=null;// 蛇 public static final int canvasWidth=200;...
    • java扫雷源码
      import java.awt.BorderLayout; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.LinkedList; import java.util.List; import javax.swing.ImageIcon; import javax....
    • java图片处理jar包
      * 添加图片水印:ImageAndTxtUtils.pressImage * 添加文字水印:ImageAndTxtUtils.pressText * 获取字符长度:ImageAndTxtUtils.getLength * 图片缩放:ImageAndTxtUtils.resize
    • etl工具kettle使用demo
      java开源项目kettle教材,使用etl工具的demo,教材,适合初学者,
    • java美化下拉框Demo
      主要代码: this.setTitle("下拉框美化"); this.setSize(800, 600); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container container = getContentPane(); container.setLayout(null);...
    • exercism_java_etl
      提取-转换-加载 (ETL) 是一种奇特的说法,“我们在这个系统中有一些粗糙的遗留数据,现在我们在这个闪亮的新系统中需要它,所以我们要迁移它。 ” (通常,这之后是,“我们只需要运行一次。”然后通常会有很多拍...
    • ArtNet-Java
      Java ArtNet Dmx发送器 构造函数: ArtNetLib(String socketIp) :带有套接字IP地址的构造方法。 ArtNetLib artnet = new ArtNetLib("xxx.xxx.xxx.xxx"); 方法: sendArtDmxPacket(byte[] dmxChannelData, byte ...
    • java swing风格包quaqua
      java swing风格包,让你的界面如同苹果界面 使用方法:在程序开始地方加如下代码: setDefaultLookAndFeelDecorated(true); UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
    • Java象棋源码
      import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; //主类 public class Chess{ public static void main(String args[]){ new ChessMainFrame("中国...