数值分析复化梯形公式复化公式程序

合集下载

数值分析积分实验报告(3篇)

数值分析积分实验报告(3篇)

第1篇一、实验目的本次实验旨在通过数值分析的方法,研究几种常见的数值积分方法,包括梯形法、辛普森法、复化梯形法和龙贝格法,并比较它们在计算精度和效率上的差异。

通过实验,加深对数值积分理论和方法的理解,提高编程能力和实际问题解决能力。

二、实验内容1. 梯形法梯形法是一种基本的数值积分方法,通过将积分区间分割成若干个梯形,计算梯形面积之和来近似积分值。

实验中,我们选取了几个不同的函数,对积分区间进行划分,计算积分近似值,并与实际积分值进行比较。

2. 辛普森法辛普森法是另一种常见的数值积分方法,它通过将积分区间分割成若干个等距的区间,在每个区间上使用二次多项式进行插值,然后计算多项式与x轴围成的面积之和来近似积分值。

实验中,我们对比了辛普森法和梯形法的计算结果,分析了它们的精度差异。

3. 复化梯形法复化梯形法是对梯形法的一种改进,通过将积分区间分割成多个小区间,在每个小区间上使用梯形法进行积分,然后计算所有小区间积分值的和来近似积分值。

实验中,我们对比了复化梯形法和辛普森法的计算结果,分析了它们的精度和效率。

4. 龙贝格法龙贝格法是一种通过外推加速提高计算精度的数值积分方法。

它通过比较使用不同点数(n和2n)的积分结果,得到更高精度的积分结果。

实验中,我们使用龙贝格法对几个函数进行积分,并与其他方法进行了比较。

三、实验步骤1. 编写程序实现梯形法、辛普森法、复化梯形法和龙贝格法。

2. 选取几个不同的函数,对积分区间进行划分。

3. 使用不同方法计算积分近似值,并与实际积分值进行比较。

4. 分析不同方法的精度和效率。

四、实验结果与分析1. 梯形法梯形法在计算精度上相对较低,但当积分区间划分足够细时,其计算结果可以接近实际积分值。

2. 辛普森法辛普森法在计算精度上优于梯形法,但当积分区间划分较细时,计算量较大。

3. 复化梯形法复化梯形法在计算精度上与辛普森法相当,但计算量较小。

4. 龙贝格法龙贝格法在计算精度上优于复化梯形法,且计算量相对较小。

数值分析计算方法程序汇总

数值分析计算方法程序汇总

(一)复化梯形公式例:求121?x dx -=⎰程序:#include "stdio.h"void main(){double a,b,s,h,x;int i,n;a=-1.0;b=1.0;n=10;h=(b-a)/n;x=a;s=x*x/2;for(i=1;i<n;i++){x=x+h;s=s+x*x;}s=s+b*b/2;s=s*h;printf("s=%f\n",s);}结果:s=0.680000(二)复化辛普森公式例:求130?x dx=⎰程序:#include "stdio.h"void main(){double a,b,c,s,h,x,y;int i,n;a=0.0;b=1.0;n=10;s=0.0;h=(b-a)/n;x=a;y=x+h;c=(x+y)/2;for(i=1;i<=n;i++){s=s+x*x*x+4*c*c*c+y*y*y;x=x+h;y=y+h;c=c+h;}s=s*h/6;printf("s=%f\n",s);}结果:s=0.250000(三)复化高斯公式例:求220?x dx=⎰程序:#include <stdio.h>#include <math.h>main(){double a,b,h,s,x1,x2;int i,n;a=0;b=2;n=20;s=0;h=(b-a)/n;for(i=0;i<n;i++){x1=a+i*h+h/2*(1/1.732+1); x2=a+i*h+h/2*(1-1/1.732); s=s+x1*x1*x1+x2*x2*x2; }s=h/2*s;printf("s=%f\n",s);}结果:s=4.000000(四)迭代法例:求x=x2的解。

程序:#include "stdio.h"#include<math.h>main(){double x,xl,y,yl;int i,j;x=0.5;xl=x;y=0.5;yl=y;for(i=0;;i++){x=x*x;if(fabs(xl-x)<0.0001)break;else xl=x;}for(j=0;;j++){y=sqrt(y);if(fabs(yl-y)<0.0001)break;else yl=y;printf("x=%f,y=%f\n",x,y);}结果:x=0.000000,y=0.999915(五)牛顿迭代法y=f(x),求f(x*)=0。

数值分析实验报告3

数值分析实验报告3

江南大学实验报告实验课程:_____数值分析______ 姓名:_______XX________ 学号:____xxxxxxxxxx_____ 班级:_____信计1001______日期2011年11月9日1. 实验目的用C 语言编程实现使用复化梯形公式和复化simpson 公式计算积分2. 实验题目使用复化梯形公式和复化simpson 公式计算下列三个积分 1) 10,sin 11102=+⎰n x 2) 4,log 21=⎰n x x 3) 8,14102==+⎰n x π3. 实验原理复化梯形公式n k kh a X n a b h k ...1,0,,=+=-= ⎰∑=++=-=b a n k k n T b f x f a f h dxx f )(])()(2)([2)(11 复化simpson 公式 n k kh a X n a b h k ...1,0,,=+=-= ⎰∑∑=+++=-=-=+b a n k k n k k n S b f x f xf a f h dx x f )(])()(2)(4)([6)(1110214. 主要算法(源程序)#include <stdio.h>#include <math.h>double CTR (int n, double a, double b, double (*f)(double)){double h,r;int k;h=(b-a)/n;r=(*f)(a)+(*f)(b);for(k=1;k<=n-1;k++){r=r+2.*(*f)(a+k*h);}r=r*(h/2.);return r;}double SR (int n, double a, double b, double (*f)(double)){double h,r;int k;h=(b-a)/n;r=(*f)(a)+(*f)(b)+4.*(*f)(a+0.5*h);for (k=1;k<=n-1;k++){r=r+2.*(*f)(a+k*h)+4.*(*f)(a+(0.5+k)*h);}r=r*(h/6.);return r;}double f1(double x){return (1.0/(1.0+sin(x)*sin(x)));}double f2(double x){return (x*log(x));}double f3(double x){return (4./(1.+x*x));}void main( ){FILE *outfile = fopen("c:/out.txt", "w");int n;double a,b;a=0.0;b=1.0;n=10;fprintf(outfile,"the output of using composite trapezoidal rule:\n");fprintf(outfile,"funtion one:%12.9e\n",CTR(n,a,b,f1));a=1.0;b=2.0;n=4;fprintf(outfile,"funtion two:%12.9e\n",CTR(n,a,b,f2));a=0.0; b=1.0;n=8;fprintf(outfile, "funtion three:%12.9e\n",CTR(n,a,b,f3));a=0.0;b=1.0;n=10;fprintf(outfile,"the output of using simpson rule:\n");fprintf(outfile, "funtion one:%12.9e\n",SR(n,a,b,f1));a=1.0;b=2.0;n=4;fprintf(outfile,"funtion two:%12.9e\n", SR(n,a,b,f2));a=0.0;b=1.0;n=8;fprintf(outfile,"funtion three:%12.9e\n", SR(n,a,b,f3));fclose(outfile);}5. 实验结果the output of using composite trapezoidal rule:funtion one:8.090931211e-001funtion two:6.399004777e-001funtion three:3.138988494e+000the output of using simpson rule:funtion one:8.093528104e-001funtion two:6.362953646e-001funtion three:3.141592651e+000。

数值分析复化梯形公式,复化Simpson公式MATLAB程序

数值分析复化梯形公式,复化Simpson公式MATLAB程序

分别用复化梯形公式、复化Simpson 公式计算定积分dx e x ⎰+201,取n=2,4,8,16分别验证结果(精确值I=4.006994)。

复化梯形公式求定积分:
function I=tquad(x,y)
%复化梯形求积公式,其中,
%x 为向量,被积函数自变量的等距结点; %y 为向量,被积函数在结点处的函数值; n=length(x);
m=length(y);
%积分自变量的结点数应与它的函数值的个数相同 h=(x(n)-x(1))/(n-1);
a=[1 2*ones(1,n-2) 1];
I=h/2*sum(a.*y);
复化Simpson 公式求定积分:
function I=squad(x,y)
%复化Simpson 求积公式,其中,
%x 为向量,被积函数自变量的等距结点; %y 为向量,被积函数在结点处的函数值; n=length(x);
m=length(y);
%积分自变量的结点数应与它的函数值的个数相同 if rem(n-1,2)~=0
I=tquad(x,y);
return;
end
N=(n-1)/2;
h=(x(n)-x(1))/N;
a=zeros(1,n);
for k=1:N
a(2*k-1)=a(2*k-1)+1;
a(2*k)=a(2*k)+4;
a(2*k+1)=a(2*k+1)+1;
end
I=h/6*sum(a.*y);。

复化梯形公式和复化辛普生公式

复化梯形公式和复化辛普生公式

(英文版)Two regulations promulgated for implementation is in the party in power for a long time and the rule of law conditions, the implementation of comprehensive strictly strategic plan, implementation in accordance with the rules and discipline to manage the party, strengthen inner-party supervision of major initiatives. The two regulations supporting each other, the < code > adhere to a positive advocate, focusing on morality is of Party members and Party leading cadres can see, enough to get a high standard; < rule > around the party discipline, disciplinary ruler requirements, listed as "negative list, focusing on vertical gauge, draw the party organizations and Party members do not touch the" bottom line ". Here, the main from four square face two party rules of interpretation: the first part introduces two party Revised regulations the necessity and the revision process; the second part is the interpretation of the two fundamental principles of the revision of laws and regulations in the party; the third part introduces two party regulations modified the main changes and needs to grasp several key problems; the fourth part on how to grasp the implementation of the two regulations of the party. < code > and < Regulations > revised the necessity and revised history of the CPC Central Committee the amendment to the Chinese CommunistParty members and leading cadres honest politics several guidelines > and < Chinese Communist Party discipline and Punishment Regulations > column 1 by 2015 to strengthen party laws and regulations focus. Two party regulations revision work lasted a Years, pooling the wisdom of the whole party, ideological consensus, draw historical experience, respect for the wisdom of our predecessors, which reflects the unity of inheritance and innovation; follow the correct direction, grasp the limited goals, adhere to the party's leadership, to solve the masses of the people reflect a focus on the problem. The new revision of the < code > and < rule >, reflects the party's 18 and the eighth session of the third, the spirit of the fourth plenary session, reflecting the experience of studying and implementing the General Secretary Xi Jinping series of important speech, reflects the party's eighteen years comprehensive strictly practice. (a) revised two regulations of the party need of < the ICAC guidelines > in < in 1997 Leaders as members of the Communist Party of China clean politics certain criteria (Trial) > based on revised, the promulgation and implementation of January 2010, to strengthen the construction of the contingent of leading cadres play an important role. But with the party to manage the party strictly administering the deepening, has not been able to fully meet the actual needs. Content is toocomplicated, "eight prohibition, 52 are not allowed to" hard to remember, and also difficult to put into practice; the second is concisely positive advocated by the lack of prohibited provisions excessive, no autonomy requirements; the third is banned terms and discipline law, both with the party discipline, disciplinary regulations repeat and Criminal law and other laws and regulations repeat; the fourth is to "clean" the theme is not prominent, not for the existing problems, and is narrow, only needle of county-level leading cadres above. < rule > is in 1997 < Chinese Communist Party disciplinary cases (Trial) > based on revision, in December 2003 the promulgation and implementation, to strengthen the construction of the party play very important role. Along with the development of the situation, which many provisions have been unable to fully meet the comprehensive strictly administering the practice needs. One is Ji law, more than half of the provisions and criminal law and other countries laws and regulations Repetition; two is the political discipline regulations is not prominent, not specific, for violation of the party constitution, damage the authority of Party Constitution of misconduct lack necessary and serious responsibility to pursue; third is the main discipline for the leading cadres, does not cover all Party members. Based on the above situation, need to < the criterion of a clean and honestadministration > and < rule > the two is likely to be more relevant regulations first amendment. By revising, really put the authority of Party discipline, the seriousness in the party tree and call up the majority of Party members and cadres of the party constitution of party compasses party consciousness. (II) two party regulations revision process the Central Committee of the Communist Party of China attaches great importance to two regulations revision . Xi Jinping, general books recorded in the Fifth Plenary Session of the eighth session of the Central Commission for Discipline Inspection, on the revised regulations < > made clear instructions. According to the central deployment, the Central Commission for Discipline Inspection from 2014 under six months begin study two regulations revision. The Standing Committee of the Central Commission for Discipline Inspection 4 review revised. Comrade Wang Qishan 14 times held a special meeting to study two regulations revision, amendment clarifies the direction, major issues of principle, path and target, respectively held a forum will listen to part of the province (area) secretary of the Party committee, Secretary of the Discipline Inspection Commission, part of the central ministries and state organs DepartmentThe first party committee is mainly responsible for people, views of experts and scholars and grassroots party organizations andParty members. Approved by the Central Committee of the Communist Party of China, on 7 September 2015, the general office of the Central Committee of the Party issued a notice to solicit the provinces (autonomous regions, municipalities) Party, the central ministries and commissions, state ministries and commissions of the Party (party), the General Political Department of the military, every 3 people organization of Party of two regulations revision opinion. Central Commission for Discipline Inspection of extensive solicitation of opinions, careful study, attracting, formed a revised sent reviewers. In October 8 and October 12, Central Committee Political Bureau Standing Committee and the Political Bureau of the Central Committee After consideration of the two regulations revised draft. On October 18, the Central Committee of the Communist Party of China formally issued two regulations. Can say, two laws amendment concentrated the wisdom of the whole party, embodies the party. Second, < code > and < Regulations > revision of the basic principles of two party regulations revision work and implement the party's eighteen, ten eight plenary, the spirit of the Fourth Plenary Session of the Eleventh Central Committee and General Secretary Xi Jinping important instructions on the revised < low political criterion > and < Regulations >, highlighting the ruling partycharacteristics, serious discipline, the discipline quite in front of the law, based on the current, a long-term, advance as a whole, with Bu Xiuding independent < rule > and < rule >. Main principle is: first, adhere to the party constitution to follow. The constitution about discipline and self-discipline required specific, awaken the party constitution of party compasses party consciousness, maintaining the authority of the constitution. General Secretary Xi Jinping pointed out that "no rules, no side round. Party constitution is the fundamental law, the party must follow the general rules. In early 2015 held the eighth session of the Central Commission for Discipline Inspection Fifth Plenary Session of the 16th Central Committee, Xi Jinping again pointed out that constitution is the party must follow the general rules, but also the general rules." the revision of the < code > and < rule > is Method in adhere to the regulations established for the purpose of combining rule of virtue is to adhere to the party constitution as a fundamental to follow, the constitution authority set up, wake up the party constitution and party rules the sense of discipline, the party constitution about discipline and self-discipline specific requirements. 4 second is to adhere to in accordance with the regulations governing the party and the party. The Party of rule of virtue "de", mainly refers to the party's ideals and beliefs, excellent traditional style. The revised the< code > closely linked to the "self-discipline", insisting on the positive initiative, for all members, highlight the "vital few", emphasized self-discipline, focusing on the morality, and the majority of Party members and the ideological and moral standards. The revised < > Ji method separately, Ji, Ji Yan to Method, as a "negative list", emphasizing the heteronomy, focusing on vertical gauge. Is this one high and one low, a positive reaction, the strict party discipline and practice results transformation for the integration of the whole party to observe moral and discipline requirements, for the majority of Party members and cadres provides benchmarking and ruler. Third, insist on to. In view of the problems existing in the party at the present stage, the main problems of Party members and cadres in the aspect of self-discipline and abide by the discipline to make clearly defined, especially the party's eighteen years strict political discipline and political rules, organization and discipline and to implement the central eight provisions of the spirit against the four winds and other requirements into Disciplinary provisions. Not one pace reachs the designated position, focusing on in line with reality, pragmatic and effective. After the revision of major changes, major changes in the < code > and < rule > modified and needs to grasp several key problems (a) < code > < code > adhere to according to regulationsgoverning the party and party with morals in combination, for at the present stage, the leadership of the party members and cadres and Party members in existing main problems of self-discipline, put forward principles, requirements and specifications, showing Communists noble moral pursuit, reflected at all times and in all over the world ethics from high from low 5 common requirements. One is closely linked to the "self-discipline", removal and no direct relation to the provisions of . the second is adhere to a positive advocate, "eight prohibition" 52 are not allowed to "about the content of the" negative list moved into synchronization amendment < cases >. Three is for all the party members, will apply object from the leadership of the party members and cadres to expand to all Party members, fully embodies the comprehensive strictly required. The fourth is prominent key minority, seize the leadership of the party members and cadres is the key, and put forward higher requirements than the ordinary Party members. Five is to simplify, and strive to achieve concise, easy to understand, easy to remember. The revised < code > is the ruling Party since the first insists on a positive advocate forAll Party members and the self-discipline norms, moral declaration issued to all members of the party and the National People's solemn commitment. > < criterion of a clean and honest administration consists of 4 parts, 18,more than 3600 words. After the revision of the < code >, a total of eight, 281 words, including lead, specification and Party member cadre clean fingered self-discipline norms, etc. Part 3 members low-cost clean and self-discipline, the main contents can be summarized as "four must" "eight code". Lead part, reiterated on ideal and faith, fundamental purpose, the fine traditions and work style, noble sentiments, such as "four must" the principle of requirements, strong tone of self-discipline, The higher request for 6 and supervised tenet, the foothold in permanent Bao the party's advanced nature and purity, to reflect the revised standards requirements. Members of self-discipline norms around the party members how to correctly treat and deal with the "public and private", "cheap and rot" thrifty and extravagance "bitter music", put forward the "four norms". Party leader cadre clean fingered self-discipline norms for the leadership of the party members and cadres of the "vital few", around the "clean politics", from civil servant of the color, the exercise of power, moral integrity, a good family tradition and other aspects of the leadership of the party members and cadres of the "four norms" < > < norm norm. "The Party member's self-discipline norms" and "party members and leading cadre clean fingered self-discipline norms," a total of eight, collectively referred to as the "eight". "Four must" and "eight" of thecontent from the party constitution and Party's several generation of leaders, especially Xi Jinping, general secretary of the important discussion, refer to the "three discipline and eight points for attention" statements, and reference some embody the Chinese nation excellent traditional culture essence of epigrams. (2) the revised regulations, the main changes in the revised Regulations > to fully adapt to the strictly requirements, reflects the according to the regulations governing the law of recognition of deepening, the realization of the discipline construction and Jin Ju. < rule > is party a ruler, members of the basic line and follow. And the majority of Party members and cadres of Party organizations at all levels should adhere to the bottom line of thinking, fear discipline, hold the bottom line, as a preventive measure, to keep the party's advanced nature and purity. 1, respect for the constitution, refinement and discipline. Revised < rule > from comprehensive comb physical constitution began, the party constitution and other regulations of the Party of Party organizations and Party discipline requirements refinement, clearly defined in violation of the party constitution will be in accordance with regulations to give the corresponding disciplinary action. The original 10 categories of misconduct, integration specification for political discipline, discipline, honesty and discipline masses Ji Law and discipline and discipline andother six categories, the content of < rule > real return to Party discipline, for the majority of Party members and listed a "negative list. 7 2, highlighting the political discipline and political rules. > < Regulations according to the stage of the discipline of outstanding performance, emphasizing political discipline and political rules, organization and discipline, in opposition to the party's leadership and the party's basic theory, basic line, basic program and basic experience, the basic requirement of behavior made prescribed punishment, increase the cliques, against the organization such as violation of the provisions, to ensure that the central government decrees and the Party of centralized and unified. 3, adhere to strict discipline in the law and discipline In front, Ji separated. Revised < Regulations > adhere to the problem oriented, do Ji separated. Any national law existing content, will not repeat the provisions, the total removal of 79 and criminal law, repeat the content of the public security management punishment law, and other laws and regulations. In the general reiterated that party organizations and Party members must conscientiously accept the party's discipline, die van comply with national laws and regulations; at the same time, to investigate violations of Party members and even criminal behavior of Party discipline and responsibility, > < Regulations distinguish five different conditions, with special provisions weremade provisions, so as to realize the connection of Party discipline and state law. 4, reflect Wind building and anti-corruption struggle of the latest achievements. < rule > the party's eighteen years implement the spirit of the central provisions of the eight, against the requirements of the "four winds" and transformation for disciplinary provisions, reflecting the style construction is always on the road, not a gust of wind. In the fight against corruption out of new problems, increase the trading rights, the use of authority relatives profit and other disciplinary terms. Prominent discipline of the masses, the new against the interests of the masses and ignore the demands of the masses and other disciplinary terms and make provisions of the disposition and the destruction of the party's close ties with the masses.Discipline to protect the party's purpose. 8 of these regulations, a total of three series, Chapter 15, 178, more than 24000 words, after the revision of the regulations a total of 3 series, Chapter 11, 133, 17000 words, divided into "general" and "special provisions" and "Supplementary Provisions" Part 3. Among them, add, delete, modify the provisions of the proportion of up to nearly 90%. 1, the general general is divided into five chapters. The first chapter to the regulations of the guiding ideology, principles and scope of application of the provisions, highlight the strengthening of the partyconstitution consciousness, maintenance the authority of Party Constitution, increase the party organizations and Party members must abide by the party constitution, Yan Centralized centralized, would examine at all levels of the amended provisions implementing and maintaining Party discipline, and consciously accept the party discipline, exemplary compliance with national laws and regulations. The second chapter of discipline concept, disciplinary action types and effects of the regulations, will be a serious warning from the original a year for a year and a half; increase the Party Congress representative, by leaving the party above (including leave probation) punishment, the party organization should be terminated its representative qualification provisions. The third chapter of the disciplinary rules of use prescribed in the discipline rectifying process, non convergence, not close hand classified as severely or heavier punishment. "Discipline straighten "At least eighteen years of five years, these five years is to pay close attention to the provisions of the central eight implementation and anti -" four winds ". The fourth chapter on suspicion of illegal party disciplinary distinguish five different conditions, with special provisions were made provisions, to achieve effective convergence of Party and country 9 method. < rule > the provisions of Article 27, Party organizations in thedisciplinary review found that party members have committed embezzlement, bribery, dereliction of duty dereliction of duty and other criminal law act is suspected of committing a crime shall give cancel party posts, probation or expelled from the party. The second is < Regulations > Article 28 the provisions of Party organizations in the disciplinary review But found that party members are stipulated in the criminal law, although not involved in a crime shall be investigated for Party discipline and responsibility should be depending on the specific circumstances shall be given a warning until expelled punishment. This situation and a difference is that the former regulation behavior has been suspected of a crime, the feeling is quite strict, and the latter for the behavior not involving crime, only the objective performance of the provisions of the criminal code of behavior, but the plot is a crime to slightly. < Regulations > the 29 provisions, Party organizations in the discipline review found that party members and other illegal behavior, affect the party's image, the damage to the party, the state and the people's interests, we should depend on the situation Seriousness given disciplinary action. The loss of Party members, seriously damaging the party's image of behavior, should be given expelled from the party. At this article is party member is in violation of the criminal law outside the other illegal acts, such as violatesthe public security administration punishment law, customs law, financial laws and regulations behavior. The fourth is < cases > Article 32 stipulates, minor party members and the circumstances of the crime, the people's Procuratorate shall make a decision not to initiate a prosecution, or the people's court shall make a conviction and exempted from criminal punishment shall be given within the party is removed from his post, probation or expelled from the party. Party members and crime, sheets were fined in accordance with For acts; the principal Ordinance amended the provisions of the preceding paragraph. This is the new content, in order to achieve Ji method effective convergence. Five is < > the thirty third article 10 of the provisions, the Party member due to an intentional crime is sentenced to criminal law (including probation) sheets or additional deprivation of political rights; due to negligence crime and was sentenced to three years or more (excluding three years) a penalty, shall give expelled punishment. Due to negligence crime is convicted and sentenced to three years (including three years) in prison or be sentenced to public surveillance, detention, shall in general be expelled from the party. For the individual may not be expelled from the party, should control Approval. This is followed and retained the original > < Regulations the provisions of punishment party authorization rules and report to a level partyorganizations. For is "party members with criminal acts, and by the criminal punishment, generally should be expelled from the party". The fifth chapter of probationary Party member of the discipline and discipline after missing members of the treatment and punishment decisions, such as the implementation of the provisions, clear the related party discipline and punishment decision made after, for duties, wages and other relevant alteration formalities for the longest time. 2, sub sub section will the original regulations of10 categories of acts of violation of discipline integration revised into 6 categories, respectively, in violation of the punishments for acts of political discipline "in violation of discipline behavior of punishment" in violation of integrity of disciplinary action points "of violation punishments for acts of mass discipline" "the violation of work discipline, punishment" in violation of discipline of life behavior punishment "6 chapters. 3, annex" Supplementary Provisions "clear authority making supplementary provisions of, cases of interpretative organ, as well as regulations implementation time and retroactivity etc.. 11 (3) learning understanding > < regulations needs to grasp several key problems The first problem -- about the violation of political discipline behavior > < new ordinance chapter 6 the political discipline column for the six disciplines, that is the main opposition to Party leadership and the opposition of the basictheory, basic line, basic program and basic experience, basic requirements of misconduct made provisions of the disposition, especially the eighteen since the CPC Central Committee put forward the Yan Mingzheng treatment of discipline and political rules requirements and practical achievements transformation for Discipline article, increase the false debate central policies, cliques, against the organization review, make no discipline of the principle of harmony terms. These are the party's eighteen years in comprehensive strictly Process combined with the practice of rich content. (1) false debate the central policies and undermine the Party of centralized and unified the problem is made in accordance with the provisions of the party constitution. Constitution in general programme requirements adhere to democratic centralism is one of the requirements of the construction of the party must adhere to the four cardinal. Application of this principle is not only the party the basic organization principle and is also the mass line in party life, it requires that we must fully develop inner-party democracy, respect for the dominant position of Party members, safeguarding the Party member democratic rights, give full play to the enthusiasm and creativity of the party organizations at all levels and Party members, at the same time, also must implement the right concentration, ensure the party's mission < the chaos in unity and concertedaction to ensure that the party's decision to get quickly and effectively implementing. The Party Central Committee formulated the major principles and policies, through different channels and ways, fully listen to the party organizations and Party members of the opinions and suggestions, but 12 is some people face to face not to say back blather "" will not say, after the meeting said, "" Taiwan does not say, and nonsense ", in fact, not only disrupt the people thought, some causing serious consequences, the damage to the Party of the centralized and unified, hinder the central policy implementation, but also a serious violation of the democratic system of principles. There is no doubt that shall, in accordance with the Regulations > 4 Specified in Article 6 to give the appropriate punishment. For did not cause serious consequences, to give criticism and education or the corresponding tissue processing. (2) about the destruction of the party's unity < New Regulations > the forty eighth to fifty second article, to damage Party's unity unified and violation of political discipline, punishment situation made explicit provisions. Article 52 of the new "in the party get round group, gangs seek private gain, cliques, cultivate private forces or through the exchange of interests, for their own to create momentum and other activities to gain political capital, given a serious warning or withdraw from their party posts disposition; if thecircumstances are serious, to give Leave a party to observation or expelled from the party. (3) on against the organization review of the provisions of the constitution, party loyalty honesty is party members must comply with the obligations. Members must obey the organization decision, shall not violate the organization decided encounters by asking questions to find organization, rely on the organization, shall not deceive the organization, against the organization. For example, after the investigation does not take the initiative to explain the situation, but to engage in offensive and defensive alliance, hiding the stolen money is against survey organization, is a violation of the behavior of political discipline. Article 24 of the original > < Regulations, although the provisions of the interference, hinder group review the behavior of the fabric can be severely or 13 Aggravated punishment, but did not put this kind of behavior alone as a discipline for qualitative amount of discipline. > < new regulations increase the Article 57, "anti organization review, one of the following acts, given a warning or serious warning; if the circumstances are relatively serious, giving removed from or placed on probation within the party post; if the circumstances are serious, give expelled from the party: (a) on supply or forged, destroyed, transfer, conceal evidence; (II) to prevent others expose, providing evidence。

复化梯形公式和复化Simpson公式

复化梯形公式和复化Simpson公式

数值计算方法上机题目3一、计算定积分的近似值:221x e xe dx =⎰ 要求:(1)若用复化梯形公式和复化Simpson 公式计算,要求误差限71021-⨯=ε,分别利用他们的余项估计对每种算法做出步长的事前估计;(2)分别利用复化梯形公式和复化Simpson 公式计算定积分;(3)将计算结果与精确解比较,并比较两种算法的计算量。

1.复化梯形公式程序:程序1(求f (x )的n 阶导数:syms xf=x*exp(x) %定义函数f (x )n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n 阶导数结果1输入n=2f2 =2*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(2*exp(x) + x*exp(x))','x') %定义f(x)的二阶导数,输入程序1里求出的f2即可。

f3='-(2*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,以便求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的二阶导数的最小值点,也就是求二阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/12*((b-a)/n)^2*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hTn1=0for k=1:n-1 %求连加和xk=a+k*hTn1=Tn1+f(xk)endTn=h/2*((f(a)+2*Tn1+f(b)))z=exp(2)R=Tn-z %求已知值与计算值的差fprintf('用复化梯形算法计算的结果 Tn=')disp(Tn)fprintf('等分数 n=')disp(n) %输出等分数fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用复化梯形算法计算的结果Tn= 7.3891等分数n=7019已知值与计算值的误差R= 2.8300e-0082. Simpson公式程序:程序1:(求f(x)的n阶导数):syms xf=x*exp(x) %定义函数f(x)n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n阶导数结果1输入n=4f2 =4*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(4*exp(x) + x*exp(x))','x') %定义f(x)的四阶导数,输入程序1里求出的f2即可f3='-(4*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,一边求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的四阶导数的最小值点,也就是求四阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/180*((b-a)/(2*n))^4*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hSn1=0Sn2=0for k=0:n-1 %求两组连加和xk=a+k*hxk1=xk+h/2Sn1=Sn1+f(xk1)Sn2=Sn2+f(xk)endSn=h/6*(f(a)+4*Sn1+2*(Sn2-f(a))+f(b)) %因Sn2多加了k=0时的值,故减去f(a)z=exp(2)R=Sn-z %求已知值与计算值的差fprintf('用Simpson公式计算的结果 Sn=')disp(Sn)fprintf('等分数 n=')disp(n)fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用Simpson公式计算的结果Sn= 7.3891等分数n=24已知值与计算值的误差R= 2.7284e-008用复化梯形公式计算的结果为:7.3891,与精确解的误差为:2.8300e-008。

合肥工业大学计算方法复化梯形公式实验

合肥工业大学计算方法复化梯形公式实验

《计算方法》实验报告(3) f(x)是由测量或计算得到的表格函数由于以上种种困难,有必要研究积分的数值计算问题。

利用插值多项式 )()(x f x P n ≈则积分dx x f ba⎰)(转化为dx x P b a n ⎰)(,显然易算。

dx x P ban ⎰)(称为插值型求积公式。

最简单的插值型求积公式是梯形公式和Simpson 公式,。

当求积结点提供较多,可以分段使用少结点的梯形公式和Simpson 公式,并称为复化梯形公式、复化Simpson 公式。

如步长未知,可以通过误差限的控制用区间逐次分半的策略自动选取步长的方法称自适应算法。

梯形递推公式给出了区间分半前后的递推关系。

由梯形递推公式求得梯形序列,相邻序列值作线性组合得Simpson 序列, Simpson 序列作线性组合得柯特斯序列, 柯特斯序列作线性组合的龙贝格序列。

若|R 2-R 1|<,则输出R2;否则…依此类推。

如此加工数据的过程叫龙贝格算法,如下图所示:复化梯形公式)]()(2)([21110n n k k n x f x f x f h T ++=∑-=复化Simpson 公式])(4)()(2)([61021110∑∑-=+-=+++=n k k n k n k n x f x f x f x f hS梯形递推公式∑-=++=10212)(22n k k n n x f h T T 加权平均公式:n n n S T T =--1442 n n n C S S =--144222 n nn R C C =--144323 龙贝格算法大大加快了误差收敛的速度,由梯形序列O(h2) 提高到龙贝格序列的O(h8)}实验结果:图1六、实验总结1.梯形公式的收敛速度太慢,所以我们才会选择之后的几种公式加快收敛速度。

2.通过实验可以看出,龙贝格算法大大加快了误差收敛的速度,由梯形序列O(h2) 提高到龙贝格序列的O(h8)3.在编程的过程中可以切身体验到龙贝格算法是基于前几种算法的实现才能实现的。

复化梯形求积公式

复化梯形求积公式

复化梯形求积公式复化梯形求积法是一种用于数值积分的常见方法,它可以帮助我们求解一元定积分(即 integrals 或者是积分函数)。

在复化梯形求积法中,我们需要对函数 f(x) 在某一区间 [a,b]内的值进行插值,并将插值后的函数值相加,以计算该函数在该区间上的积分值。

复化梯形求积法的步骤如下:第一步:分解积分区间[a,b],将其分解为 n 个子区间,其中区间长度为 h=(b-a)/n。

第二步:对积分区间[a,b] 中每个子区间使用复化梯形公式来计算它们的积分值。

根据复化梯形求积公式,积分区间 [a,b] 中每个子区间的积分值如下:Ii = h/2 * [f(xi) + f(xi+1)] (i=0,1,...,n-1)其中,xi 是第 i 个(0≤i≤n-1)子区间的左端点,xi+1 是第 i 个子区间的右端点,f(xi) 是第 i 个子区间左端点处的函数值,f(xi+1) 是第 i 个子区间右端点处的函数值。

第三步:将所有子区间积分值进行累加,得到积分区间[a,b]的总积分值。

按照复化梯形求积法,积分区间 [a,b] 的总积分值计算公式如下:I=h/2 * [f(x0)+f(xn)+∑(i=1,2,...,n-1)[f(xi)+f(xi+1)]]以上就是复化梯形求积法的基本原理及其用于求解一元定积分的步骤:首先将积分区间分解为子区间,然后使用复化梯形公式计算每个子区间的积分值,最后将子区间积分值相加得到积分区间的总积分值。

这种求积方法容易理解,计算量小,计算速度快,因此复化梯形求积法在积分计算中有着重要的应用价值。

在复化梯形求积法中,可以使用高斯公式来加快积分值的计算。

高斯公式的定义如下:I=h/2 * [f(x0)+f(xn)+c1f(x1)+c2f(x2)+...+cnf(xn-1)]其中,c1,...,cn 是某些常数,x1,...,xn-1 为积分区间上的中点。

应用高斯公式,可以将积分计算量减小一半以上,同时也大大减少计算精度上的误差。

复化梯形公式和复化Simpson公式

复化梯形公式和复化Simpson公式

数值计算方法上机题目3一、计算定积分的近似值:221x e xe dx =⎰ 要求:(1)若用复化梯形公式和复化Simpson 公式计算,要求误差限71021-⨯=ε,分别利用他们的余项估计对每种算法做出步长的事前估计;(2)分别利用复化梯形公式和复化Simpson 公式计算定积分;(3)将计算结果与精确解比较,并比较两种算法的计算量。

1.复化梯形公式程序:程序1(求f (x )的n 阶导数:syms xf=x*exp(x) %定义函数f (x )n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n 阶导数结果1输入n=2f2 =2*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(2*exp(x) + x*exp(x))','x') %定义f(x)的二阶导数,输入程序1里求出的f2即可。

f3='-(2*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,以便求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的二阶导数的最小值点,也就是求二阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/12*((b-a)/n)^2*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hTn1=0for k=1:n-1 %求连加和xk=a+k*hTn1=Tn1+f(xk)endTn=h/2*((f(a)+2*Tn1+f(b)))z=exp(2)R=Tn-z %求已知值与计算值的差fprintf('用复化梯形算法计算的结果 Tn=')disp(Tn)fprintf('等分数 n=')disp(n) %输出等分数fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用复化梯形算法计算的结果 Tn= 7.3891等分数 n=7019已知值与计算值的误差 R= 2.8300e-0082. Simpson公式程序:程序1:(求f(x)的n阶导数):syms xf=x*exp(x) %定义函数f(x)n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n阶导数结果1输入n=4f2 =4*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(4*exp(x) + x*exp(x))','x') %定义f(x)的四阶导数,输入程序1里求出的f2即可f3='-(4*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,一边求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的四阶导数的最小值点,也就是求四阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/180*((b-a)/(2*n))^4*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hSn1=0Sn2=0for k=0:n-1 %求两组连加和xk=a+k*hxk1=xk+h/2Sn1=Sn1+f(xk1)Sn2=Sn2+f(xk)endSn=h/6*(f(a)+4*Sn1+2*(Sn2-f(a))+f(b)) %因Sn2多加了k=0时的值,故减去f(a)z=exp(2)R=Sn-z %求已知值与计算值的差fprintf('用Simpson公式计算的结果 Sn=')disp(Sn)fprintf('等分数 n=')disp(n)fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用Simpson公式计算的结果 Sn= 7.3891等分数 n=24已知值与计算值的误差 R= 2.7284e-008用复化梯形公式计算的结果为:7.3891,与精确解的误差为:2.8300e-008。

数值分析中的各种公式C 代码

数值分析中的各种公式C  代码

二分法2.2 算法步骤步骤1:准备计算f(x)在有根区间[a,b]端点处的值f(a),f(b).步骤2:二分计算f(x)在区间中点(a+b)/2处的值f((a+b)/2).步骤3:判断若f((a+b)/2)=0,则(a+b)/2即是根,计算过程结束,否则检验;若f((a+b)/2)f(a)<0,则以(a+b)/2代替b,否则以(a+b)/2代替a.反复执行步骤2和步骤3,直到区间[a,b]的长度小于允许误差e,此时中点(a+b)/2即为所求近似根。

2.3 程序流程图3 实验结果分析#include"stdio.h"void main(){float a,b,e,x,c;int k=0,n=1;scanf("%f,%f,%f",&a,&b,&e);while(n==1){x=(a+b)/2;c=(x*x*x-x-1)*(a*a*a-a-1);if(c<0){b=x;if(b-a<=e){printf("%f,%d\n",x,k);break;}else k++;}else{ if(c==0) { printf("%f,%d\n",x,k);break;}else { a=x; if(b-a<=e) { printf("%f,%d\n",x,k);break;}else k++;}}}}高斯塞德尔迭代法求方程组解 高斯主元素消去法求方程组解2.2 算法步骤高斯塞德尔迭代法:步骤1:给定初值)0(1)0(2)0(1,...,,n x x x ,精度ε,最大容许迭代次数M,令k=1。

步骤2:对 i=1,2,…,n 依此计算)0()1()0()1(01)0()1()1().(i i ii i iinj j j ij iix x x x e a x a xx→-=-=∑≠=步骤3:求出 e=}{max 1i ni e ≤≤,若 e<ε,则输出 )0(i x (i=1,2,..,n ),停止计算。

数值分析数值微积分实验

数值分析数值微积分实验

实验报告
一、实验目的
复化求积公式计算定积分。

二、实验题目
1.用复化梯形公式、复化辛普森公式求下列定积分,要求绝对误差为3
10-=ε,并将计算结果与精确解进行比较: dx e x e x 232
143
2⎰= 三、实验原理
复化求积公式程序,复化辛普森公式程序。

四、实验内容及结果
五、实验结果分析
实验1中复化梯形公式和复化辛普森公式的比较:
运行复化梯形公式的时候,因为要去找区分精度,所以花的时间比较长,需要将区间分为365份时才能达到规定的误差范围。

而复化辛普森公式则只需要将区间分为12份即可。

说明复化辛普森比较好。

复化梯形算法求解数值积分

复化梯形算法求解数值积分

复化梯形算法求解数值积分摘要求某函数的定积分时,在多数情况下,被积函数的原函数很难用初等函数表达出来,因此能够借助微积分学的牛顿-莱布尼兹公式计算定积分的机会是不多的。

另外,许多实际问题中的被积函数往往是列表函数或其他形式的非连续函数,对这类函数的定积分,也不能用不定积分方法求解。

由于以上原因,数值积分的理论与方法一直是计算数学研究的基本课题。

构造数值积分公式最通常的方法是用积分区间上的n 次插值多项式代替被积函数,由此导出的求积公式称为插值型求积公式。

特别在节点分布等距的情形称为牛顿-柯茨公式,例如梯形公式与抛物线公式就是最基本的近似公式。

但是它们的精度较差。

而且高阶Newton-Cotes求积公式是不稳定的。

因此,通常不用高阶求积公式得到比较精确的积分值,而是将整个积分区间分段,在每一小段上用低阶求积公式。

这种方法称为复化求积方法。

本文从三个积分实例出发,主要讨论复化梯形公式以及精确程度分析。

关键词:数值积分;复化求积公式;复化梯形算法;MATLABTHE REHABILITATION OF TRAPEZOID FORMULA TO SOLVE THE NUMERICAL INTEGRATIONABSTRACTFind the definite integral of a function, in most cases, the original integrand function is difficult toexpress the elementary functions, it can use calculus of Newton - Leibniz formula to calculate thedefinite integral of the few opportunities . In addition, many practical problems in the integrand is often a list of functions or other forms of non-continuous function, the definite integral of suchfunctions, indefinite integral method can not solve. For these reasons, the numerical integration oftheory and method has been the subject of calculation of the basic mathematical research.Structural formula for numerical integration method is used most often on the n-th integration interval polynomial interpolation instead of the integrand, thus derived is called interpolation-typequadrature formula quadrature formula. Especially in the case of equidistant distribution of nodesis called Newton - Keci formula, such as trapezoidal formula and the formula is the most basicparabolic approximation formula. But their accuracy is poor. And high-level Newton-Cotesquadrature formula is unstable. So it is usually not higher-order quadrature formula to be moreprecise integral values, but the whole range of sub-points, with each short on low-level quadrature formula. This method is called complex method of quadrature.This example from three points of departure, the main complex of the trapezoid formula anddiscuss the accuracy of the analysis.Key words: Numerical integration;Rehabilitation of numerical integration;Rehabilitation of trapezoid formula;MA TLAB目录1 问题的提出 (1)2 问题的分析 (2)3 问题假设 (2)4 符号说明 (3)5 模型的建立及求解 (3)5.1 模型的准备工作 (3)5.1.1 复化梯形数值积分基本原理........... (3)5.2 模型的建立及求解 (4)6 模型验证及结果分析 (8)参考文献 (9)附录 (10)1问题提出有很多实际问题常常需要计算积分才能求解。

数值分析中的复化梯形法误差控制

数值分析中的复化梯形法误差控制

数值分析中的复化梯形法误差控制在数值分析领域中,误差控制是一个至关重要的问题。

而在数值积分中使用的一种常见方法是复化梯形法。

本文将探讨复化梯形法的误差控制问题,并介绍如何有效地控制误差,提高数值积分的准确性和可靠性。

1. 复化梯形法概述复化梯形法是一种数值积分方法,用于估计定积分值。

它基于将积分区间分割成多个子区间,并在每个子区间上使用梯形公式来计算积分值的近似值。

具体而言,对于一个被积函数 f(x) 在[a, b] 上的定积分∫(a到b) f(x)dx ,可以将[a, b] 分割成 n 个子区间,每个子区间的长度为h=(b-a)/n 。

然后,对于每个子区间 [xi-1, xi] ,计算其上的梯形近似值Ti,然后将这些梯形的面积相加得到最终的近似积分值。

2. 复化梯形法误差分析然而,复化梯形法的计算结果并不完全准确,存在一定的误差。

为了更好地控制误差,我们需要对误差进行分析和估计。

根据复化梯形法的误差公式,误差可以表示为 E = -((b-a)^3)/(12*n^2) * f''(ξ),其中ξ 是 [a, b] 区间上的某个点,f''(ξ) 是函数 f(x) 的二阶导数。

由此可见,误差与 n 的平方成反比,当 n 增大时,误差将减小。

3. 误差控制方法那么,如何有效地控制误差呢?下面介绍几种常用的方法:a. 增加子区间数:通过增加子区间数 n,可以减小误差。

然而,增加子区间数将导致计算量增加,因此需要权衡计算效率和精度的要求。

b. 自适应算法:自适应算法是一种动态调整子区间数的方法,它根据当前积分的精度要求来决定是否增加或减少子区间数。

这种方法可以在满足精度要求的前提下,减少计算量。

c. 改进的复化梯形法:改进的复化梯形法是对传统的复化梯形法的改进。

它使用了梯形法和辛普森法的组合,可以提高积分精度,减小误差。

4. 数值实例为了更好地理解误差控制方法的效果,我们举一个数值实例来进行演示。

复化梯形公式和复化Simpson公式

复化梯形公式和复化Simpson公式

数值计算方法上机题目3一、计算定积分的近似值:221x e xe dx =⎰ 要求:(1)若用复化梯形公式和复化Simpson 公式计算,要求误差限71021-⨯=ε,分别利用他们的余项估计对每种算法做出步长的事前估计;(2)分别利用复化梯形公式和复化Simpson 公式计算定积分;(3)将计算结果与精确解比较,并比较两种算法的计算量。

1.复化梯形公式程序:程序1(求f (x )的n 阶导数:syms xf=x*exp(x) %定义函数f (x )n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n 阶导数结果1输入n=2f2 =2*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(2*exp(x) + x*exp(x))','x') %定义f(x)的二阶导数,输入程序1里求出的f2即可。

f3='-(2*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,以便求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的二阶导数的最小值点,也就是求二阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/12*((b-a)/n)^2*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hTn1=0for k=1:n-1 %求连加和xk=a+k*hTn1=Tn1+f(xk)endTn=h/2*((f(a)+2*Tn1+f(b)))z=exp(2)R=Tn-z %求已知值与计算值的差fprintf('用复化梯形算法计算的结果 Tn=')disp(Tn)fprintf('等分数 n=')disp(n) %输出等分数fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用复化梯形算法计算的结果Tn= 7.3891等分数n=7019已知值与计算值的误差R= 2.8300e-0082. Simpson公式程序:程序1:(求f(x)的n阶导数):syms xf=x*exp(x) %定义函数f(x)n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n阶导数结果1输入n=4f2 =4*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(4*exp(x) + x*exp(x))','x') %定义f(x)的四阶导数,输入程序1里求出的f2即可f3='-(4*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,一边求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的四阶导数的最小值点,也就是求四阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/180*((b-a)/(2*n))^4*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hSn1=0Sn2=0for k=0:n-1 %求两组连加和xk=a+k*hxk1=xk+h/2Sn1=Sn1+f(xk1)Sn2=Sn2+f(xk)endSn=h/6*(f(a)+4*Sn1+2*(Sn2-f(a))+f(b)) %因Sn2多加了k=0时的值,故减去f(a)z=exp(2)R=Sn-z %求已知值与计算值的差fprintf('用Simpson公式计算的结果 Sn=')disp(Sn)fprintf('等分数 n=')disp(n)fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用Simpson公式计算的结果Sn= 7.3891等分数n=24已知值与计算值的误差R= 2.7284e-008用复化梯形公式计算的结果为:7.3891,与精确解的误差为:2.8300e-008。

复化梯形公式和复化Simpson公式

复化梯形公式和复化Simpson公式

数值计算方法上机题目3一、计算定积分的近似值:221x e xe dx =⎰ 要求:(1)若用复化梯形公式和复化Simpson 公式计算,要求误差限71021-⨯=ε,分别利用他们的余项估计对每种算法做出步长的事前估计;(2)分别利用复化梯形公式和复化Simpson 公式计算定积分;(3)将计算结果与精确解比较,并比较两种算法的计算量。

1.复化梯形公式程序:程序1(求f (x )的n 阶导数:syms xf=x*exp(x) %定义函数f (x )n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n 阶导数结果1输入n=2f2 =2*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(2*exp(x) + x*exp(x))','x') %定义f(x)的二阶导数,输入程序1里求出的f2即可。

f3='-(2*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,以便求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的二阶导数的最小值点,也就是求二阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/12*((b-a)/n)^2*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hTn1=0for k=1:n-1 %求连加和xk=a+k*hTn1=Tn1+f(xk)endTn=h/2*((f(a)+2*Tn1+f(b)))z=exp(2)R=Tn-z %求已知值与计算值的差fprintf('用复化梯形算法计算的结果 Tn=')disp(Tn)fprintf('等分数 n=')disp(n) %输出等分数fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用复化梯形算法计算的结果Tn= 7.3891等分数n=7019已知值与计算值的误差R= 2.8300e-0082. Simpson公式程序:程序1:(求f(x)的n阶导数):syms xf=x*exp(x) %定义函数f(x)n=input('输入所求导数阶数:')f2=diff(f,x,n) %求f(x)的n阶导数结果1输入n=4f2 =4*exp(x) + x*exp(x)程序2:clcclearsyms x%定义自变量xf=inline('x*exp(x)','x') %定义函数f(x)=x*exp(x),换函数时只需换该函数表达式即可f2=inline('(4*exp(x) + x*exp(x))','x') %定义f(x)的四阶导数,输入程序1里求出的f2即可f3='-(4*exp(x) + x*exp(x))'%因fminbnd()函数求的是表达式的最小值,且要求表达式带引号,故取负号,一边求最大值e=5*10^(-8) %精度要求值a=1 %积分下限b=2 %积分上限x1=fminbnd(f3,1,2) %求负的四阶导数的最小值点,也就是求四阶导数的最大值点对应的x值for n=2:1000000 %求等分数nRn=-(b-a)/180*((b-a)/(2*n))^4*f2(x1) %计算余项if abs(Rn)<e %用余项进行判断break% 符合要求时结束endendh=(b-a)/n %求hSn1=0Sn2=0for k=0:n-1 %求两组连加和xk=a+k*hxk1=xk+h/2Sn1=Sn1+f(xk1)Sn2=Sn2+f(xk)endSn=h/6*(f(a)+4*Sn1+2*(Sn2-f(a))+f(b)) %因Sn2多加了k=0时的值,故减去f(a)z=exp(2)R=Sn-z %求已知值与计算值的差fprintf('用Simpson公式计算的结果 Sn=')disp(Sn)fprintf('等分数 n=')disp(n)fprintf('已知值与计算值的误差 R=')disp(R)输出结果显示:用Simpson公式计算的结果Sn= 7.3891等分数n=24已知值与计算值的误差R= 2.7284e-008用复化梯形公式计算的结果为:7.3891,与精确解的误差为:2.8300e-008。

数值分析复化Simpson积分公式和复化梯形积分公式计算积分的通用程序培训讲学

数值分析复化Simpson积分公式和复化梯形积分公式计算积分的通用程序培训讲学

数值分析复化S i m p s o n积分公式和复化梯形积分公式计算积分的通用程序数值分析第五次程序作业PB09001057 孙琪【问题】分别编写用复化Simpson积分公式和复化梯形积分公式计算积分的通用程序;用如上程序计算积分:取节点并分析误差;简单分析你得到的数据。

【复化Simpson积分公式】Simpson法则:使用偶数个子区间上的复合Simpson法则:设n是偶数,则有将Simpson法则应用于每一个区间,得到复合Simpson法则:公式的误差项为:其中δ【复化梯形积分公式】梯形法则:对两个节点相应的积分法则称为梯形法则:如果划分区间[a,b]为:那么在每个区间上可应用梯形法则,此时节点未必是等距的,由此得到复合梯形法则:对等间距h=(b-a)/n及节点,复合梯形法则具有形式:误差项为:【算法分析】复合Simpson法则和复合梯形法则的算法上述描述中都已介绍了,在此不多做叙述。

【实验】通过Mathematica编写程序得到如下结果:1.利用复化Simpson积分公式得:可以看出,当节点数选取越来越多时,误差项越来越小,这从复合的Simpson公式很好看出来,因为在每一段小区间内,都是用Simpson法则去逼近,而每一段的误差都是由函数在该区间内4阶导数值和区间长度的4次方乘积决定的,当每一段小区间越来越小时,相应的每一段小区间内的逼近就会越来越好,从而整体的逼近效果就会越来越好。

2.利用复化梯形积分公式得:可以看出,当节点数选取越来越多时,误差项越来越小,这从复合的梯形公式很好看出来,因为在每一段小区间内,都是用梯形法则去逼近,而每一段的误差都是由函数在该区间内2阶导数值和区间长度的2次方乘积决定的,当每一段小区间越来越小时,相应的每一段小区间内的逼近就会越来越好,从而整体的逼近效果就会越来越好。

【分析】通过对上述两种法则的效果来看,复合Simpson法则的误差要比复合梯形法则收敛到0更快,说明复合Simpson法则逼近到原来的解更快,这主要是因为在每一段小区间内,复合Simpson法则利用得是Simpson法则,复合梯形法则利用得是梯形法则,前者的误差项要比后者的误差项小很多,因此造成了逼近速度的不一样。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

分别用复化梯形公式、复化Simpson 公式计算定积分dx e x ⎰+201,取n=2,4,8,16分别验证结果(精确值I=)。

复化梯形公式求定积分:
function I=tquad(x,y)
%复化梯形求积公式,其中,
%x 为向量,被积函数自变量的等距结点; %y 为向量,被积函数在结点处的函数值; n=length(x);
m=length(y);
%积分自变量的结点数应与它的函数值的个数相同 h=(x(n)-x(1))/(n-1);
a=[1 2*ones(1,n-2) 1];
I=h/2*sum(a.*y);
复化Simpson 公式求定积分:
function I=squad(x,y)
%复化Simpson 求积公式,其中,
%x 为向量,被积函数自变量的等距结点; %y 为向量,被积函数在结点处的函数值; n=length(x);
m=length(y);
%积分自变量的结点数应与它的函数值的个数相同 if rem(n-1,2)~=0
I=tquad(x,y);
return;
end
N=(n-1)/2;
h=(x(n)-x(1))/N;
a=zeros(1,n);
for k=1:N
a(2*k-1)=a(2*k-1)+1;
a(2*k)=a(2*k)+4;
a(2*k+1)=a(2*k+1)+1;
end
I=h/6*sum(a.*y);。

相关文档
最新文档