| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 492 人关注过本帖
标题:求助.继续求助 请高手指导
只看楼主 加入收藏
snowkiss
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-3-14
结帖率:50%
收藏
已结贴  问题点数:16 回复次数:3 
求助.继续求助 请高手指导
#define M_E    2.71828182845904523536
#include <iostream>
#include <math.h>
#include <stdio.h>


using namespace std;

float r,ds,B,b,t;               // r is radius, ds is the density of substance, B is Buoyancy force, b is damping coefficient, m is the mass of substance
const float g=9.81;
const float dw=1000;           // dw is density of water
const float Pi =3.1415926;

void main()  {

    float a,v,s,m;
    int im;
    cout<<"r=?\n";                //prompt for read of r
    cin>> r;
    B = dw*4*Pi*r*r*r*g/3;              //do the computation for Buoyancy force
    b = 6*Pi*0.01*r;                 //do the computation for damping coefficient
    cout<<" The Buoyancy force  = "<<B<<"\n";             //display the Buoyancy force B
    cout<<" The damping coefficient  = "<<b<<"\n";        //display damping coefficient b

    cout <<"ds=?"; cin >>ds;       //prompt for read of density of substance and give a value for it
    m = ds*4*Pi*r*r*r/3;       //do the computation for the mass of ball

   

for (im=1,t=0.1;t<=10;im++,t+=0.10)  // loop from 0.1 to 10   im is a counter and start from 1
   
{
        v=(m*g-B)/b*(1-pow(float(M_E),-(b*t)/m));        //do the computation
        a=(m*g-B)/m*pow(float(M_E),-(b*t)/m);       //do the computation
        s=(m*g-B)/b* (t+m/b*(pow(float(M_E),-(b*t)/m)-1)) ;       //do the computation

            cout<<" v= "<<v<<"m/s\t";
                        cout<<" a= "<<a<<"m/s^2\t";
                        cout<<" s= "<<s<<"m\n";
        }
   

    cout <<"t=?"; cin >>t;        //prompt for read of time step and give a value for it

    for (im=1,t=0.1;t<=10;im++,t+=0.10)  // loop from 0.1 to 10   im is a counter and start from 1
    {
        v=(m*g-B)/b*(1-pow(float(M_E),-(b*t)/m));
        a=(m*g-B)/m*pow(float(M_E),-(b*t)/m);
        s=(m*g-B)/b* (t+m/b*(pow(float(M_E),-(b*t)/m)-1)) ;
        if (im%10==0)      // when im could be divided by 10 with no remainder
        {
             cout<<" v= "<<v<<"m/s\t";  // calculate every ten times values of velocity
             cout<<" a= "<<a<<"m/s^2\t";  // calculate every ten times values of acceleration
             cout<<" s= "<<s<<"m\n";  // calculate every ten times values of distance
        }
    }
     
}

#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
class avs;
float velocity(int nv,vector<avs >& fv,avs &temp);
float acceleration(int na,vector<avs >& fv,avs &temp);
float distance(int ns,vector<avs >& fv,avs &temp);
float r,ds,B,b,t;
const float g=9.81;
const float dw=1000;
const float Pi =3.1415926;
bool ba=false,bb=false,bc=false;

float m;

class avs
{
public:
    float a;
    float v;
    float s;
protected:
private:
};

void main()  {

    vector<avs> farray;
    cout<<"r=?\n";
    cin>> r;
    B = dw*4*Pi*r*r*r*g/3;
    b = 6*Pi*0.01*r;
    cout<<" The Buoyancy force  = "<<B<<"\n";
    cout<<" The damping coefficient  = "<<b<<"\n";

    int i;
    cout <<"ds=?"; cin >>ds;
    m = ds*4*Pi*r*r*r/3;

    cout <<"t=?"; cin >>t;

    for (i=0;i<=100;i++) {
        avs temp;
        cout << "v"<<i<<"="<<velocity(i,farray,temp)<<"m/s\t";
        cout << "a"<<i<<"="<<acceleration(i,farray,temp)<<"m/s^2\t";
        cout << "s"<<i<<"="<<distance(i,farray,temp)<<"m\n";
        farray.push_back(temp);
    }
}

float velocity(int nv,vector<avs >& fv,avs &temp) {
    float v;
    if (nv!=0)
    {   
         
        temp.v=v=fv[nv-1].v+fv[nv-1].a*t;
    }
    else
    {
        v=0;
        temp.v=0;
    }
    return (v);
}



float acceleration(int na,vector<avs >& fv,avs &temp) {
    float a;
    if (na==0)
    {
        a=temp.a=g*(1-dw/ds);
    }
    else
    {
        a=temp.a=g-3*(B+b*fv[na-1].v)/(4*Pi*r*r*r*ds);
         
    }
    return (a);
}

float distance(int ns,vector<avs >& fv,avs &temp) {
    float s;
    if (ns==0)
    {
        s=temp.s=0;
    }
    else
    {   
        s=temp.s=fv[ns-1].s+0.5*t*(fv[ns-1].v+temp.v);
        //s=distance(ns-1)+0.5*t*(velocity(ns-1)+velocity(ns));
    }
    return (s);
}
两个程序 合并成一个  最后结果要是这样 还要有个差值
euler method         analytic method     difference
a1    v1   s1       a1    v1    s1      a 1  v1   s1
a2     v2   s2      a2    v2    s2
求助高手..+Q286811803
搜索更多相关主题的帖子: 指导 
2010-03-23 20:47
james230932
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:162
专家分:629
注 册:2008-1-20
收藏
得分:5 
来学习的。。

老天给了我十根纤纤玉指,我却用它们来挖鼻屎。
2010-03-25 15:11
guchao2009
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:101
专家分:106
注 册:2009-4-13
收藏
得分:5 
高手
vector<avs >& fv,avs &temp

容器都使用到了
正在朝这个努力中···
2010-03-26 12:49
asdjc
Rank: 6Rank: 6
来 自:武汉
等 级:侠之大者
威 望:7
帖 子:98
专家分:487
注 册:2010-1-22
收藏
得分:5 
太长了,又没注解,高手不会看的。
先注解了在说。
2010-03-27 11:31
快速回复:求助.继续求助 请高手指导
数据加载中...
 
   



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

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