求助.继续求助 请高手指导
#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