ProjectsForTest/WinForm.NET5TeeChart-NET-Pro-Samples/Functions/CurveFitting_Models.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
#if VS2005
using System.Collections.Generic;
#endif
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart.Functions;

namespace Steema.TeeChart.Samples
{
    public class CurveFitting_Models : Steema.TeeChart.Samples.BaseForm
    {
        public CurveFitting_Models()
        {
            InitializeComponent();
            points1.Add(1.1, 1);
            points1.Add(1.2, 2.5);
            points1.Add(1.25, 4);
            points1.Add(1.3, 3);
            points1.Add(1.9, 5.5);
            points1.Add(2.1, 6.2);
            points1.Add(2.2, 6.6);
            points1.Add(2.4, 7.2);
            points1.Add(3, 8);
            points1.Add(3.5, 12);
        }

        private bool FitModel(Steema.TeeChart.Styles.Series source, ref double[] yhat, out double[] coeffs, int modelindex)
        {
            double[] y = new double[source.Count];
            double[] x = new double[source.Count];
            double[] w = new double[source.Count];
            bool validmodel = true;

            switch (modelindex)
            {
                case 0:
                    // y(x)=a*Exp(b*x)
                    // linear model: ln(y) = b*x + ln(a)
                    for (int i = 0; i < source.Count; i++)
                    {
                        x[i] = source.notMandatory[i];
                        y[i] = Math.Log(source.mandatory[i]);
                        w[i] = source.mandatory[i] * source.mandatory[i];
                    }
                    Regression.LinearRegression(source.Count, x, y, w, out coeffs);
                    coeffs[0] = Math.Exp(coeffs[0]);
                    for (int i = 0; i < source.Count; i++)
                    {
                        yhat[i] = coeffs[0] * Math.Exp(coeffs[1] * x[i]);
                    }
                    break;
                case 1: 
                    // Power model y=a*x^b
                    // linear model : ln(y) = b*ln(x) + ln(a)
                    for (int i = 0; i < source.Count; i++)
                    {

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。