C语言编程求微分,愿意再追加50分.

C语言编程求微分,愿意再追加50分.,第1张

#include <stdio.h>

main()

{

float x,y,ji_fen,wei_fen

for(x=0x<2x=x+0.01)

{

y=x*x

ji_fen=ji_fen+y*0.01

wei_fen=(y-(x-0.01)*(x-0.01))/汪信0.01

printf("x=%f y=%f ji_fen=%f wei_fen=%f\困败轮n"枯改,x,y,ji_fen,wei_fen)

}

}

辛普森

#include <stdio.h>

#include <math.h>

#define F(X) (4.0/(1+X*X))

static float EPS = 1.0E-14

static int COUNT=1

static double a=0.0, b=1.0

static double M[32],T[32],S[32],C[32],R[32],E[32]

double GETM(int K)

{ unsigned long j,n=1

double x=0,y=0,step=0

for(j=0j<Kj++) n*=2

step = (b-a)/n

x = a+step/2

for(j=0j<nj++){y+=F(x)x+=step}

return (y*step)

}

Simpson(float EPS)

{ int k=0

T[0]= (b-a)*(F(a)+F(b))/2.0

S[0]=T[0]

E[0]=1.0E10

for(k=0k<20k++)

{ M[k] = GETM(k)

T[k+1]=(M[k]+T[k])/2.0

S[k+1]=(4.0*T[k+1]-T[k])/3.0

COUNT++

E[k+1]=fabs(S[k+1]-S[k])

if(k<3)continue

if(E[k+1]<EPS)break

}

return

}

ShawResult()

{ int k

system("cls"弊顷让)

printf("\n K M[K] T[K] S[K]")

printf(" E[K]")

printf("\n-------------------------------------------")

printf("-----------------------------------")

for(k=0k<COUNTk++)

printf("\n%2d %20.15lf%20.15lf%20.15lf%12.4e",k,M[k],T[k],S[k],E[k])

printf("\n--------------------------------------------")

printf("-----------------------------------")

getch()

system("cls")

return

}

SaveResult()

{ int k

FILE * fp

fp=fopen("Simpson.htm","w")

if(!fp) return

fprintf(fp,"租局<html><head></head>乎含")

fprintf(fp,"<body bgcolor = #006699 text = #FFff00>")

fprintf(fp,"<pre><font size=\"6\">")

fprintf(fp,"\n K M[K] T[K] S[K]")

fprintf(fp," E[K]")

fprintf(fp,"\n----------------------------------------------")

fprintf(fp,"----------------------------------")

for(k=0k<COUNTk++)

fprintf(fp,"\n%2d %20.15f%20.15f%20.15f%12.4le",k,M[k],T[k],S[k],E[k])

fprintf(fp,"\n----------------------------------------------")

fprintf(fp,"----------------------------------")

fprintf(fp,"</pre></font></body>")

fclose(fp)

return

}

main()

{ Simpson(EPS)

ShawResult()

SaveResult()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12334610.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存