c语言编写求解常微分方程初值问题

c语言编写求解常微分方程初值问题

ID:16701493

大小:17.50 KB

页数:3页

时间:2018-08-24

c语言编写求解常微分方程初值问题_第1页
c语言编写求解常微分方程初值问题_第2页
c语言编写求解常微分方程初值问题_第3页
资源描述:

《c语言编写求解常微分方程初值问题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、本文档利用C语言编写求解常微分方程的方法,包括改进欧拉方法求解常微分方程的初值问题,以及四阶龙格-库塔法求解常微分方程的初值问题。程序均采用txt文件输入输出方式。/*改进欧拉方法求解常微分方程的初值问题*/#include#include#include#definef(x,y)(y-2*x/y)voidmain(){FILE*fp1;/*依次输入初值、步长、下限、上限*/floatx,h,l,f0,f1,f2;if((fp1=fopen("in.txt","r"))==NULL){pr

2、intf("Can'topenthisfile!");exit(0);}fscanf(fp1,"%f%f%f%f",&f0,&h,&x,&l);fclose(fp1);FILE*fp2;if((fp2=fopen("out.txt","w"))==NULL){printf("Can'topenthisfile!");exit(0);}while(x<=l)/*改进欧拉法算法*/{f1=f0+h*f(x,f0);x=x+h;f2=f0+h*f(x,f1);f0=0.5*(f1+f2);fprintf(fp2,"x=%f,f=%f",

3、x,f0);/*输出运算结果*/}fclose(fp2);}forthequalityofreviewsandreview.Article26threview(a)theCCRAcompliance,whethercopiesofchecks;(B)whetherdoubleinvestigation;(C)submissionofprogramcompliance,investigationorexaminationofwhetherviewsareclear;(D)theborrower,guarantorloans/*四阶龙格-库塔法求

4、解常微分方程的初值问题*/#include#include#includefloatf(floatx,floaty)/*定义一个函数*/{floatf;f=(y-2*x/y);returnf;}voidmain(){intn,N;/*定义各变量*/floatx0,y0,h,x1,y1,l;floatk1,k2,k3,k4;FILE*fp1;/*依次输入初值、步长、下限、上限*/if((fp1=fopen("in.txt","r"))==NULL){printf("Can'topenthis

5、file!");exit(0);}fscanf(fp1,"%f%f%f%f",&y0,&h,&x0,&l);fclose(fp1);FILE*fp2;if((fp2=fopen("out.txt","w"))==NULL){printf("Can'topenthisfile!");exit(0);}for(n=1;x0

6、/6*(k1+2*k2+2*k3+k4);fprintf(fp2,"x%d=%3.1f,y%d=%f",n,x1,n,y1);x0=x1;y0=y1;forthequalityofreviewsandreview.Article26threview(a)theCCRAcompliance,whethercopiesofchecks;(B)whetherdoubleinvestigation;(C)submissionofprogramcompliance,investigationorexaminationofwhetherviewsar

7、eclear;(D)theborrower,guarantorloans}fclose(fp2);}forthequalityofreviewsandreview.Article26threview(a)theCCRAcompliance,whethercopiesofchecks;(B)whetherdoubleinvestigation;(C)submissionofprogramcompliance,investigationorexaminationofwhetherviewsareclear;(D)theborrower,guara

8、ntorloans

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。