数值分析 解微分方程



 

 

if (k>1) C1 = C2; 

 

 

if (k>2) R1 = R2; 

 

 

k++; h/=2; 

 

 

f = 0; x = a + h/2; 

 

 

while (x<b) 

 

 

 

 

 

f += fx(x); 

 

 

 

x += h; 

 

 

 

 

T2 = (T1 + h * f) / 2; 

 

 

S2 = T2 + (T2 - T1)/3; 

 

 

if (k==1) continue; 

 

 

C2 = S2 + (S2 - S1)/15; 

 

 

if (k==2) continue; 

 

 

R2 = C2 + (C2 - C1)/63; 

 

 

 

 

system("pause"); 

 

return 0; 

B

.中心加速求导:

 

// y = e^ x 

#include <iostream> 

#include <cmath> 

#define eps 1e-6 

using namespace std; 

double G(double h) 

 

if (h<0) h = -h; 

 

return (exp(1+h) - exp(1-h))/(2*h); 

 

int main() 

 

double h; 

 

cin>>h; 

 

 

double S1, S2, T1, T2, C1, C2, R1, R2; 

 

double x, f; 

 

T2 = T1 = G(h); 

 

int k = 0; 

 

R1=0; R2=1; h *= 2; 

 

while (fabs(R2-R1)>eps) 

 

 

 

 

 

cout<<T2<<" "; 

 

 

if (k>1) cout<<S2<<" "; 

 

 

if (k>2) cout<<C2<<" "; 

 

 

if (k>3) cout<<R2; 

 

 

cout<<endl; 

 

 

 

 

 

T1 = T2; 

 

 

 

 

 

S1 = S2; 

 

 

if (k>1) C1 = C2; 

 

 

if (k>2) R1 = R2; 

 

 

k++; h/=2; 

 

 

T2 = G(h); 

 

 

S2 = T2 + (T2 - T1)/3; 

 

 

if (k==1) continue; 

 

 

C2 = S2 + (S2 - S1)/15; 

 

 

if (k==2) continue; 

 

 

R2 = C2 + (C2 - C1)/63; 

 

 

system("pause"); 

 

return 0; 

}

 

 

if (k>1) C1 = C2; 

 

 

if (k>2) R1 = R2; 

 

 

k++; h/=2; 

 

 

f = 0; x = a + h/2; 

 

 

while (x<b) 

 

 

 

 

 

f += fx(x); 

 

 

 

x += h; 

 

 

 

 

T2 = (T1 + h * f) / 2; 

 

 

S2 = T2 + (T2 - T1)/3; 

 

 

if (k==1) continue; 

 

 

C2 = S2 + (S2 - S1)/15; 

 

 

if (k==2) continue; 

 

 

R2 = C2 + (C2 - C1)/63; 

 

 

 

 

system("pause"); 

 

return 0; 

B

.中心加速求导:

 

// y = e^ x 

#include <iostream> 

#include <cmath> 

#define eps 1e-6 

using namespace std; 

double G(double h) 

 

if (h<0) h = -h; 

 

return (exp(1+h) - exp(1-h))/(2*h); 

 

int main() 

 

double h; 

 

cin>>h; 

 

 

double S1, S2, T1, T2, C1, C2, R1, R2; 

 

double x, f; 

 

T2 = T1 = G(h); 

 

int k = 0; 

 

R1=0; R2=1; h *= 2; 

 

while (fabs(R2-R1)>eps) 

 

 

 

 

 

cout<<T2<<" "; 

 

 

if (k>1) cout<<S2<<" "; 

 

 

if (k>2) cout<<C2<<" "; 

 

 

if (k>3) cout<<R2; 

 

 

cout<<endl; 

 

 

 

 

 

T1 = T2; 

 

 

 

 

 

S1 = S2; 

 

 

if (k>1) C1 = C2; 

 

 

if (k>2) R1 = R2; 

 

 

k++; h/=2; 

 

 

T2 = G(h); 

 

 

S2 = T2 + (T2 - T1)/3; 

 

 

if (k==1) continue; 

 

 

C2 = S2 + (S2 - S1)/15; 

 

 

if (k==2) continue; 

 

 

R2 = C2 + (C2 - C1)/63; 

 

 

system("pause"); 

 

return 0; 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李霁明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值