📄 阻尼振动.cpp
字号:
#include <a:ccbp.h>
void main()
{
double y,t,w0,w,b;
char c,m[20];
int N=1;
int gd=DETECT,gm;
initgraph(&gd,&gm,"e:\\borlandc\\bgi");
setbkcolor(3);
setcolor(5);
b=50;
w0=50;
do
{
cleardevice();
sprintf(m,"b=%d,w=%d",(int)b,(int)w0);
setcolor(4);
outtextxy(250,450,m);
setcolor(13);
outtextxy(530,470,"ESC-exit");
outtextxy(500,450,"Up-w+ Down-w-");
outtextxy(500,460,"Right-b+ Left-b-");
t=0;
setlinestyle(0,0,1);
coordc(40,350,590,0,590,1);
coordc(40,460,450,90,450,1);
setcolor(4);
outtextxy(615,355,"t");
outtextxy(45,20,"X");
setcolor(5);
setlinestyle(0,0,3);
if(fabs(b*b-w0*w0)<0.1)
{
outtextxy(200,430,"x=(c1+c2*t)*exp(-b*t)");
do
{
y=(300+10*0.01*t)*exp(-b*0.01*t);
if(t==0)
moveto(40,350-y);
else
lineto(40+30*t,350-y);
}while((t=t+0.1)<19);
}
else
if(b*b>w0*w0)
{
outtextxy(100,430,"x=c1*exp(-(b-sqrt(b*b-w*w))*t)+c2*exp(-(b+sqrt(b*b-w*w))*t)");
do
{
y=150*exp(-(b-sqrt(b*b-w0*w0))*0.01*t)+150*exp(-(b+sqrt(b*b-w0*w0))*0.01*t);
if(t==0)
moveto(40,350-y);
else
lineto(40+30*t,350-y);
}while((t=t+0.1)<19);
}
else
if(b*b<w0*w0)
{
outtextxy(200,430,"x=A*exp(-b*t)*cos(w*t)");
w=sqrt(w0*w0-b*b);
do
{
y=300*exp(-b*t*0.01)*cos(w*t*0.01);
if(t==0)
moveto(40,350-y);
else
lineto(40+30*t,350-y);
}while((t=t+0.1)<19);
}
c=getch();
if(c==75)
b=(b-2)<0?0:(b-2);
else
if(c==77)
b=b+2;
else
if(c==72)
w0=w0+2;
else
if(c==80)
w0=(w0-2)<0?0:(w0-2);
else
if(c==27)
N=0;
}while(N);
closegraph();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -