• 大小: 73KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: C#
  • 标签: C#  

资源简介

通过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;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace WindowsFormsApplication3
{

    public partial class Form1 : Form
    {
        double[] X = new double[5]{12345};//get data
        double[] Y = new double[5] {12345 };
        double a=0;
        double b=0;
        
        public Form1()
        {

            InitializeComponent();


        }
        private void button1_Click(object sender EventArgs e)
        {
           
           
            double sumX = 0;
            double sumY = 0;
            double sumx = 0;
            double sumy = 0;
            double sumxy = 0;
           
            double s=0;
            double r = 0;
            string str = null;

            for (int i = 0; i < 5; i++)
            {

                sumX = sumX + X[i];
                sumY = sumY + Y[i];
                sumx = sumx + X[i] * X[i];
                sumy = sumy + Y[i] * Y[i];
                sumxy = sumxy + X[i] * Y[i];
            }
          
           a = sumxy/sumx;//calculate k
           for(int i=0;i<5;i++){
           s=s+(Y[i]-a*X[i])*(Y[i]-a*X[i]);//标准差
           
           }
           b = a * a / (4 * 5 * s + a * a);//决定系数
           r = sumxy / Math.Sqrt(sumx*sumy);//相关系数
          
            
            str = “y=“ + a.ToString(“0.000“) + “*x“;
            this.textBox1.Text = a.ToString(“0.000“);
            this.textBox2.Text = b.ToString(“0.000“);
            this.textBox3.Text = r.ToString(“0.000“);

            this.textBox4.Text = “y=“ + a.ToString(“0.000“) + “*x“;
           
            
        }



        private void panel1_Paint(object sender PaintEventArgs e)
        {

                Graphics g = e.Graphics;
                Pen pn1 = new Pen(Color.Red);
                Pen pn2 = new Pen(Color.Black);
                Point p1 = new Point(50 300);
                Point p2 = new Point(50 20);
                Point p3 = new Point(50 300);
                Point p4 = new Point(350 300);
                //原点50300
                g.DrawLine(pn2 p1 p2);
                g.DrawLine(pn2 p3 p4);
                Font fnt = new Font(“Verdana“ 9);
                g.DrawString(“▶“ fnt new SolidBrush(Color.Black) 343 292);
                g.DrawString(“▲“ fnt new SolidBrush(Color.Black) 42 8);
                g.DrawString(“Y“ fnt new SolidBrush(Color.Black) 5 150);
                g.DrawString(“轴“ fnt new SolidBrush(Color.Black) 5 165);
                g.DrawString(“X轴“ fnt new SolidBrush(Color.Black) 200 320);
                g.DrawString(“饱和度—电阻增大率“fntnew SolidBrush (Color.Black)20010);
                for (int i = 0; i < 10; i++)
                {
                    Point p5 =

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12288  2014-09-08 11:06  加权\WindowsFormsApplication3\bin\Debug\WindowsFormsApplication3.exe

     文件      32256  2014-09-08 11:06  加权\WindowsFormsApplication3\bin\Debug\WindowsFormsApplication3.pdb

     文件      11592  2014-09-10 10:16  加权\WindowsFormsApplication3\bin\Debug\WindowsFormsApplication3.vshost.exe

     文件      11776  2014-09-30 10:26  加权\WindowsFormsApplication3\bin\Release\WindowsFormsApplication3.exe

     文件      32256  2014-09-30 10:26  加权\WindowsFormsApplication3\bin\Release\WindowsFormsApplication3.pdb

     文件      11592  2014-10-29 15:41  加权\WindowsFormsApplication3\bin\Release\WindowsFormsApplication3.vshost.exe

     文件        490  2009-06-11 05:14  加权\WindowsFormsApplication3\bin\Release\WindowsFormsApplication3.vshost.exe.manifest

     文件       4035  2014-09-16 12:09  加权\WindowsFormsApplication3\Form1.cs

     文件       7610  2013-09-09 16:41  加权\WindowsFormsApplication3\Form1.Designer.cs

     文件       5814  2013-09-09 16:41  加权\WindowsFormsApplication3\Form1.resx

     文件       3761  2014-09-10 10:16  加权\WindowsFormsApplication3\obj\Debug\WindowsFormsApplication3.csproj.FileListAbsolute.txt

     文件        847  2014-09-04 09:51  加权\WindowsFormsApplication3\obj\Debug\WindowsFormsApplication3.csproj.GenerateResource.Cache

     文件      12288  2014-09-08 11:06  加权\WindowsFormsApplication3\obj\Debug\WindowsFormsApplication3.exe

     文件        180  2014-09-08 11:06  加权\WindowsFormsApplication3\obj\Debug\WindowsFormsApplication3.Form1.resources

     文件      32256  2014-09-08 11:06  加权\WindowsFormsApplication3\obj\Debug\WindowsFormsApplication3.pdb

     文件        180  2014-09-08 11:06  加权\WindowsFormsApplication3\obj\Debug\WindowsFormsApplication3.Properties.Resources.resources

     文件       2318  2014-10-29 15:41  加权\WindowsFormsApplication3\obj\Release\WindowsFormsApplication3.csproj.FileListAbsolute.txt

     文件        847  2013-09-09 16:41  加权\WindowsFormsApplication3\obj\Release\WindowsFormsApplication3.csproj.GenerateResource.Cache

     文件      11776  2014-09-30 10:26  加权\WindowsFormsApplication3\obj\Release\WindowsFormsApplication3.exe

     文件        180  2014-09-10 10:16  加权\WindowsFormsApplication3\obj\Release\WindowsFormsApplication3.Form1.resources

     文件      32256  2014-09-30 10:26  加权\WindowsFormsApplication3\obj\Release\WindowsFormsApplication3.pdb

     文件        180  2014-09-10 10:16  加权\WindowsFormsApplication3\obj\Release\WindowsFormsApplication3.Properties.Resources.resources

     文件        505  2014-08-11 09:50  加权\WindowsFormsApplication3\Program.cs

     文件       1380  2014-08-11 09:50  加权\WindowsFormsApplication3\Properties\AssemblyInfo.cs

     文件       2898  2014-08-11 09:50  加权\WindowsFormsApplication3\Properties\Resources.Designer.cs

     文件       5612  2014-08-11 09:50  加权\WindowsFormsApplication3\Properties\Resources.resx

     文件       1109  2014-08-11 09:50  加权\WindowsFormsApplication3\Properties\Settings.Designer.cs

     文件        249  2014-08-11 09:50  加权\WindowsFormsApplication3\Properties\Settings.settings

     文件       3794  2014-09-08 11:06  加权\WindowsFormsApplication3\WindowsFormsApplication3.csproj

     文件        962  2014-08-11 09:50  加权\WindowsFormsApplication3.sln

............此处省略16个文件信息

评论

共有 条评论