科學編程計算器
1. 編程實現一個科學計算器,能夠實現加減乘除,三角函數計算等。用戶界面自己設計
java寫的,可行
package ex1;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
public class Calcutor extends JFrame {
private JTextField tf;
private JPanel panel1, panel2, panel3, panel4;
private JMenuBar myBar;
private JMenu menu1, menu2, menu3;
private JMenuItem editItem1, editItem2, help1, help2, help3;
private JRadioButtonMenuItem seeItem1, seeItem2;//單選框
private JCheckBoxMenuItem seeItem3;//復選框
private ButtonGroup bgb;
private String back;
private boolean IfResult = true, flag = false;
private String oper = "=";
private double result = 0;
private Num numActionListener;
private DecimalFormat df;
public Calcutor(){
super("科學計算器");//設置標題欄
df = new DecimalFormat("#.####");//保留四位小數
this.setLayout(new BorderLayout(10, 5));
panel1 = new JPanel(new GridLayout(1, 3, 10, 10));
panel2 = new JPanel(new GridLayout(5, 6, 5, 5));//5行6列
panel3 = new JPanel(new GridLayout(5, 1, 5, 5));
panel4 = new JPanel(new BorderLayout(5, 5));
/**
* 菜單欄
*/
myBar = new JMenuBar();
menu1 = new JMenu("編輯(E)");
menu2 = new JMenu("查看(V)");
menu3 = new JMenu("幫助(H)");
menu1.setFont(new Font("宋體", Font.PLAIN, 12));
menu2.setFont(new Font("宋體", Font.PLAIN, 12));
menu3.setFont(new Font("宋體", Font.PLAIN, 12));
/**
* 編輯欄
*/
editItem1 = new JMenuItem("復制(C) Ctrl+C");
editItem2 = new JMenuItem("粘貼(P) Ctrl+V");
editItem1.setFont(new Font("宋體",Font.PLAIN,12));
editItem2.setFont(new Font("宋體",Font.PLAIN,12));
/**
* 查看欄
*/
seeItem1 = new JRadioButtonMenuItem("科學型(T)");
seeItem2 = new JRadioButtonMenuItem("標准型(S)");
seeItem3 = new JCheckBoxMenuItem("數字分組(I)");
seeItem1.setFont(new Font("宋體",Font.PLAIN,12));
seeItem2.setFont(new Font("宋體",Font.PLAIN,12));
seeItem3.setFont(new Font("宋體",Font.PLAIN,12));
/**
* 幫助欄
*/
help1 = new JMenuItem("幫助主題(H)");
help2 = new JMenuItem("關於計算器(A)");
help1.setFont(new Font("宋體",Font.PLAIN,12));
help2.setFont(new Font("宋體",Font.PLAIN,12));
bgb = new ButtonGroup();//選項組
menu1.add(editItem1);
menu1.add(editItem2);
menu2.add(seeItem1);
menu2.add(seeItem2);
menu2.addSeparator();//添加一條分割線
menu2.add(seeItem3);
menu3.add(help1);
menu3.addSeparator();//添加一條分割線
menu3.add(help2);
myBar.add(menu1);
myBar.add(menu2);
myBar.add(menu3);
this.setJMenuBar(myBar);
numActionListener = new Num();//實現數字監聽
/**
* 文本域,即為計算器的屏幕顯示區域
*/
tf = new JTextField();
tf.setEditable(false);//文本區域不可編輯
tf.setBackground(Color.white);//文本區域的背景色
tf.setHorizontalAlignment(JTextField.RIGHT);//文字右對齊
tf.setText("0");
tf.setBorder(BorderFactory.createLoweredBevelBorder());
init();//對計算器進行初始化
}
/**
* 初始化操作
* 添加按鈕
*/
private void init(){
addButton(panel1, "Backspace", new Clear(), Color.red);
addButton(panel1, "CE", new Clear(), Color.red);
addButton(panel1, "C", new Clear(), Color.red);
addButton(panel2, "1/x", new Signs(), Color.magenta);
addButton(panel2, "log", new Signs(), Color.magenta);
addButton(panel2, "7", numActionListener, Color.blue);
addButton(panel2, "8", numActionListener, Color.blue);
addButton(panel2, "9", numActionListener, Color.blue);
addButton(panel2, "÷", new Signs(), Color.red);
addButton(panel2, "n!", new Signs(), Color.magenta);
addButton(panel2, "sqrt", new Signs(), Color.magenta);
addButton(panel2, "4", numActionListener, Color.blue);
addButton(panel2, "5", numActionListener, Color.blue);
addButton(panel2, "6", numActionListener, Color.blue);
addButton(panel2, "×", new Signs(), Color.red);
addButton(panel2, "sin", new Signs(), Color.magenta);
addButton(panel2, "x^2", new Signs(), Color.magenta);
addButton(panel2, "1", numActionListener, Color.blue);
addButton(panel2, "2", numActionListener, Color.blue);
addButton(panel2, "3", numActionListener, Color.blue);
addButton(panel2, "-", new Signs(), Color.red);
addButton(panel2, "cos", new Signs(), Color.magenta);
addButton(panel2, "x^3", new Signs(), Color.magenta);
addButton(panel2, "0", numActionListener, Color.blue);
addButton(panel2, "-/+", new Clear(), Color.blue);
addButton(panel2, ".", new Dot(), Color.blue);
addButton(panel2, "+", new Signs(), Color.red);
addButton(panel2, "tan", new Signs(), Color.magenta);
addButton(panel2, "%", new Signs(), Color.magenta);
addButton(panel2, "π", numActionListener, Color.orange);
addButton(panel2, "e", numActionListener, Color.orange);
addButton(panel2, "′″", new Signs(), Color.orange);
addButton(panel2, "=", new Signs(), Color.red);
JButton btns = new JButton("計算器");
btns.setBorder(BorderFactory.createLoweredBevelBorder());
btns.setEnabled(false);//按鈕不可操作
btns.setPreferredSize(new Dimension(20, 20));
panel3.add(btns);//加入按鈕
addButton(panel3, "MC", null, Color.red);
addButton(panel3, "MR", null, Color.red);
addButton(panel3, "MS", null, Color.red);
addButton(panel3, "M+", null, Color.red);
panel4.add(panel1, BorderLayout.NORTH);
panel4.add(panel2, BorderLayout.CENTER);
this.add(tf, BorderLayout.NORTH);
this.add(panel3, BorderLayout.WEST);
this.add(panel4);
pack();
this.setResizable(false);//窗口不可改變大小
this.setLocation(300, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* 統一設置按鈕的的使用方式
* @param panel
* @param name
* @param action
* @param color
*/
private void addButton(JPanel panel, String name, ActionListener action, Color color){
JButton bt = new JButton(name);
panel.add(bt);//在面板上增加按鈕
bt.setForeground(color);//設置前景(字體)顏色
bt.addActionListener(action);//增加監聽事件
}
/**
* 計算器的基礎操作(+ - × ÷)
* @param x
*/
private void getResult (double x){
if(oper == "+"){result += x;}
else if(oper == "-"){result -= x;}
else if(oper == "×"){result *= x;}
else if(oper == "÷"){result /= x;}
else if(oper == "="){result = x;}
tf.setText(df.format(result));
}
/**
* 運算符號的事件監聽
*/
class Signs implements ActionListener{
public void actionPerformed(ActionEvent e) {
/*
* 用ActionEvent對象的getActionCommand()方法
* 取得與引發事件對象相關的字元串
*/
String str = e.getActionCommand();
/* sqrt求平方根 */
if(str.equals("sqrt")){
double i = Double.parseDouble(tf.getText());
if(i>=0){
/*
* String.valueOf() 轉換為字元串
* df.format() 按要求保留四位小數
* Math.sqrt() 求算數平方根
*/
tf.setText(String.valueOf(df.format(Math.sqrt(i))));
}
else{
tf.setText("負數不能開平方根");
}
}
/* log求常用對數 */
else if(str.equals("log")){
double i = Double.parseDouble(tf.getText());
if(i>0){
tf.setText(String.valueOf(df.format(Math.log(i))));
}else{
tf.setText("負數不能求對數");
}
}
/* %求百分比 */
else if(str.equals("%")){
tf.setText(df.format(Double.parseDouble(tf.getText()) / 100));
}
/* 1/x求倒數 */
else if(str.equals("1/x")){
if(Double.parseDouble(tf.getText()) == 0){
tf.setText("除數不能為零");
}else{
tf.setText(df.format(1 / Double.parseDouble(tf.getText())));
}
}
/* sin求正弦函數 */
else if(str.equals("sin")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(Math.sin(i))));
}
/* cos求餘弦函數 */
else if(str.equals("cos")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(Math.cos(i))));
}
/* tan求正切函數 */
else if(str.equals("tan")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(Math.tan(i))));
}
/* n!求階乘 */
else if(str.equals("n!")){
double i = Double.parseDouble(tf.getText());
if((i%2==0)||(i%2==1))//判斷為整數放進行階乘操作
{
int j = (int)i;//強制類型轉換
int result=1;
for(int k=1;k<=j;k++)
result *= k;
tf.setText(String.valueOf(result));
}
else
{
tf.setText("無法進行階乘");
}
}
/* x^2求平方 */
else if(str.equals("x^2")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(i*i)));
}
/* x^3求立方 */
else if(str.equals("x^3")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(i*i*i)));
}
/* ′″角度轉換 */
/**
* 將角度值轉換成弧度值,方便三角函數的計算
*/
else if(str.equals("′″")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(i/180*Math.PI));
}
else{
if(flag){
IfResult = false;
}
if(IfResult){
oper = str;
}else{
getResult(Double.parseDouble(tf.getText()));
oper = str;
IfResult = true;
}
}
}
}
/**
* 清除按鈕的事件監聽
*/
class Clear implements ActionListener{
public void actionPerformed(ActionEvent e) {
/*
* 用ActionEvent對象的getActionCommand()方法
* 取得與引發事件對象相關的字元串
*/
String str = e.getActionCommand();
if(str == "C"){
tf.setText("0");
IfResult = true;
result = 0;
}else if(str == "-/+"){
double i = 0 - Double.parseDouble(tf.getText().trim());
tf.setText(df.format(i));
}else if(str == "Backspace"){
if(Double.parseDouble(tf.getText()) > 0){
if(tf.getText().length() > 1){
tf.setText(tf.getText().substring(0, tf.getText().length() - 1));
//使用退格刪除最後一位字元
}else{
tf.setText("0");
IfResult = true;
}
}else{
if(tf.getText().length() > 2){
tf.setText(tf.getText().substring(0, tf.getText().length() - 1));
}else{
tf.setText("0");
IfResult = true;
}
}
}else if(str == "CE"){
tf.setText("0");
IfResult = true;
}
}
}
/**
* 數字輸入的事件監聽
*/
class Num implements ActionListener{
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(IfResult){
tf.setText("");
IfResult = false;
}
if(str=="π")
{
tf.setText(String.valueOf(Math.PI));
}
else if(str=="e")
{
tf.setText(String.valueOf(Math.E));
}
else{
tf.setText(tf.getText().trim() + str);
if(tf.getText().equals("0")){
tf.setText("0");
IfResult = true;
flag = true;
}
}
}
}
/**
* 小數點的事件監聽
*/
class Dot implements ActionListener{
public void actionPerformed(ActionEvent e) {
IfResult = false;
if(tf.getText().trim().indexOf(".") == -1){
tf.setText(tf.getText() + ".");
}
}
}
/**
* main方法
*/
public static void main(String[] args) {
new Calcutor().setVisible(true);
}
}
2. 什麼是編程計算器
非編程的只有簡單的函數功能。編程計算器,支持變數定義,臨時結果存儲等,支持變數拖放操作,程序步數高達4000步以上,具備常用科學函數,程序計算速度極快。支持疊代運算,可以用於日常復雜的計算以及工程運算。
為了解決使用機器語言編寫應用程序所帶來的一系列問題,人們首先想到使用助記符號來代替不容易記憶的機器指令,這種助記符號來表示計算機指令的語言稱為符號語言,也稱匯編語言。
在匯編語言中,每一條用符號來表示的匯編指令與計算機機器指令一一對應;記憶難度大大減少了,不僅易於檢查和修改程序錯誤,而且指令、數據的存放位置可以由計算機自動分配。
(2)科學編程計算器擴展閱讀:
使用匯編語言編寫計算機程序,程序員仍然需要十分熟悉計算機系統的硬體結構,所以從程序設計本身上來看仍然是低效率的、繁瑣的。
但正是由於匯編語言與計算機硬體系統關系密切,在某些特定的場合,如對時空效率要求很高的系統核心程序以及實時控製程序等,迄今為止匯編語言仍然是十分有效的程序設計工具。
但它有不可替代的特性,比如一些單片機或者一些直接控制硬體的程序就一定要用匯編語言。
3. 科學計算器和函數計算器的區別
函數科學計算器主要是給學生使用的,包括小學高年級,初中高中和大學,主要完成的部分是基本代數計算,統計計算,回歸計算,簡單的方程,矩陣和函數賦值等功能,和課本上的指示類似,例如82ES 991ES。高級的圖形科學計算器帶編程和函數圖像功能 ,例如9750,9860等。函數工程計算器主要是面向工程師的,除了基本的功能,都帶有編程(以工程為主)功能,26個變數和數據傳遞功能,例如5800等
4. 科學計算器怎麼編程
如果你說的是電腦系統中自帶的科學計數器的話,那東西沒有編程功能,只有對不同進制的數進行輔助計算的功能,如果是其他的計算器可以查看產品說明書或網路相關資料。
5. 用可編程科學計算器,怎樣編寫灰色預測模型GM(1,1)程序
分享興趣,傳播快樂,增長見聞,留下美好!親愛的您,這里是LearningYard學苑。
今天小編為大家帶來《快速上手灰色系統理論GM(1,1)模型》,一起來看看吧!
快速上手灰色系統理論GM(1,1)模型
01:53來自LearningYard學苑
多圖預警!建議連接WIFI閱讀!
【1】研究背景
灰色系統理論是由我國著名學者鄧聚龍教授創立,是中國原創學科,是確定性理論和系統科學領域的重要學科。我們稱部分信息已知,部分信息不明確的系統為灰色系統,通過對少量信息的累加、累減等計算處理,獲取有價值的部分,實現對灰色系統變化趨勢的預測,或者對當前系統狀況的准確監控。如今灰色系統理論已經進過了將近40年的發展完善,成果豐碩,在理論體系和模型框架方面已經比較完善,參數優化和計算方法等方面都有了相當大的改進,已形成包含了系統分析、預測、優化等技術體系,在許多學科領域得到了廣泛的應用。
GM(1,1)模型作為灰色系統理論重要組成部分,適合於小樣本數據的預測,在樣本缺乏導致信息不足的情況下能充分利用所觀察到的決策信息,給出較高精度的預測結果。GM(1,1)模型的思想是對最開始的數據進行一次累加生成數據序列,新的數據序列相應的曲線可以應用特定曲線無限逼近,把逼近曲線作為基礎模型,將預測值做幾次滾動累加還原,以預測出發展趨勢。
【2】基礎概念
(1)灰色系統
灰色系統介於黑色系統與白色系統之間,稱部分信息已知、另部分信息未知,且內部各因素間有不確定的關系的系統為灰色系統。
(2)灰色預測
灰色預測是通過少量的、不完全的信息,建立數學模型做出預測的一種預測方法。該方法基於客觀事物的過去和現在的發展規律,對未來的發展趨勢和狀況進行描述和分析,並形成科學的假設和判斷。其中GM(1,1)模型就是灰色預測中的強力工具之一。
(3)GM(1,1)模型
該模型中,G表示Grey,M表示Model,括弧中第一個1代表一階微分方程,第二個1代表微分方程有一個變數。同理,灰色預測理論中GM(1,2)表示有兩個變數的一階微分方程灰色模型。
【3】基於GM(1,1)模型的灰色預測步驟
令不完全信息非負序列為X(0),生成1-AGO(1-Accumulating Generation Operational)序列X(1)。1-AGO序列類似帕累托圖中的累加折線。
利用高數知識構建GM(1,1)模型的灰色微分方程,其中a為發展系數,b為灰色作用量。通過公式得到均值形式的GM(1,1)模型Z(1)。
構建灰色預測矩陣:
通過最小二乘法構建函數,並求出估計值:
GM(1,1)模型的白化微分方程為:
得到在公式(1)條件下時間響應函數,並對公式(7)進行計算,得到模擬預測序列。
【英語學習】
Grey system theory was founded by the famous Chinese scholar Professor Deng Julong. It is an original subject in China and an important subject in the field of deterministic theory and systems science. We call a system with some known information and some unclear information as a gray system. By accumulating and subtracting a small amount of information, we can obtain valuable parts to predict the changing trend of the gray system or the current system status. Accurate monitoring. Now the grey system theory has been developed and perfected for nearly 40 years, with fruitful results. It has been relatively complete in terms of theoretical system and model framework, and considerable improvements have been made in parameter optimization and calculation methods, and it has been formed to include system analysis. Technical systems such as, forecasting, and optimization have been widely used in many disciplines. As an important part of gray system theory, GM(1,1) model is suitable for the prediction of small sample data. It can make full use of the observed decision information when the lack of samples leads to insufficient information, and give high-precision prediction results . The idea of the GM(1,1) model is to accumulate the initial data once to generate a data sequence. The corresponding curve of the new data sequence can be approximated infinitely by a specific curve. The approximate curve is used as the basic model and the predicted value is rolled several times. Accumulate rection to predict the development trend.
本期的分享就到這里,如果您對今天的文章有獨特的想法,歡迎給我們留言,讓我們相約明天,祝您今天過得開心快樂!
本文由LearningYard學苑原創,僅代表作者個人觀點,如有侵權請聯系刪除。
翻譯參考來源:Google翻譯。
內容參考來源:
[1] Liu S , Yin C , Cao D . Weapon equipment management cost prediction based on forgetting factor recursive GM (1,1) model[J]. Grey Systems Theory & Application, 2019, 10(1):38-45.
6. 計算機上面的 科學計算器怎麼設置
這是科學計演算法的結果,數學中我們可以叫做指數。
通過結果我們可以得知這是1.0689……×10的-37次方,計算的結果也就是1.0689的小數點往前移37位,0.000000……151。
1、點擊開始——所有程序——附件——計算器打開即可。
打開計算器程序後,我們可以看到常用的頁面顯示出來了,那麼下面我們來設置科學計算器,找到上方的「查看」功能並打開選擇「科學型」。
e-37表示n(10)得-37次方,e37表示n(10)得37次方。e一般在編程中表示科學計演算法,我們經常說得win7,win10也是編程所編寫得。
7. 手機上的科學計算器度分秒怎麼輸入
科學計算器鍵盤一般不能直接輸入度或分或秒,這是因為它內部使用的是弧度制,所以在計算之前,需要將度分秒轉化為對應的弧度,再進行計算。為計算的更加方便,可以下載功能強大的科學計算器。
第1,在手機上安裝名稱叫作易歷知食的軟體。
第2,打開該軟體,點左下角的「開始」,再點「應用程序」,再點「可編程計算器」,此時計算器已經打開,可以進行計算了。第3,將度分秒轉化為弧度。
這里展示兩種方式:方式一,使用計算器內置的rad角度轉換函數來直接計算
方式二,使用計算器內置的rad角度轉換函數並結合編程來計算(這種方式可以計算復雜的問題),先點擊「編程區」,並輸入角度轉換的變數(d表示度對應的弧度,f表示分對應的弧度,m表示秒對應的弧度),之後計算
計算器中輸入度分秒方法:百
具體步驟如下(以輸入度30度24分32秒為例):
首先輸入
輸入30,按「。,,,「鍵(該鍵左上角標記FACT,右上角標記B,以fx-82ES機型為主)表問示30度;
然後輸入24,再按「。,,,「鍵;
最後輸入32,按「。,,,「鍵。
註:答如果是30度零32秒,需要輸入0分,即輸入的應該是30度0分32秒;如果是30度24分,則只需要進專行到上述第二部即可!