{"id":40,"date":"2005-04-21T15:04:14","date_gmt":"2005-04-21T07:04:14","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/40.aspx"},"modified":"2006-03-26T22:03:41","modified_gmt":"2006-03-26T14:03:41","slug":"%e8%ae%a1%e7%ae%97+Lagrange+%e6%8f%92%e5%80%bc%e7%9a%84C%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/40","title":{"rendered":"\u8ba1\u7b97 Lagrange \u63d2\u503c\u7684C\u7a0b\u5e8f"},"content":{"rendered":"<p>\u597d\u4e45\u6ca1\u5199\u8fc7 C \u7a0b\u5e8f\u4e86\uff0c\u4eca\u5929\u5199\u4e86\u4e00\u4e2a\uff0c\u4e5f\u662f\u8feb\u4e0d\u5f97\u5df2\uff0c\u662f\u8ba1\u7b97\u65b9\u6cd5\u7684\u4f5c\u4e1a\uff0c\u5475\u5475\uff5e\uff5e<br \/>\u8fd9\u4e2a\u7a0b\u5e8f\u7528\u6765\u8ba1\u7b97 Lagrange \u63d2\u503c\uff0c\u8001\u5e08\u8981\u6c42\u8981\u7528\u6570\u7ec4\uff0c\u5076\u5c31\u7528\u6570\u7ec4\u4e86\uff0c\u6709\u70b9\u6d6a\u8d39\u5185\u5b58\u7684\u8bf4\uff0c\u4e0d\u8fc7\u73b0\u5728\u7684\u673a\u5668\u5185\u5b58\u592a\u5927\u4e86\uff0c\u5076\u7684\u90a3\u70b9\u5185\u5b58\u7b97\u4ec0\u4e48\uff0c\u5475\u5475\uff5e\uff5e<br \/>\u7531\u4e8e\u5f88\u4e45\u6ca1\u5199\u4e86\uff0c\u8fd8\u771f\u6709\u70b9\u624b\u751f\uff0c\u5728\u90a3\u4e2a\u5faa\u73af\u90a3\u91cc\u8fd8\u5361\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u6700\u540e\u7ec8\u4e8e\u641e\u6e05\u695a\u662f\u90a3\u51e0\u4e2a\u53d8\u91cf\u6ca1\u6709\u521d\u59cb\u5316\uff0c\u5509\uff0c\u8fd9\u4e48\u4f4e\u7ea7\u7684\u9519\u8bef\uff0c\u6c57\uff5e\uff5e\uff5e[neutral]<\/p>\n<p><pre lang=\"cpp\">\n\/*lagrange.c*\/\n\/*\u8ba1\u7b97Lagrange\u63d2\u503c*\/\n\/*2005\u5e744\u670821\u65e5*\/\n\/*\u4f5c\u8005\uff1aFdream*\/\n\n#include&lt;stdio.h&gt;\n\n\/*\u5b9a\u4e49\u521d\u59cb\u6570\u7ec4\u7684\u5927\u5c0f*\/\n#define M 100\n\n\/*\u4e3b\u51fd\u6570*\/\nvoid main(void){\n\t\/*\u5b9a\u4e49\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u653e\u70b9\u7684\u4fe1\u606f*\/\n\tfloat point[M][2];\n\t\/*\u5b9a\u4e49\u53d8\u91cf*\/\n\tfloat fdx,fdy,fdxx,fdm,fdn,fdyy=0;\n\tint n,i,j,k;\n\t\/*\u8f93\u5165\u70b9\u7684\u4e2a\u6570*\/\n\tprintf(&quot;How many points do you want to input:\\n&quot;);\n\tscanf(&quot;%d&quot;,&amp;n);\n\t\/*\u5224\u65ad\u8f93\u5165\u7684\u70b9\u7684\u4e2a\u6570\u662f\u5426\u5927\u4e8e2*\/\n\tfor(;n&lt;2;){\n\t\tprintf(&quot;The number of points cannot be less than 2 !\\n&quot;);\n\t\tprintf(&quot;How many points do you want to input:\\n&quot;);\n\t\tscanf(&quot;%d&quot;,&amp;n);\n\t}\n\t\/*\u8f93\u5165\u70b9\u7684\u4fe1\u606f;x\u548cf(x)*\/\n\tfor(i=0;i&lt;n;i++){\n\t\tprintf(&quot;point %d:\\n&quot;,i+1);\n\t\tscanf(&quot;%f%f&quot;,&amp;fdx,&amp;fdy);\n\t\tpoint[i][0]=fdx;\n\t\tpoint[i][1]=fdy;\n\t}\n\t\/*\u8f93\u5165\u8981\u63d2\u503c\u7684\u70b9\u7684x\u503c*\/\n\tprintf(&quot;Please input x:\\n&quot;);\n\tscanf(&quot;%f&quot;,&amp;fdxx);\n\t\/*\u8ba1\u7b97\u8fc7\u7a0b*\/\n\tfor(j=0;j&lt;n;j++){\n\t\t\/*\u521d\u59cb\u5316\u5404\u53d8\u91cf\u7684\u503c*\/\n\t\tk=0;\n\t\tfdn=1;\n\t\tfdm=1;\n\t\t\/*\u8ba1\u7b97\u220f(x-xi)\u4e0e\u220f(xi-xj),\u4e0b\u6807\u4ece0\u5230j-1*\/\n\t\tfor(k=0;k&lt;j;k++){\n\t\t\tfdn*=(fdxx-point[k][0]);\n\t\t\tfdm*=(point[j][0]-point[k][0]);\n\t\t}\n\t\tk++;\n\t\t\/*\u8ba1\u7b97\u220f(x-xi)\u4e0e\u220f(xi-xj),\u4e0b\u6807\u4ecej+1\u5230n-1*\/\n\t\tfor(;k&lt;n;k++){\n\t\t\tfdn*=(fdxx-point[k][0]);\n\t\t\tfdm*=(point[j][0]-point[k][0]);\n\t\t}\n\t\t\/*\u8ba1\u7b97\u2211yi(\u220f(x-xi)\/\u220f(xi-xj)),\u4e0b\u6807\u4ece0\u5230n-1*\/\n\t\tfdyy+=(fdn\/fdm)*point[j][1];\n\t}\n\t\/*\u8f93\u51fa\u7ed3\u679c*\/\n\tprintf(&quot;The result is: %f\\n&quot;,fdyy);\n}\n<\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u4e45\u6ca1\u5199\u8fc7 C \u7a0b\u5e8f\u4e86\uff0c\u4eca\u5929\u5199\u4e86\u4e00\u4e2a\uff0c\u4e5f\u662f\u8feb\u4e0d\u5f97\u5df2\uff0c\u662f\u8ba1\u7b97\u65b9\u6cd5\u7684\u4f5c\u4e1a\uff0c\u5475\u5475\uff5e\uff5e\u8fd9\u4e2a\u7a0b\u5e8f\u7528\u6765\u8ba1\u7b97 Lagrange \u63d2\u503c\uff0c\u8001\u5e08\u8981\u6c42\u8981\u7528\u6570\u7ec4\uff0c\u5076\u5c31\u7528\u6570\u7ec4\u4e86\uff0c\u6709\u70b9\u6d6a\u8d39\u5185\u5b58\u7684\u8bf4\uff0c\u4e0d\u8fc7\u73b0\u5728\u7684\u673a\u5668\u5185\u5b58\u592a\u5927\u4e86\uff0c\u5076\u7684\u90a3\u70b9\u5185\u5b58\u7b97\u4ec0\u4e48\uff0c\u5475\u5475\uff5e\uff5e\u7531\u4e8e\u5f88\u4e45\u6ca1\u5199\u4e86\uff0c\u8fd8\u771f\u6709\u70b9\u624b\u751f\uff0c\u5728\u90a3\u4e2a\u5faa\u73af\u90a3\u91cc\u8fd8\u5361\u4e86\u4e00\u6bb5\u65f6\u95f4\uff0c\u6700\u540e\u7ec8\u4e8e\u641e\u6e05\u695a\u662f\u90a3\u51e0\u4e2a\u53d8\u91cf\u6ca1\u6709\u521d\u59cb\u5316\uff0c\u5509\uff0c\u8fd9\u4e48\u4f4e\u7ea7\u7684\u9519\u8bef\uff0c\u6c57\uff5e\uff5e\uff5e[neutral] \/*lagrange.c*\/ \/*\u8ba1\u7b97Lagrange\u63d2\u503c*\/ \/*2005\u5e744\u670821\u65e5*\/ \/*\u4f5c\u8005\uff1aFdream*\/ #include&lt;stdio.h&gt; \/*\u5b9a\u4e49\u521d\u59cb\u6570\u7ec4\u7684\u5927\u5c0f*\/ #define M 100 \/*\u4e3b\u51fd\u6570*\/ void main(void){ \/*\u5b9a\u4e49\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u653e\u70b9\u7684\u4fe1\u606f*\/ float point[M][2]; \/*\u5b9a\u4e49\u53d8\u91cf*\/ float fdx,fdy,fdxx,fdm,fdn,fdyy=0; int n,i,j,k; \/*\u8f93\u5165\u70b9\u7684\u4e2a\u6570*\/ printf(&quot;How many points do you want to input:\\n&quot;); scanf(&quot;%d&quot;,&amp;n); \/*\u5224\u65ad\u8f93\u5165\u7684\u70b9\u7684\u4e2a\u6570\u662f\u5426\u5927\u4e8e2*\/ for(;n&lt;2;){ printf(&quot;The number of points cannot be less than 2 !\\n&quot;); printf(&quot;How many points do you want to input:\\n&quot;); &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[167],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-coding","tag-C"],"views":30696,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}