| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1304 人关注过本帖
标题:我用C++写的龙贝格算法无法运行,请高手们帮忙看看
只看楼主 加入收藏
天怒浪子
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-10-18
收藏
 问题点数:0 回复次数:5 
我用C++写的龙贝格算法无法运行,请高手们帮忙看看
#include<iostream>
#include<cmath>
using namespace std;
double f(double x);
double zt2(double,double,double,double);
double zs2(double,double);
double zc2(double,double);
double zr2(double,double);
const double e=0.00001;
int main()
{
    double a,b,h,t1,t2,c1,c2,s1,s2,r1,r2;
    int k;
    k=1;
    cout<<"please input a and b"<<endl;
    cin>>a>>b;
    h=b-a;
    t1=h/2*(f(a)+f(b));
    t2=zt2(t1,h,a,b);
    s2=zs2(t2,t1);
        k=k+1;
        h=h/2;
        t1=t2;
        s1=s2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        h=h/2;
        c2=zc2(s2,s1);
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
        k=k+1;
        h=h/2;
        r1=r2;
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
    for(k=4;abs(r2-r1)<e;k++)
        {
        
                    h=h/2;
                    r1=r2;
                    c1=c2;
                    s1=s2;
                    t1=t2;
                    t2=zt2(t1,h,a,b);
                    s2=zs2(t2,t1);
                    c2=zc2(s2,s1);
                     r2=zr2(c2,c1);
        
    }
    cout<<"r2 is"<<r2<<endl;
    return 0;
}
double f(double x)
{
    double z;
    z=sin(x)/x;
    return z;
}
double zt2(double t1,double h,double a,double b)
{
    double s=0,T2;
    for(a=a+h/2;a<b;a=a+h)
    s=s+f(a);
    T2=1/2*t1+h/2*s;
    return T2;
}
double zs2(double T2,double T1)
{
    double S2;
    S2=T2+1/3*(T2-T1);
    return S2;
}

double zc2(double S2,double S1)
{
    double C2;
    C2=S2+1/15*(S2-S1);
    return C2;
}

double zr2(double C2,double C1)
{
    double R2;
    R2=C2+1/63*(C2-C1);
    return R2;
}
搜索更多相关主题的帖子: 龙贝格 算法 运行 
2008-10-18 16:54
天怒浪子
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-10-18
收藏
得分:0 
摆脱,很急的,看了快点回复
#include<iostream>
#include<cmath>
using namespace std;
double f(double x);
double zt2(double,double,double,double);
double zs2(double,double);
double zc2(double,double);
double zr2(double,double);
const double e=0.00001;
int main()
{
    double a,b,h,t1,t2,c1,c2,s1,s2,r1,r2;
    int k;
    k=1;
    cout<<"please input a and b"<<endl;
    cin>>a>>b;
    h=b-a;
    t1=h/2*(f(a)+f(b));
    t2=zt2(t1,h,a,b);
    s2=zs2(t2,t1);
        k=k+1;
        h=h/2;
        t1=t2;
        s1=s2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        h=h/2;
        c2=zc2(s2,s1);
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
        k=k+1;
        h=h/2;
        r1=r2;
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
    for(k=4;abs(r2-r1)<e;k++)
        {
        
                    h=h/2;
                    r1=r2;
                    c1=c2;
                    s1=s2;
                    t1=t2;
                    t2=zt2(t1,h,a,b);
                    s2=zs2(t2,t1);
                    c2=zc2(s2,s1);
                     r2=zr2(c2,c1);
        
    }
    cout<<"r2 is"<<r2<<endl;
    return 0;
}
double f(double x)
{
    double z;
    z=sin(x)/x;
    return z;
}
double zt2(double t1,double h,double a,double b)
{
    double s=0,T2;
    for(a=a+h/2;a<b;a=a+h)
    s=s+f(a);
    T2=1/2*t1+h/2*s;
    return T2;
}
double zs2(double T2,double T1)
{
    double S2;
    S2=T2+1/3*(T2-T1);
    return S2;
}

double zc2(double S2,double S1)
{
    double C2;
    C2=S2+1/15*(S2-S1);
    return C2;
}

double zr2(double C2,double C1)
{
    double R2;
    R2=C2+1/63*(C2-C1);
    return R2;
}
2008-10-18 16:56
天怒浪子
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-10-18
收藏
得分:0 
摆脱,很急的,看了快点回复
#include<iostream>
#include<cmath>
using namespace std;
double f(double x);
double zt2(double,double,double,double);
double zs2(double,double);
double zc2(double,double);
double zr2(double,double);
const double e=0.00001;
int main()
{
    double a,b,h,t1,t2,c1,c2,s1,s2,r1,r2;
    int k;
    k=1;
    cout<<"please input a and b"<<endl;
    cin>>a>>b;
    h=b-a;
    t1=h/2*(f(a)+f(b));
    t2=zt2(t1,h,a,b);
    s2=zs2(t2,t1);
        k=k+1;
        h=h/2;
        t1=t2;
        s1=s2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        h=h/2;
        c2=zc2(s2,s1);
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
        k=k+1;
        h=h/2;
        r1=r2;
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
    for(k=4;abs(r2-r1)<e;k++)
        {
        
                    h=h/2;
                    r1=r2;
                    c1=c2;
                    s1=s2;
                    t1=t2;
                    t2=zt2(t1,h,a,b);
                    s2=zs2(t2,t1);
                    c2=zc2(s2,s1);
                     r2=zr2(c2,c1);
        
    }
    cout<<"r2 is"<<r2<<endl;
    return 0;
}
double f(double x)
{
    double z;
    z=sin(x)/x;
    return z;
}
double zt2(double t1,double h,double a,double b)
{
    double s=0,T2;
    for(a=a+h/2;a<b;a=a+h)
    s=s+f(a);
    T2=1/2*t1+h/2*s;
    return T2;
}
double zs2(double T2,double T1)
{
    double S2;
    S2=T2+1/3*(T2-T1);
    return S2;
}

double zc2(double S2,double S1)
{
    double C2;
    C2=S2+1/15*(S2-S1);
    return C2;
}

double zr2(double C2,double C1)
{
    double R2;
    R2=C2+1/63*(C2-C1);
    return R2;
}
2008-10-18 16:57
天怒浪子
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-10-18
收藏
得分:0 
摆脱,很急的,看了快点回复
#include<iostream>
#include<cmath>
using namespace std;
double f(double x);
double zt2(double,double,double,double);
double zs2(double,double);
double zc2(double,double);
double zr2(double,double);
const double e=0.00001;
int main()
{
    double a,b,h,t1,t2,c1,c2,s1,s2,r1,r2;
    int k;
    k=1;
    cout<<"please input a and b"<<endl;
    cin>>a>>b;
    h=b-a;
    t1=h/2*(f(a)+f(b));
    t2=zt2(t1,h,a,b);
    s2=zs2(t2,t1);
        k=k+1;
        h=h/2;
        t1=t2;
        s1=s2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        h=h/2;
        c2=zc2(s2,s1);
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
        k=k+1;
        h=h/2;
        r1=r2;
        c1=c2;
        s1=s2;
        t1=t2;
        t2=zt2(t1,h,a,b);
        s2=zs2(t2,t1);
        c2=zc2(s2,s1);
        r2=zr2(c2,c1);
    for(k=4;abs(r2-r1)<e;k++)
        {
        
                    h=h/2;
                    r1=r2;
                    c1=c2;
                    s1=s2;
                    t1=t2;
                    t2=zt2(t1,h,a,b);
                    s2=zs2(t2,t1);
                    c2=zc2(s2,s1);
                     r2=zr2(c2,c1);
        
    }
    cout<<"r2 is"<<r2<<endl;
    return 0;
}
double f(double x)
{
    double z;
    z=sin(x)/x;
    return z;
}
double zt2(double t1,double h,double a,double b)
{
    double s=0,T2;
    for(a=a+h/2;a<b;a=a+h)
    s=s+f(a);
    T2=1/2*t1+h/2*s;
    return T2;
}
double zs2(double T2,double T1)
{
    double S2;
    S2=T2+1/3*(T2-T1);
    return S2;
}

double zc2(double S2,double S1)
{
    double C2;
    C2=S2+1/15*(S2-S1);
    return C2;
}

double zr2(double C2,double C1)
{
    double R2;
    R2=C2+1/63*(C2-C1);
    return R2;
}
2008-10-18 16:57
沼泽
Rank: 4
等 级:业余侠客
威 望:8
帖 子:291
专家分:228
注 册:2008-9-15
收藏
得分:0 
楼主可以在for循环中加入cout<<abs(r2-r1)<<endl;
看看你的程序的计算过程
2008-10-19 16:15
vbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:352
专家分:147
注 册:2006-12-30
收藏
得分:0 
龙贝格算法好像挺麻烦的

清远鹏程万里人才网:[url=http://www.]http://www.[/url]zq.,qy.
2008-10-20 12:51
快速回复:我用C++写的龙贝格算法无法运行,请高手们帮忙看看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017133 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved