1、灵敏度分析C#程序代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 灵敏度分析尝试 public partial class Form1 : Form public Form1() InitializeComponent(); public bool jiansuo(dou
2、ble x, double y) bool cunzai = false; ; for (int i = 0; i y.Length; i+) if (yi = x) cunzai = true; return cunzai; public double qiumax(List array) double max=-9999; for (int i = 0; i max) max = arrayi; return max; public double qiumin(List array) double min = 9999; for (int i = 0; i array.Count; i+)
3、 if (arrayi 0 | dataGridView2.Columns.Count 0 | dataGridView3.Columns.Count 0 | dataGridView4.Columns.Count 0 | dataGridView5.Columns.Count 0) dataGridView1.Columns.Clear(); dataGridView2.Columns.Clear(); dataGridView3.Columns.Clear(); dataGridView4.Columns.Clear(); dataGridView5.Columns.Clear(); if
4、 (dataGridView1.Rows.Count 0 | dataGridView2.Rows.Count 0 | dataGridView4.Rows.Count 0 | dataGridView5.Rows.Count 0) dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); dataGridView3.Rows.Clear(); dataGridView4.Rows.Clear(); dataGridView2.Rows.Clear(); int m, n; m = int.Parse(textBox1production.
5、Text);/m=3 n = int.Parse(textBox2resource.Text);/n=3 for (int i = 1; i = m + n; i+) dataGridView5.Columns.Add( , C + i.ToString(); for (int i = 1; i = m + n; i+) dataGridView4.Columns.Add(, X + i.ToString(); dataGridView4.Rows.Add(n + 1); dataGridView3.Columns.Add( , C); dataGridView1.Columns.Add(,
6、Cb); dataGridView1.Columns.Add(, Xb(下标); dataGridView1.Columns.Add(, B-1b); dataGridView1.Rows.Add(n); dataGridView2.Columns.Add( , C); dataGridView2.Rows.Add(1); private void splitContainer3_SplitterMoved(object sender, SplitterEventArgs e) private void splitContainer6_Panel2_Paint(object sender, P
7、aintEventArgs e) private void button1产品_Click(object sender, EventArgs e) double Xb = new doubledataGridView1.Rows.Count;/用于存放Xb的下标; for (int i = 0; i dataGridView1.Rows.Count; i+) if (dataGridView1.Rowsi.Cells1.Value != null) Xbi = double.Parse(dataGridView1.Rowsi.Cells1.Value.ToString(); double, A
8、 = new doubledataGridView4.Rows.Count, dataGridView4.Columns.Count;/A矩阵存放后面的 for (int i = 0; i dataGridView4.Rows.Count; i+) for (int j = 0; j dataGridView4.Columns.Count; j+) if (dataGridView4.Rowsi.Cellsj.Value != null) Ai, j = double.Parse(dataGridView4.Rowsi.Cellsj.Value.ToString(); int pro=0; i
9、f (textBox3输入产品.Text!=) pro = int.Parse(textBox3输入产品.Text); if (pro int.Parse(textBox1production.Text)+int.Parse (textBox2resource .Text) MessageBox.Show(输入的数据必须大于0小于产品总数+资源数!,请重新输入!); else if (jiansuo(pro, Xb) List zuo = new List(); List you = new List(); double zuomax = 0, youmin = 0; for (int j =
10、 0; j Xb.Length; j+) if (pro = Xbj)/pro是基变量,且第i列是非基变量 for (int i = 0; i 0) shang=AA.GetLength(0) - 1, i / Aj, i; zuo.Add(Math.Round (shang,2); /非基变量的检验数除以Cj(j就是pro)对应的变量Xj那一行 if (Aj, i 0) zuomax = qiumax(zuo); if (you.Count 0) youmin = qiumin(you); if (zuo.Count = 0 & you.Count = 0) textBox1产品结果.Tex
11、t = ; if (zuo.Count 0 & you.Count = 0) textBox1产品结果.Text = 产品 + pro + 的变化量= + Convert.ToString(zuomax); if (zuo.Count = 0 & you.Count 0) textBox1产品结果.Text = 产品 + pro + 的变化量 0 & you.Count 0) textBox1产品结果.Text = 产品 + pro + 的变化范围为 + Convert.ToString(zuomax) + 到 + Convert.ToString(youmin); if (jiansuo(p
12、ro, Xb)=false ) int hangbiao=dataGridView4.Rows .Count-1; if (dataGridView4.Rowshangbiao.Cellspro-1.Value != null) double jieguo = -(double.Parse(dataGridView4.Rowshangbiao.Cellspro -1.Value.ToString(); textBox1产品结果.Text = 产品 + pro + 的变化量= + Convert.ToString(jieguo); private void button资源计算_Click(ob
13、ject sender, EventArgs e) double B_1b = new doubledataGridView1.Rows.Count;/用于存放B-1b列; for (int i = 0; i dataGridView1.Rows.Count; i+) /给XbB_1b赋值 if (dataGridView1.Rowsi.Cells2.Value != null) B_1bi = double.Parse(dataGridView1.Rowsi.Cells2.Value.ToString(); int Res = 0; if (textBox3输入资源.Text != ) Re
14、s = int.Parse(textBox3输入资源.Text); if (Res int.Parse(textBox2resource.Text) MessageBox.Show(输入的数据必须大于0小于等于资源数!,请重新输入!); else double Xnaddi = new doubledataGridView4.Rows.Count-1;/用于存放Xnaddi列 for (int i = 0; i dataGridView4.Rows.Count-1; i+) if (dataGridView4.Rowsi.Cellsint.Parse(textBox1production.Te
15、xt) + Res-1.Value != null) Xnaddii = double.Parse(dataGridView4.Rowsi.Cellsint.Parse(textBox1production.Text) + Res-1.Value.ToString(); double shang = 0; List zuo = new List(); List you = new List(); double zuomax = 0, youmin = 0; for (int i = 0; i 0) shang = -(B_1bi) / Xnaddii; zuo.Add(Math.Round(s
16、hang, 2); /非基变量的检验数除以Cj(j就是pro)对应的变量Xj那一行 if (Xnaddii 0) zuomax = qiumax(zuo); if (you.Count 0) youmin = qiumin(you); if (zuo.Count = 0 & you.Count = 0) textBox2资源结果.Text = ; if (zuo.Count 0 & you.Count = 0) textBox2资源结果.Text = 资源 + Res + 的变化量= + Convert.ToString(zuomax); if (zuo.Count = 0 & you.Cou
17、nt 0) textBox2资源结果.Text = 资源 + Res + 的变化量 0 & you.Count 0) textBox2资源结果.Text = 资源 + Res + 的变化范围为 + Convert.ToString(zuomax) + 到 + Convert.ToString(youmin); private void button1影子价格_Click(object sender, EventArgs e) int m; m = Convert.ToInt32(textBox1production.Text ); int n; n = Convert.ToInt32(text
18、Box2resource.Text ); double Aend = new double dataGridView4.Columns.Count;/A矩阵存放后面的 for (int j = 0; j dataGridView4.Columns.Count; j+) if (dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj.Value != null) Aendj = double.Parse(dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj.Value.ToString();
19、 int resource = 0; if (textBox1输入资源.Text != ) resource = int.Parse(textBox1输入资源.Text); if (resource n) MessageBox.Show(输入的数据必须大于0小于等于资源数!,请重新输入!); if (resource 0 & resource 0 | dataGridView6.Columns.Count 0) dataGridView6.Rows.Clear(); dataGridView6.Columns.Clear(); dataGridView6.Columns.Add( , 单位利润
20、 ); for (int i = 1; i = int.Parse(textBox2resource.Text); i+) dataGridView6.Columns.Add( , 消耗资源 + i.ToString(); dataGridView6.Rows.Add(1); private void splitContainer9_Panel1_Paint(object sender, PaintEventArgs e) private void buttonCount_Click(object sender, EventArgs e) int m, n; m = int.Parse(tex
21、tBox1production.Text);/m=3 n = int.Parse(textBox2resource.Text);/n=3 double A = new doublen;/A矩阵存放后面的 for (int j = 0; j n; j+) if (dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj+m.Value != null) Aj = Math.Abs(double.Parse(dataGridView4.RowsdataGridView4.Rows.Count - 1.Cellsj+m.Value.ToString(
22、); double XbN = new doublen+1; for (int i = 0; i n+1; i+) if (dataGridView6.Rows0.Cellsi.Value != null) XbNi = double.Parse(dataGridView6.Rows0.Cellsi.Value.ToString(); double z = XbN0; for (int i = 0; i 0) textBox1.Text = 生产该商品盈利; else textBox1.Text = 生产该商品亏本; private void button2_Click(object send
23、er, EventArgs e) int i = 0, j = 0; if (textBox6i.Text != & textBox5j.Text != ) i = int.Parse(textBox6i.Text); j = int.Parse(textBox5j.Text); if (j (int.Parse(textBox1production.Text) + int.Parse(textBox2resource.Text) | i int.Parse(textBox2resource.Text) MessageBox.Show(输入的产品必须大于0小于产品总数+资源数;输入的资源必须大
24、于0小于资源数!,请输入正确的数字!); else double shang = 0; double Azuihouyihang = new doubledataGridView4.Columns.Count; for (int n = 0; n 0) i = int.Parse(textBox6i.Text); j = int.Parse(textBox5j.Text); shang = y / Math.Abs(x); textBox4Aij结果.Text = A + i + j + 的变化量= + Convert.ToString(Math.Round(shang, 2); i = int.Parse(textBox6i.Text); j = int.Parse(textBox5j.Text); else textBox4Aij结果.Text = A + i + j + 的变化量为 + R; private void button1产品计算_Click(object sender, EventArgs e)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1