數(shù)值分析五個題目的C語言及Matlab程序_第1頁
數(shù)值分析五個題目的C語言及Matlab程序_第2頁
數(shù)值分析五個題目的C語言及Matlab程序_第3頁
數(shù)值分析五個題目的C語言及Matlab程序_第4頁
數(shù)值分析五個題目的C語言及Matlab程序_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、本文檔包含上一個文檔中的五個數(shù)值分析實驗題C語言程序及Matlab程序?qū)嶒炓籆程序#include stdio.h#include math.hvoid main()int i=0;float a=0.1,b=1.9,t=0.0,e=1.9;if(pow(a,7)-28*pow(a,4)+14)*(pow(b,7)-28*pow(b,4)+14)0)if(7*pow(x,6)-112*pow(x,3)printf(x=%f,i=%d,e=%fn,x,i,e);for(i=1;i0.00001;i+)t=x;x=x-(pow(x,7)-28*pow(x,4)+14)/(7*pow(x,6)-11

2、2*pow(x,3);e=fabs(t-x);printf(x=%f,i=%d,e=%fn,x,i,e);Matable 程序i=0;x=1.9;t=0.0;e=1.9;disp(i=,num2str(i), ,x=,num2str(x), ,e=,num2str(e);for i=1:7 t=x; x=x-(x7-28*x4+14)/(7*x6-112*x3); e=abs(t-x); disp(i=,num2str(i), ,x=,num2str(x), ,e=,num2str(e); if e0.00001 break; endend實驗二C程序#includestdio.h#inclu

3、demath.h/已知量double x10=1,2,3,4,5,6,7,8,9,10;double fd1=1,fd2=0.1;double fx10=0,0.69314718,1.0986123,1.3862944,1.6094378, 1.7917595,1.9459101,2.079445,2.1972246,2.3025851; /函數(shù)聲明void canshu(double *h,double *r,double *u,double *d);void wanju(double *u,double *r,double *d,double *m);double yths(double

4、*m,double *h,double p);double ytdhs(double *m,double *h,double p);/主函數(shù)void main()double p,q1,q2;double h9,u9,r9,m10,d10;/ 矩陣Am=d參數(shù)數(shù)據(jù)u8=1,r0=1;canshu(h,r,u,d);wanju(u,r,d,m);printf(請輸入待求數(shù)值:x=);scanf(%lf,&p);q1=yths(m,h,p);q2=ytdhs(m,h,p);printf(輸出結(jié)果為:nf(%lf)=%lfnf(%lf)=%lfn,p,q1,p,q2);/求參函數(shù)void cansh

5、u(double *h,double *r,double *u,double *d)int i,j;double a10;for(i=0;i-1)ri=hj+1/(hj+1+hj);uj=hj/(hj+hj+1);di=(6/(hj+hi)*(ai-aj);d0=(6/h0)*(ai-9-fd1);d9=(6/hi-1)*(fd2-ai-1);/追趕法求彎矩向量mvoid wanju(double *u,double *r,double *d,double *m)int i,j;double l9,n10,z10;n0=2;z0=d0;for(i=0;i-1;j-)mj=(zj-rj*mj+1

6、)/nj;/三次樣條插值函數(shù)double yths(double *m,double *h,double p)int i,j=0;double q;for(i=0;i10;i+)if(xi=(p-1)break;q=pow(xi+1-p,3)/6/hi+1*mi+pow(p-xi,3)/6/hi+1*mi+1+ (fxi-pow(hi+1,2)*mi/6)*(xi+1-p)/hi+1+ (fxi+1-pow(hi+1,2)*mi+1/6)*(p-xi)/hi+1;return q;/三次樣條插值導(dǎo)函數(shù)double ytdhs(double *m,double *h,double p)int i

7、,j=0;double q;for(i=0;i10;i+)if(xi=(p-1)break;q=-pow(xi+1-p,2)/2/hi+1*mi+pow(p-xi,2)/2/hi+1*mi+1-(fxi-pow(hi+1,2)*mi/6)/hi+1+(fxi+1-pow(hi+1,2)*mi+1/6)/hi+1;return q;Matlab 程序functionh,r,u,d=canshu(x,fx,h,r,u,d,fd1,fd2)%UNTITLED10 Summary of this function goes here% Detailed explanation goes herefor

8、 i=1:9 h(i)=x(i+1)-x(i); a(i)=(fx(i)-fx(i+1)/(x(i)-x(i+1); j=i-1; if j0 r(i)=h(j+1)/(h(j+1)+h(j); u(j)=h(j)/(h(j)+h(j+1); d(i)=(6/(h(j)+h(i)*(a(i)-a(j); end endd(1)=(6/h(1)*(a(i-8)-fd1);d(10)=(6/h(i)*(fd2-a(i);endglobal x fd1 fd2 fx h d m r u;x=1,2,3,4,5,6,7,8,9,10;fd1=1;fd2=0.1;fx=0,0.69314718,1.09

9、86123,1.3862944,1.6094378,1.7917595,1.9459101,2.079445,2.1972246,2.3025851;u(9)=1;r(1)=1;h,r,u,d=canshu(x,fx,h,r,u,d,fd1,fd2);m=wanju(u,r,d,m);p=input(請輸入待求數(shù)值:x=);q1=yths(m,h,p,x,fx);q2=ytdhs(m,h,p,fx,x);disp(輸出結(jié)果為:,f(,num2str(p),)=,num2str(q1),f(,num2str(p),)=,num2str(q2);functionm=wanju(u,r,d,m)%U

10、NTITLED12 Summary of this function goes here% Detailed explanation goes heren(1)=2;z(1)=d(1);for i=1:9 l(i)=u(i)/n(i); n(i+1)=2-l(i)*r(i); z(i+1)=d(i+1)-l(i)*z(i); endm(10)=z(10)/n(10);for j=9:-1:1 m(j)=(z(j)-r(j)*m(j+1)/n(j);endendfunction q =ytdhs(m,h,p,fx,x)%UNTITLED14 Summary of this function go

11、es here% Detailed explanation goes herefor i=1:10 if x(i)=(p) break; endq=-(x(i+1)-p)2/2/h(i+1)*m(i)+(p-x(i)2/2/h(i+1)*m(i+1)-(fx(i)-(h(i+1)2*m(i)/6)/h(i+1)+(fx(i+1)-(h(i+1)2*m(i+1)/6)/h(i+1);endendfunctionq=yths(m,h,p,x,fx)%UNTITLED13 Summary of this function goes here% Detailed explanation goes he

12、refor i=1:10if x(i)=(p)break;endq=(x(i+1)-p)3/6/h(i+1)*m(i)+(p-x(i)3/6/h(i+1)*m(i+1)+(fx(i)-(h(i+1)2*m(i)/6)*(x(i+1)-p)/h(i+1)+(fx(i+1)-(h(i+1)2*m(i+1)/6)*(p-x(i)/h(i+1);endend實驗三C程序#includestdio.h#includemath.h/已知量double b=3,a=1;/函數(shù)聲明double romberg();double fhs(double x);/主函數(shù)void main()double q;q=r

13、omberg();printf(輸出結(jié)果為:r=%lfn,q);/Romberg算法double romberg()int n,j,k=0,m=0,z=0,i;double e=1,qh=0,q,h,x0,r1=0,t50,s50,c50,r50;t0=(b-a)/2*(fhs(a)+fhs(b);for(i=1;1;i+)n=pow(2,i-1);h=(b-a)/n;x0=a+0.5*h;for(j=0;j=3)for(k;ki;k+)sk=(4*tk+1-tk)/3;for(m;mk-1;m+)cm=(16*sm+1-sm)/15;for(z;zm-1;z+)rz=(64*cz+1-cz)

14、/63;e=fabs(r1-rz-1);r1=rz-1;if(e=4 for k=k:i s(k)=(4*t(k+1)-t(k)/3; end for m=m:k-1 c(m)=(16*s(m+1)-s(m)/15; end for z=z:m-1 r(z)=(64*c(z+1)-c(z)/63; end e=abs(r1-r(z-1); r1=r(z-1); end if(e0.00001) break; endendq=r(z-1);endglobal b a k m z e qh r1;k=0;m=0;z=0;e=1;qh=0;r1=0;b=3;a=1;q=romberg();disp(

15、輸出結(jié)果為:r=,num2str(q);實驗四C程序#includestdio.h#includemath.h/已知量double x=0,h=0.0005,y3=0,p4=0.025,0.045,0.085,0.1;double fx(double x,double y3,int t);void main()int i,t;double k4,m3;for(i=0;i4;i+)for(x=0;x=pi;x=x+h)for(t=0;t3;t+)mt=yt;for(t=0;t3;t+)k0=fx(x,m,t);mt=yt+0.5*h*k0;k1=fx(x+0.5*h,m,t);mt=yt+0.5

16、*h*k1;k2=fx(x+0.5*h,m,t);mt=yt+h*k2;k3=fx(x+h,m,t);/mt=yt;yt=yt+h*(k0+2*k1+2*k2+k3)/6;x=0;for(t=0;t3;t+)printf(y%d(%lf)=%lft,t+1,pi,yt);printf(n);for(t=0;t3;t+)yt=0;double fx(double x,double y3,int t)double f;if(t=0)f=0*x+1;else if(t=1)f=0*x+y2;elsef=0*x+1000-1000*y1-100*y2;return f;Matlab 程序functio

17、nf=fx(x,y)%UNTITLED7 Summary of this function goes here% Detailed explanation goes heref(1)=0*x+1;f(2)=0*x+y(3);f(3)=0*x+1000-1000*y(2)-100*y(3);endy=zeros(1,3);h=0.0005;x=0;p=0.025,0.045,0.085,0.1;k=zeros(4,3);for i=1:4 for j=1:fix(p(i)/h) k(1,:)=fx(x,y); k(2,:)=fx(x+0.5*h,y+0.5*h*k(1,:); k(3,:)=fx

18、(x+0.5*h,y+0.5*h*k(2,:); k(4,:)=fx(x+h,y+h*k(3,:); y=y+h*(k(1,:)+2*k(2,:)+2*k(3,:)+k(4,:)/6; x=x+h; end disp(x=,num2str(p(i), ,y=,num2str(y); y=zeros(1,3);end實驗五C程序#includestdio.h#includemath.h#define N 9/已知量double ANN=12.38412,2.115237,-1.061074,1.112336,-0.113584,0.718719,1.742382,3.067813,-2.0317

19、43,2.115237,19.141823,-3.125432,-1.012345,2.189736,1.563849,-0.784165,1.112348,3.123124,-1.061074,-3.125432,15.567914,3.123848,2.031454,1.836742,-1.056781,0.336993,-1.010103,1.112336,-1.012345,3.123848,27.108437,4.101011,-3.741856,2.101023,-0.71828,-0.037585,-0.113584,2.189736,2.031454,4.101011,19.8

20、97918,0.431637,-3.111223,2.121314,1.784317, 0.718719,1.563849,1.836742,-3.741856,0.431637,9.789356,-0.103458,-1.103456,0.238417, 1.742382,-0.784165,-1.056781,2.101023,-3.111223,-0.103458,14.7138465,3.123789,-2.213474, 3.067813,1.112348,0.336993,-0.71828,2.121314,-1.103456, 3.123789,30.719334,4.44678

21、2, -2.031743,3.123124,-1.010103,-0.037585,1.784317,0.238417,-2.213474,4.446782,40.00001;double b9=2.1874369,33.992318,-25.173417,-0.84671695,1.784317,-86.612343,1.1101230,4.719345,-5.6784392;/函數(shù)聲明void change(int a,int b);/主函數(shù)void main()int i,j,q1,n,m,t;double tmp1,tmp2=0,x9,tmp3;for(i=0;i9;i+)tmp1=A

22、ii;q1=i;for(j=i;j9;j+)/if(fabs(tmp1)fabs(Aji)tmp1=Aji;q1=j;if(q1!=i)change(i,q1);for(n=i+1;n9;n+)tmp3=Aii/Ani;for(m=i+1;m=0;t-)int l,p;l=8-t;for(p=1;p=l;p+)tmp2+=Att+p*xt+p/Att;xt=bt/Att-tmp2;tmp2=0;printf(x%d=%lfn,t,xt);/交換對應(yīng)行void change(int a,int d)int i;double tmp;tmp=ba;ba=bd;bd=tmp;for(i=0;i9;i

23、+)tmp=Aai;Aai=Adi;Adi=tmp;Matlab程序A=12.38412,2.115237,-1.061074,1.112336,-0.113584,0.718719,1.742382,3.067813,-2.031743;2.115237,19.141823,-3.125432,-1.012345,2.189736,1.563849,-0.784165,1.112348,3.123124;-1.061074,-3.125432,15.567914,3.123848,2.031454,1.836742,-1.056781,0.336993,-1.010103;1.112336,-1.012345,3.123848,27.108437,4.101011,-3.741856,2.101023,-0.71828,-0.037585;-0.113584,2.189736,2.031454,4.101011,19.897918,0.431637,-3.111223,2.121314,1.784317; 0.718719,1.563849,1.836742,-3.741856,0.431637,9.789356,-0.103458,-1.103456,0.238417; 1.742382,-0.784165,-1.05678

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論