{"id":1215,"date":"2010-07-22T20:55:00","date_gmt":"2010-07-22T12:55:00","guid":{"rendered":""},"modified":"2013-11-17T12:05:06","modified_gmt":"2013-11-17T04:05:06","slug":"%e6%8b%89%e6%a0%bc%e6%9c%97%e6%97%a5%e5%86%85%e6%8f%92c%e7%89%88","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1215.html","title":{"rendered":"\u62c9\u683c\u6717\u65e5\u5185\u63d2C#\u7248"},"content":{"rendered":"<p>\u628a\u4ee5\u524d\u5199\u7684\u90a3\u4e2aDelphi\u7248\u672c\u7ffb\u8bd1\u6210\u4e86C#\u8bed\u8a00\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.ComponentModel;\r\nusing System.Data;\r\nusing System.Drawing;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Windows.Forms;\r\n\r\nnamespace \u62c9\u683c\u6717\u65e5\u5185\u63d2\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n        }\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/ \u62c9\u683c\u6717\u65e5\u5185\u63d2\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=&quot;fx&quot;&gt;x\u5e8f\u5217&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;fy&quot;&gt;y\u5e8f\u5217&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;xx&quot;&gt;\u8981\u63d2\u503c\u7684x\u5e8f\u53f7&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=&quot;n&quot;&gt;\u9636\u6570&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public double lagrange(double&#x5B;] fx, double&#x5B;] fy, double xx, int n)\r\n        {\r\n            double&#x5B;] a = new double&#x5B;n + 1];\r\n            double&#x5B;] fx2 = new double&#x5B;n + 1];\r\n            double&#x5B;] fy2 = new double&#x5B;n + 1];\r\n            int sum1 = 0;\r\n            int half_n = n \/ 2;\r\n            int len = fx.Length - 1;\r\n            \/\/===================BEGIN=========\u53d6nn\u4e2a\u6570\u53c2\u4e0e\u63d2\u503c\uff0c\u4f7f\u8981\u6c42\u7684\u6570\u5728\u5176\u4e2d\u95f4========\r\n            int st_n = Convert.ToInt32(Math.Truncate(xx - fx&#x5B;0])) \/ (15 * 60); \/\/\u65f6\u95f4\u5904\u4e8e\u7b2c\u51e0\u4e2a15\u5206\u949f\r\n            if (st_n &gt;= len)   \/\/\u8d85\u51fa\u6240\u6709\r\n            {\r\n                for (int j = len - n; j &lt;= len; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n            }\r\n            else if (st_n &lt;= 0)  \/\/\u4f4e\u4e8e\u6240\u6709\r\n            {\r\n                for (int j = 0; j &lt;= n; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n            }\r\n            else if (len - st_n &lt; half_n)  \/\/\u53f3\u8fb9\u4e0d\u591f\r\n            {\r\n                for (int j = st_n; j &lt;= len; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n                for (int j = len - n + 1; j &lt;= st_n; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j - 1];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j - 1];\r\n                    sum1++;\r\n                }\r\n            }\r\n            else if (st_n &lt; (n \/ 2))   \/\/\u5de6\u8fb9\u4e0d\u591f\r\n            {\r\n                for (int j = 0; j &lt;= st_n; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n                for (int j = st_n + 1; j &lt;= n; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n            }\r\n            else   \/\/\u4e24\u8fb9\u90fd\u591f\r\n            {\r\n                for (int j = (st_n - (n \/ 2)); j &lt;= st_n; j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n                for (int j = st_n + 1; j &lt;= st_n + n - (n \/ 2); j++)\r\n                {\r\n                    fx2&#x5B;sum1] = fx&#x5B;j];\r\n                    fy2&#x5B;sum1] = fy&#x5B;j];\r\n                    sum1++;\r\n                }\r\n            }\r\n            \/\/========================END======\u53d6nn\u4e2a\u6570\u53c2\u4e0e\u63d2\u503c\uff0c\u4f7f\u8981\u6c42\u7684\u6570\u5728\u5176\u4e2d\u95f4========\r\n            double yy = 0;\r\n            for (int i = 0; i &lt;= n; i++)\r\n            {\r\n                a&#x5B;i] = fy2&#x5B;i];\r\n                for (int j = 0; j &lt;= n; j++)\r\n                {\r\n                    if (j != i)\r\n                    {\r\n                        a&#x5B;i] = a&#x5B;i] * (xx - fx2&#x5B;j]) \/ (fx2&#x5B;i] - fx2&#x5B;j]);\r\n                    }\r\n                }\r\n                yy = yy + a&#x5B;i];\r\n            }\r\n            return yy;\r\n        }\r\n        \/\/\u51fd\u6570\u6d4b\u8bd5\r\n        private void button1_Click(object sender, EventArgs e)\r\n        {\r\n            int N = 4;\r\n            double&#x5B;] fx = new double&#x5B;5] { 0.4, 0.55, 0.8, 0.9, 1 };\r\n            double&#x5B;] fy = new double&#x5B;5] { 0.41075, 0.57815, 0.88811, 1.02652, 1.17520 };\r\n            double x = 0.5;\r\n            MessageBox.Show(lagrange(fx, fy, x, N).ToString());\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u628a\u4ee5\u524d\u5199\u7684\u90a3\u4e2aDelphi\u7248\u672c\u7ffb\u8bd1\u6210\u4e86C#\u8bed\u8a00\u3002 using System; using System.Col [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1215","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1215"}],"version-history":[{"count":4,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1215\/revisions"}],"predecessor-version":[{"id":4575,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1215\/revisions\/4575"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}