博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
线性差值法结构类(面向对象的方式)
阅读量:6469 次
发布时间:2019-06-23

本文共 4275 字,大约阅读时间需要 14 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using User1.Valuation.Holworth.EngineInfrastructure;namespace ConsoleApplication7{    public enum PointState    {        Inner = 0,//定义域的点        Mid = 1,//未超出定义域的点        LeftOuter = 2,//超出左侧        RightOuter = 3//超出右侧    }    public class Point    {        public Point Left;        public Point Right;        public double x;        public double y;        public PointState state;    }    class Program    {        static void Main(string[] args)        {                      List
list1 = new List
(); List
list2 = new List
(); for (int i = 0; i < 10; i++) { byte[] buffer = Guid.NewGuid().ToByteArray(); int iSeed = BitConverter.ToInt32(buffer, 0); Random r = new Random(iSeed); list1.Add(r.Next(1,100)); list2.Add(r.Next(1,100)); } double[] xarr; double[] yarr; xarr = list1.ToArray(); yarr = list2.ToArray(); //求解的点 double[] x1arr = new double[] { 1, 2, 3, 4, 6, 8, 11, 13, 14, 16, 17 }; double[] y1arr; Dictionary
pointDictionary = new Dictionary
(); int m = 1* 1; DateTime t1 = DateTime.Now; for (int i = 0; i < m; i++) { pointDictionary = LineDifferenceMethod(xarr, yarr, x1arr,out y1arr, true); } DateTime t2 = DateTime.Now; Console.WriteLine("勇士:"+t2.Subtract(t1).TotalSeconds); foreach (var item in pointDictionary) { Console.WriteLine(item.Key + "\t" + item.Value.y); } Console.Read(); } ///
/// 线性差值法 /// ///
原始数据x轴 ///
原始数据y轴 ///
求解的x轴的点的数组 ///
边缘点是否使用斜率延伸 ///
public static Dictionary
LineDifferenceMethod(double[] xarr, double[] yarr, double[] x1arr,out double[] y1arr, bool extension = false) { Dictionary
pointDict = new Dictionary
(); for (int i = 0; i < xarr.Length; i++) { Point p = new Point(); p.x = xarr[i]; p.y = yarr[i]; p.state = PointState.Inner; pointDict[p.x] = p; } for (int i = 0; i < x1arr.Length; i++) { if (pointDict.ContainsKey(x1arr[i])) { continue; } Point p = new Point(); p.x = x1arr[i]; p.state = PointState.Mid;//默认值 pointDict[p.x] = p; } var orderbylist = pointDict.OrderBy(p => p.Key).ToList(); pointDict=orderbylist.ToDictionary(p=>p.Key,p=>p.Value); var oriList = orderbylist.Where(p => p.Value.state== PointState.Inner).Select(p=>p.Value).ToArray(); Point firstPoint = oriList[0]; ; Point lastPoint = oriList[oriList.Length-1]; if (xarr.Length== 1) { for (int i = 0; i < x1arr.Length; i++) { Point p = new Point(); p.x = x1arr[i]; p.y = yarr[0]; if (p.x != xarr[0]) { if (p.x < xarr[0]) { p.state = PointState.LeftOuter; } else if (p.x > xarr[0]) { p.state = PointState.RightOuter; } } } y1arr = new double[x1arr.Length]; for (int i = 0; i < x1arr.Length; i++) { y1arr[i] = yarr[0]; pointDict[x1arr[i]].y = y1arr[i]; } return pointDict; } for (int i = 0; i < x1arr.Length; i++) { double qx = x1arr[i]; Point p = pointDict[qx]; if (qx < firstPoint.x) { p.state = PointState.LeftOuter; } else if (qx > lastPoint.x) { p.state = PointState.RightOuter; } else if (pointDict.ContainsKey(qx)) { //内部点不用求了 p = pointDict[qx]; continue; } else { p.state = PointState.Mid; } } var points = pointDict.Values.ToArray(); for (int i = 0; i < points.Length; i++) { Point p = points[i]; if (i == 0) { p.Left = null; if (points.Length > 1) { p.Right = points[i + 1]; } else { p.Right = null; } } else if (i == points.Length - 1) { p.Right = null; if (points.Length > 1) { p.Left = points[i - 1]; } else { p.Right = null; } } else if (i > 0 && i < points.Length - 1) { p.Left = points[i - 1]; p.Right = points[i + 1]; } } //foreach (var item in points) for(int i=0;i
x1arr.Contains(p.Key)).Select(x => x.Value.y).ToArray(); return pointDict; } private static void AdjustLeftRight(ref Point right, ref Point left, Point item) { while (right.state != PointState.Inner) { right = right.Right; } while (left.state != PointState.Inner) { left = left.Left; } double k = (right.y - left.y) / (right.x - left.x);//斜率 item.y = left.y + k * (item.x - left.x); } }}

 

转载于:https://www.cnblogs.com/kexb/p/9241474.html

你可能感兴趣的文章
i4o开源项目增强LINQ索引功能
查看>>
蔡超:入门 Go 语言必须跨越的五个思维误区
查看>>
使用Akka Actor和Java 8构建反应式应用
查看>>
curl常用命令详解
查看>>
saltstack 添加计划任务
查看>>
Puppet module命令参数介绍(六)
查看>>
《UNIX网络编程》中第一个timer_server的例子
查看>>
CISCO 路由器(4)
查看>>
网络服务搭建、配置与管理大全(Linux版)
查看>>
Silverlight 5 Beta新特性[4]文本缩进控制
查看>>
springMVC多数据源使用 跨库跨连接
查看>>
简单java在线测评程序
查看>>
录音和朗诵的实现
查看>>
Git服务端和客户端安装笔记
查看>>
Spring Security(14)——权限鉴定基础
查看>>
云安全与IT系统漏洞管理成为IT决策者最关注的话题
查看>>
2016年全球光纤需求量将达4.25亿芯公里 中国占57%决定产业格局
查看>>
MaxCompute UDF系列之拼音转换
查看>>
《JavaScript和jQuery实战手册(原书第2版)》——2.2节内置函数
查看>>
部署混合云指南:多云服务商管理的八大要素
查看>>