一元線性回歸模型控制方程求解_第1頁
一元線性回歸模型控制方程求解_第2頁
一元線性回歸模型控制方程求解_第3頁
一元線性回歸模型控制方程求解_第4頁
一元線性回歸模型控制方程求解_第5頁
已閱讀5頁,還剩31頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

梅國平,袁捷敏,毛小兵,李杰編著《概率論與數(shù)理統(tǒng)計出社2007年給出一個一元線性回歸模型控制問題求解方程組:書中解得p=2.51p=2.4812上述控制方程組的解可以表示成兩條曲線中間夾一條直線與直線、線y=3相的四個交點(diǎn)所對應(yīng)的橫坐標(biāo)x值用mathematica軟做的示意圖如下軟中相應(yīng)的隱函數(shù)作圖命令為:1

2.02.83.2用語編寫出求解類似控制方程組求解程序。程求解過程的難點(diǎn)在于上述方程組中的根號開方部分程把解上述復(fù)雜方程組的根號開方問題轉(zhuǎn)化為求一個一元二次方程的兩個根借鑒其他參考書中有論述被區(qū)間兩個端點(diǎn)的中心對應(yīng)的回歸直線上投影點(diǎn)橫坐標(biāo)x值代控制方程中根號下的未知數(shù)似論一下控制區(qū)間的長度是否滿足可控條件是準(zhǔn)確確討論上述控制方程組的可控問題比較復(fù)雜程沒有實現(xiàn)。程序運(yùn)行啟動界面截圖:2

點(diǎn)擊“求解”按鈕后程序運(yùn)行界面截圖:源程序清單如下:主程序:一元線性回歸模型控制方程求.java/***根給定的因變量被控區(qū)間,求出自變量的施控區(qū)間。**作:Adam**/publicclass一線性回歸模型控制方程求解{publicstaticvoidmain(Stringargs{界面求解例=界面6.45,-1.58,2.0,3.0,4.78,2.306,0.2,10.0,2.5);}}輸入輸出界面類:界.javaimportjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JTextField;3

importjavax.swing.JButton;importjavax.swing.JPanel;importjava.awt.BorderLayout;importjava.awt.GridLayout;importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;publicclass界{private主口privateJLabela標(biāo);privateJTextFielda;privateJLabelb標(biāo);privateJTextFieldb;privateJLabelTn_2標(biāo)簽privateJTextFieldprivateJLabelSe標(biāo)簽privateJTextFieldSe;privateJLabeln標(biāo);privateJTextFieldn;privateJLabelaverageOfX標(biāo);privateJTextFieldaverageOfX;privateJLabellxx簽privateJTextFieldprivateJLabel左點(diǎn)標(biāo);privateJTextField左端點(diǎn)privateJLabel右點(diǎn)標(biāo);privateJTextField右端點(diǎn)privateJLabel可否標(biāo);privateJLabel左點(diǎn)dY原;privateJLabel左點(diǎn)根1標(biāo);privateJTextField左端點(diǎn)根1值privateJLabel左點(diǎn)根1dY檢值privateJLabel左點(diǎn)根2標(biāo);privateJTextField左端點(diǎn)根2值privateJLabel左點(diǎn)根2dY檢值privateJLabel右點(diǎn)dY原;privateJLabel右點(diǎn)根1標(biāo);privateJTextField右端點(diǎn)根1值privateJLabel右點(diǎn)根1dY檢值privateJLabel右點(diǎn)根2標(biāo);privateJTextField右端點(diǎn)根2值privateJLabel右點(diǎn)根2dY檢值privateJButton求解;private求按鈕動作實求;4

privateJButton重置;privateJButton退出;界面(){初始化界面);實際求解=求按鈕動作this);求解.實求解;}界面(doubleoriginalA,doubleoriginalB,doubleoriginal左點(diǎn)doubleoriginal右點(diǎn),doubleoriginalLxx,doubleoriginalTn_2,doubleoriginalSe,doubleoriginalN,doubleoriginalAverageOfX){初始化界面);a.setText(Double.toString(originalA));b.setText(Double.toString(originalB));左端點(diǎn)setText(Double.toString(original左點(diǎn));右端點(diǎn)setText(Double.toString(original右點(diǎn));lxx.setText(Double.toString(originalLxx));Tn_2.setText(Double.toString(originalTn_2));Se.setText(Double.toString(originalSe));n.setText(Double.toString(originalN));averageOfX.setText(Double.toString(originalAverageOfX));實際求解=求按鈕動作this);求解.實求解;}privatevoid初化界面{主窗口JFrame("一線性回歸模型控制方程求);主窗口setSize(900,400);主窗口setLocation(120,120);a標(biāo)JLabel("a:a=newJTextField(20);輸入文本框數(shù)字檢查check=new輸文本框數(shù)字檢窗)a.getDocument().addDocumentListener(check);b標(biāo)簽=new:");b=JTextField("",20);b.getDocument().addDocumentListener(check);Tn_2標(biāo)簽=:Tn_2=newJTextField("",20);Tn_2.getDocument().addDocumentListener(check);5

Se標(biāo)簽=JLabel("Se:Se=newJTextField("",20);Se.getDocument().addDocumentListener(check);n標(biāo)簽=newJLabel("n:n=newJTextField("",20);n.getDocument().addDocumentListener(check);averageOfX標(biāo)簽=JLabel("averageof:");averageOfX=newJTextField("",20);averageOfX.getDocument().addDocumentListener(check);lxx標(biāo)簽=JLabel("lxx:lxx=newJTextField("",20);lxx.getDocument().addDocumentListener(check);左端點(diǎn)標(biāo)簽=newJLabel("左點(diǎn):");左端點(diǎn)=JTextField("",20);左端點(diǎn)getDocument().addDocumentListener(check);右端點(diǎn)標(biāo)簽=newJLabel("右點(diǎn):");右端點(diǎn)=JTextField("",20);右端點(diǎn)getDocument().addDocumentListener(check);JPanel輸?shù)谝恍?newJPanel();JPanel輸?shù)诙?newJPanel();JPanel輸?shù)谌?newJPanel();輸入第一行add(a標(biāo));輸入第一行add(a);輸入第一行add(b標(biāo));輸入第一行add(b);輸入第一行add(Tn_2標(biāo);輸入第一行add(Tn_2);輸入第二行add(Se標(biāo));輸入第二行add(Se);輸入第二行add(n標(biāo));輸入第二行add(n);輸入第二行add(averageOfX標(biāo)輸入第二行add(averageOfX);輸入第三行add(lxx標(biāo);輸入第三行add(lxx);輸入第三行左點(diǎn)標(biāo);輸入第三行左點(diǎn);輸入第三行右點(diǎn)標(biāo);輸入第三行右點(diǎn);左端點(diǎn)dY原始值=JLabel("左端點(diǎn)原始值:",JLabel.CENTER);左端點(diǎn)根1標(biāo)=new由1:",JLabel.CENTER);左端點(diǎn)根1值=newJTextField(20);左端點(diǎn)根1dY檢值newJLabel("dy檢值:",JLabel.CENTER);左端點(diǎn)根2標(biāo)=new由2:",JLabel.CENTER);6

左端點(diǎn)根2值=newJTextField(20);左端點(diǎn)根2dY檢值newJLabel("dy檢值:",JLabel.CENTER);右端點(diǎn)dY原始值=JLabel("右端點(diǎn)原始值:",JLabel.CENTER);右端點(diǎn)根1標(biāo)=new由1:",JLabel.CENTER);右端點(diǎn)根1值=newJTextField(20);右端點(diǎn)根1dY檢值newJLabel("dy檢值:",JLabel.CENTER);右端點(diǎn)根2標(biāo)=new由2:",JLabel.CENTER);右端點(diǎn)根2值=newJTextField(20);右端點(diǎn)根2dY檢值newJLabel("dy檢值:",JLabel.CENTER);JPanelrightPoint1=newJPanel();JPanelrightPoint2=newJPanel();JPanelrightPoint3=newJPanel();JPanelleftPoint1=newJPanel();JPanelleftPoint2=newJPanel();JPanelleftPoint3=newJPanel();leftPoint1.add(左點(diǎn)dY原值;leftPoint2.add(左點(diǎn)根1標(biāo)簽;leftPoint2.add(左點(diǎn)根1值leftPoint2.add(左點(diǎn)根1dY檢值leftPoint3.add(左點(diǎn)根2標(biāo)簽;leftPoint3.add(左點(diǎn)根2值leftPoint3.add(左點(diǎn)根2dY檢值右點(diǎn)dY原值;右點(diǎn)根1標(biāo))右點(diǎn)根1值;右點(diǎn)根1dY檢驗值右點(diǎn)根2標(biāo))右點(diǎn)根2值;右點(diǎn)根2dY檢驗值求解=求");重置=重");重置.addActionListener(new重置按鈕動(this));退出=退");退出.addActionListener(new退出按鈕動(this));JPanel按行=newJPanel();按鈕行求解);按鈕行重置);按鈕行退出);可控否標(biāo)簽=JLabel("",JLabel.CENTER);JPanelpointPanel=JPanel(newGridLayout(11,1));輸?shù)谝?輸?shù)诙?輸?shù)谌?可否標(biāo);7

pointPanel.add(leftPoint1);pointPanel.add(leftPoint2);pointPanel.add(leftPoint3);pointPanel.add(rightPoint1);pointPanel.add(rightPoint2);pointPanel.add(rightPoint3);按行主窗口setLayout(newBorderLayout());主窗口add(pointPanel,BorderLayout.CENTER);主窗口setVisible(true);主窗口validate();主窗口setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicset主口JFrame主口{主口=主窗;}public主口{return主口}publicsetA標(biāo)(JLabel標(biāo)簽{this.a標(biāo)=a標(biāo);}publicJLabelgetA簽{returna標(biāo);}publicsetA(JTextFielda){this.a=a;主窗口validate();}publicJTextFieldgetA(){return}publicsetB標(biāo)(JLabelb標(biāo))8

{this.a標(biāo)=a標(biāo);主窗口validate();}publicJLabelgetB標(biāo)){returnb標(biāo);}publicsetB(JTextFieldb){this.b=b;主窗口validate();}publicJTextFieldgetB(){returnb;}publicsetTn_2標(biāo)(JLabel標(biāo)){this.Tn_2標(biāo)簽=Tn_2標(biāo)簽主窗口validate();}publicJLabelgetTn_2標(biāo)簽{return標(biāo)簽}publicsetTn_2(JTextFieldTn_2){this.Tn_2Tn_2;主窗口validate();}publicJTextFieldgetTn_2(){returnTn_2;}publicsetSe標(biāo)簽JLabel標(biāo)簽9

{this.Se標(biāo)=Se標(biāo);主窗口validate();}publicJLabelgetSe標(biāo)){returnSe標(biāo);}publicsetSe(JTextFieldSe){this.SeSe;主窗口validate();}publicJTextFieldgetSe(){returnSe;}publicsetN標(biāo)簽(JLabeln標(biāo)){this.n標(biāo)=n標(biāo)簽;主窗口validate();}publicJLabelgetN標(biāo)簽({returnn標(biāo);}publicsetN(JTextFieldn){this.n=n;主窗口validate();}publicJTextFieldgetN(){returnn;}public標(biāo)(JLabel標(biāo)簽10

{this.averageOfX標(biāo)=averageOfX標(biāo);主窗口validate();}publicJLabel標(biāo)(){return標(biāo);}publicsetAverageOfX(JTextFieldaverageOfX){this.averageOfX=averageOfX;主窗口validate();}publicJTextFieldgetAverageOfX(){returnaverageOfX;}publicsetLxx標(biāo)(JLabellxx標(biāo)){this.lxx標(biāo)=lxx標(biāo)簽主窗口validate();}publicJLabelgetLxx標(biāo)(){returnlxx標(biāo);}publicsetLxx(JTextFieldlxx){this.lxxlxx;主窗口validate();}publicJTextFieldgetLxx(){returnlxx;}publicset左點(diǎn)JLabel左點(diǎn)標(biāo)簽11

{左點(diǎn)標(biāo)簽左點(diǎn)標(biāo)簽主窗口validate();}publicJLabelget端點(diǎn)標(biāo)(){return左點(diǎn)標(biāo)簽}publicset左點(diǎn)JTextField左端點(diǎn){左點(diǎn)=左端;主窗口validate();}publicJTextFieldget左點(diǎn){return左點(diǎn)}publicset右點(diǎn)JLabel右點(diǎn)標(biāo)簽{右點(diǎn)標(biāo)簽右點(diǎn)標(biāo)簽主窗口validate();}publicJLabelget端點(diǎn)標(biāo)(){return右點(diǎn)標(biāo)簽}publicset右點(diǎn)JTextField右端點(diǎn){右點(diǎn)=右端;主窗口validate();}publicJTextFieldget右點(diǎn){return右點(diǎn)}publicset可否JLabel可否標(biāo)簽12

{可否標(biāo)簽可否標(biāo)簽主窗口validate();}publicJLabelget控否標(biāo)(){return可否標(biāo)簽}publicset左點(diǎn)dY原始值JLabel左端點(diǎn)dY原值{左點(diǎn)dY原始值=左端點(diǎn)原始值主窗口validate();}publicJLabelget端點(diǎn)dY原始值){return左點(diǎn)dY原值}publicset左點(diǎn)1標(biāo)(JLabel左點(diǎn)根1標(biāo)簽){左點(diǎn)根標(biāo)簽左點(diǎn)根1標(biāo)簽主窗口validate();}publicJLabelget端點(diǎn)根標(biāo){return左點(diǎn)根1標(biāo);}publicset左點(diǎn)1值JTextField左點(diǎn)根1值{左點(diǎn)根值左點(diǎn)根值主窗口validate();}publicJTextFieldget左點(diǎn)根1值{return左點(diǎn)根1值;}publicset左點(diǎn)檢驗JLabel左點(diǎn)根1dY檢值13

{左點(diǎn)根1dY檢值=左點(diǎn)根1dY檢值主窗口validate();}publicJLabelget端點(diǎn)根1dY檢值){return左點(diǎn)根1dY檢值}publicset左點(diǎn)2標(biāo)(JLabel左點(diǎn)根2標(biāo)簽){左點(diǎn)根標(biāo)簽左點(diǎn)根2標(biāo)簽主窗口validate();}publicJLabelget端點(diǎn)根標(biāo){return左點(diǎn)根2標(biāo);}publicset左點(diǎn)2值JTextField左點(diǎn)根2值{左點(diǎn)根值左點(diǎn)根值主窗口validate();}publicJTextFieldget左點(diǎn)根2值{return左點(diǎn)根2值;}publicset左點(diǎn)檢驗JLabel左點(diǎn)根2dY檢值{左點(diǎn)根2dY檢值=左點(diǎn)根2dY檢值主窗口validate();}publicJLabelget端點(diǎn)根2dY檢值){return左點(diǎn)根2dY檢值}publicset右點(diǎn)dY原始值JLabel右端點(diǎn)dY原值14

{右點(diǎn)dY原始值=右端點(diǎn)原始值主窗口validate();}publicJLabelget端點(diǎn)dY原始值){return右點(diǎn)dY原值}publicset右點(diǎn)1標(biāo)(JLabel右點(diǎn)根1標(biāo)簽){右點(diǎn)根標(biāo)簽右點(diǎn)根1標(biāo)簽主窗口validate();}publicJLabelget端點(diǎn)根標(biāo){return右點(diǎn)根1標(biāo);}publicset右點(diǎn)1值JTextField右點(diǎn)根1值{右點(diǎn)根值右點(diǎn)根值主窗口validate();}publicJTextFieldget右點(diǎn)根1值{return右點(diǎn)根1值;}publicset右點(diǎn)檢驗JLabel右點(diǎn)根1dY檢值{右點(diǎn)根1dY檢值=右點(diǎn)根1dY檢值主窗口validate();}publicJLabelget端點(diǎn)根1dY檢值){return右點(diǎn)根1dY檢值}publicset右點(diǎn)2標(biāo)(JLabel右點(diǎn)根2標(biāo)簽)15

{右點(diǎn)根標(biāo)簽右點(diǎn)根2標(biāo)簽主窗口validate();}publicJLabelget端點(diǎn)根標(biāo){return右點(diǎn)根2標(biāo);}publicset右點(diǎn)2值JTextField右點(diǎn)根2值{右點(diǎn)根值右點(diǎn)根值主窗口validate();}publicJTextFieldget右點(diǎn)根2值{return右點(diǎn)根2值;}publicset右點(diǎn)檢驗JLabel右點(diǎn)根2dY檢值{右點(diǎn)根2dY檢值=右點(diǎn)根2dY檢值主窗口validate();}publicJLabelget端點(diǎn)根2dY檢值){return右點(diǎn)根2dY檢值}publicset求(JButton求解){求=求;主窗口validate();}publicJButtonget求解{return求;}publicset實求(求按鈕動作實求)16

{實求解實求;主窗口validate();}public求按鈕動作get實求解{return實求;}publicset重(JButton重置){重=重;主窗口validate();}publicJButtonget重置{return重;}publicset退(JButton退出){退=退;主窗口validate();}publicJButtonget退出{return退;}}輸入?yún)?shù)是否為數(shù)字格式檢查類:輸入文本框數(shù)字檢.javaimportjavax.swing.event.DocumentListener;importjavax.swing.event.DocumentEvent;importjavax.swing.text.Document;importjavax.swing.text.BadLocationException;importjavax.swing.JOptionPane;importjavax.swing.JFrame;publicclass輸文本框數(shù)字檢查implementsDocumentListener{private主口輸入文本框數(shù)字檢查)17

{主窗口null;}輸入文本框數(shù)字檢查JFrame主口{主口=主窗;}publicset主口JFrame主口{主口=主窗;}public主口{return主口}publicinsertUpdate(DocumentEvente){數(shù)字檢查e.getDocument());}publicremoveUpdate(DocumentEvente){數(shù)字檢查e.getDocument());}publicchangedUpdate(DocumentEvente){數(shù)字檢查e.getDocument());}privatevoid數(shù)檢(doc){double=0;try{tDouble.parseDouble(doc.getText(0,doc.getLength()));}catch(BadLocationExceptione){//System.out.println("文框字符位置越界!錯誤提示讀文本框字符位置越界內(nèi)錯");18

}catch(NumberFormatExceptione){//System.out.println("您入了非數(shù)字字符,請輸入數(shù)字");錯誤提示您入了非數(shù)字字符,請輸入數(shù)字入錯");}}privatevoid錯提(Object提信,String標(biāo)){JOptionPane.showMessageDialog(窗口提信,標(biāo),JOptionPane.ERROR_MESSAGE);}}根據(jù)輸入?yún)?shù)計算施控區(qū)間端點(diǎn)值的求解按鈕動作類:求解按鈕動importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;importjavax.swing.JOptionPane;publicclass求按鈕動作implementsActionListener{private界源對;privatedoubleprivatedoubleb;privatedoubleTn_2;privatedoubleprivatedoublen;privatedoubleaverageOfX;privatedoublelxx;privatedouble左;privatedouble右;privateboolean輸異;privateboolean可否求解按鈕動(){源對象null;a=0;b=0;Tn_2=0;Se=0;n=0;averageOfX0;lxx=0;左端點(diǎn)0;右端點(diǎn)0;輸入異常=true;19

可控否

=false;}求解按鈕動(界源對象{源象=源對;try{a=源對象getA().getText());b=源象getB().getText());Tn_2=源象getTn_2().getText());Se=源象.getSe().getText());n=源象getN().getText());averageOfXDouble.parseDouble(源象getAverageOfX().getText());lxx=Double.parseDouble(源對.getLxx().getText());左端點(diǎn)Double.parseDouble(對象.get左端點(diǎn)).getText());右端點(diǎn)Double.parseDouble(對象.get右端點(diǎn)).getText());輸入異常=false;}catch(NullPointerException空文本框{輸入異常=true;錯誤提示文框為空,請輸入數(shù)值輸錯誤);}catch(NumberFormatException數(shù)格式異常){輸入異常=true;錯誤提示輸數(shù)字格式錯","內(nèi)錯");}可控否false;}publicset源象界源象{源象=源對;}public界get源對象{return源象}publicsetA(doublea){20

this.a=a;}publicgetA(){return}publicsetB(doubleb){this.b=b;}publicgetB(){returnb;}publicsetTn_2(doubleTn_2){this.Tn_2Tn_2;}publicgetTn_2(){returnTn_2;}publicsetSe(doubleSe){this.SeSe;}publicgetSe(){returnSe;}publicsetN(doublen){this.n=n;}publicgetN()21

{returnn;}publicsetAverageOfX(doubleaverageOfX){this.averageOfX=averageOfX;}publicgetAverageOfX(){returnaverageOfX;}publicsetLxx(doublelxx){this.lxxlxx;}publicgetLxx(){returnlxx;}publicset左點(diǎn)double左點(diǎn){左點(diǎn)=左端;}publicget左端點(diǎn)){return左點(diǎn)}publicset右點(diǎn)double右點(diǎn){右點(diǎn)=右端;}publicget右端點(diǎn)){return右點(diǎn)}22

publicset輸異(boolean輸異常{輸異常輸異;}publicget輸異(){return輸異;}publicset可否boolean可控否{可否=可控;}publicget可否{return可否}publicactionPerformed(ActionEvente){try{a=源對象getA().getText());b=源象getB().getText());Tn_2=源象getTn_2().getText());Se=源象.getSe().getText());n=源象getN().getText());averageOfXDouble.parseDouble(源象getAverageOfX().getText());lxx=Double.parseDouble(源對.getLxx().getText());左端點(diǎn)Double.parseDouble(對象.get左端點(diǎn)).getText());右端點(diǎn)Double.parseDouble(對象.get右端點(diǎn)).getText());輸入異常=false;}catch(NullPointerException空文本框{輸入異常=true;錯誤提示文框為空,請輸入數(shù)值輸錯誤);}catch(NumberFormatException數(shù)格式異常){輸入異常=true;錯誤提示輸數(shù)字格式錯","內(nèi)錯");23

}輸異==false){求解端點(diǎn)左點(diǎn)左端點(diǎn)求解端點(diǎn)(右點(diǎn)new右端點(diǎn)));確定是否可();可否true){修改可控否標(biāo)簽"被區(qū)間滿足可控條件,可以實現(xiàn)控制");}else{修改可控否標(biāo)簽"被區(qū)間過小,不能實現(xiàn)控制");}}}privatevoid求端(端Point){doubleresult=0;double=0.0;doubleV=0.0;doubleW=0.0;doubleQ=0.0;doubledA=0.0;double0.0;double=0.0;U((a-dY)Math.sqrt(lxx))/(Tn_2*Se);V=b*Math.sqrt(lxx)/(Tn_2Se);Wlxx*(1.0+1.0/n);QaverageOfX;dAMath.pow(V,2)1.0;dB2.0*U*V+2.0*Q;dC=Math.pow(U,2)-W-Math.pow(Q,2);OnceBasicQuadraticEquation求根OnceBasicQuadraticEquation(dA,dB,dC);求根.求();(求根get實)==true){求根get根的個(0){result=Double.NEGATIVE_INFINITY;}else求.get根個()1)24

{驗根(求.get根1(),Point);}else求.get根個()2){驗根(求.get根1(),求根get根2(),Point);}else{result=Double.NEGATIVE_INFINITY;}}else{result=Double.NEGATIVE_INFINITY;}}public驗根double根端Point){Point.修界面源象根;}privatevoid驗根double根1,double根端Point){Point.修界面源象根根}privatevoid確是否可控){double=x0左端點(diǎn)右端點(diǎn)2.0;double=L=2.0*Tn_2*Math.sqrt(1.0(1.0/n)+(Math.pow((x0-averageOfX),2)/lxx));if(Math.abs(端點(diǎn)右點(diǎn)>L){可控否true;}else{可控否false;}}privatevoid修可控否標(biāo)簽String是否可控提示25

{源對象get可否標(biāo)(是可控提);源對象get主).validate();}privatevoid錯提(Object提示信,String標(biāo)){JOptionPane.showMessageDialog(源對象.get題JOptionPane.ERROR_MESSAGE);}

主窗口提示信息,標(biāo)}求解一元二次方程兩個實根類OnceBasicQuadraticEquation.javapublicclassOnceBasicQuadraticEquation{privatedoubleprivatedoubleb;privatedoubleprivateint根的個數(shù)privatedouble根1;privatedouble根2;privateboolean實否privatedouble實;privatedouble虛1;privatedouble虛2;OnceBasicQuadraticEquation(){a=0;b=0;c0;根的個數(shù)=0;根10;根20;實根否=true;實部=0;虛部1=0;虛部2=0;}OnceBasicQuadraticEquation(doublea,doubleb,doublec){this.a=a;this.b=b;this.cc;26

根的個數(shù)=0;根10;根20;實根否=true;實部=0;虛部1=0;虛部2=0;}publicsetA(doublea){this.a=a;}publicgetA(){return}publicsetB(doubleb){this.b=b;}publicgetB(){returnb;}publicsetC(doublec){this.cc;}publicgetC(){return}publicset根個(int根的個數(shù){根個數(shù)根個;}27

publicint根個{return根個;}publicset根1(){根=根1;}publicget根1(){return根1;}publicset根2(double根2){根=根2;}publicget根2(){return根2;}publicset實否boolean實根否{實否=實根;}publicget實否{return實否}publicset實(double實部){實=實;}publicget實部{return實;}28

publicset虛1(double虛1){虛1虛1;}publicget虛部1(){return虛1;}publicset虛2(double虛2){虛2虛2;}publicget虛部2(){return虛2;}public求根){(a=={if(b=={if(c0){根的個數(shù)Integer.MAX_VALUE;根1=-100;根2100;}else{根的個數(shù)0;}}else{根的個數(shù)1;根1c/根2c/}29

}else{if(getDlt()>0){實根否=true;根的個數(shù)2;根1getLeftRoot();根2getRightRoot();}elseif(getDlt()=={實根否=true;根的個數(shù)1;根1-b(2*a);根2根1;}else{實根否實部

=false;=-b(2*a);虛部=Math.sqrt(-getDlt())/(2*a);虛部=-虛1;}}}publicgetDlt(){doubleresult=Math.pow(b,2)-4a*returnresult;}privatedoublegetRightRoot(){doublerightRoot0;rightRoot=(-b+Math.sqrt(getDlt()))(2*a);returnrightRoot;}privatedoublegetLeftRoot(){doubleleftRoot0;leftRoot=(-b-Math.sqrt(getDlt()))/(2a);30

returnleftRoot;}}端點(diǎn)抽象類:端.javapublicabstract端{(lán)abstractdouble驗求解按鈕動作源動作double根abstractvoid修界界源界,根;abstractvoid修界界源界,根1,double根2);}左端點(diǎn)具體類:左端.javapublicclass左點(diǎn)端點(diǎn){public驗求按鈕動作源動double根{doubleresult=0;result=源.getA()+源作getB()根-源.getTn_2()*源作getSe()*Math.sqrt(1+(1.0/源作getN())+Math.pow((根-源動作getAverageOfX()),2)/源動作getLxx()));returnresult;}public修界(界源面double根1,double根{源界面get左端點(diǎn)dY原始值).setText("左點(diǎn)原值:+源面get左點(diǎn)().getText());源界面get左端點(diǎn)根1值根1));源界面get左端點(diǎn)根2值根2));源界面get左端點(diǎn)根1dY檢值).setText("dy檢值"+驗(源面get實際求解),根1)+右端點(diǎn)dy檢值+右端).驗源.get實求解),1));源界面get左端點(diǎn)根2dY檢值).setText("dy檢值"+驗(源面get實際求解),根2)+右端點(diǎn)dy檢值+右端).驗源.get實求解),2));源界面get主窗).validate();}public修界(界源面double根31

{源界面get左端點(diǎn)dY原始值).setText("左點(diǎn)原值:+源面get左點(diǎn)().getText());源界面get左端點(diǎn)根1值根);源界面get左端點(diǎn)根2值).setText("");源界面get左端點(diǎn)根1dY檢值).setText("dy檢值"+驗(源面get實際求解),根+右端點(diǎn)dy檢值+右端).驗源.get實求解),根);源界面get左端點(diǎn)根2dY檢值).setText("dy檢值:");源界面ge

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論