帮我解决这个问题... [英] Help me in this Question...

查看:79
本文介绍了帮我解决这个问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个弹丸从地球表面向上发射.
假定作用在物体上的唯一力是重力的向下力.
在这种情况下,可以使用力平衡来导出

dv =-g(0)(R)2
dt(R + x)2


哪里
v =上升速度(m/s),
t =时间(s),
x =从地面向上测量的高度(m),
g(0)=地表的重力加速度(9.8m/s2),
R =地球半径(6.37x 106 m).

认识到dx/dt = v,请使用(Runge Kutta
方法)来确定在v(t = 0)= 1400 m/s且
时将获得的最大高度 达到最大值的时间.
解决方案:

V(t =?)= 0
初始条件
t = 0 s
v(t = 0)= 1400m/s; Xmax
x(t = 0)= 0m; ________________

dv =-g(0)(R)2
dt(R + x)2

dv = -9.8(6.37 x 106)2
dt(6.37 x 106 + X)2

= -9.8(4.05769 x 1013)
(6.37x106 + X)

=(-3.9765362x1014)
(6.37x106 + X)2


涉及方程式

dv = d2x =(-3.9765362x1014)………….(1)
dt dt2(6.37x106 + X)2

dv = V……………………………..(2)
dt


初始状态
x = 0m; t = 0s; v = 1400m/s

下一页是使用输出进行编程+
图为Runge-Kutta 4th的二阶导数..



我尝试执行C ++程序..请帮助我..

Suppose that a projectile is launched upward from the earth’s surface.
Assume that the only force acting on the object is the downward force of gravity.
Under these conditions, a force balance can be used to derive

dv = - g (0) ( R )2
dt ( R + x)2


Where
v = upward velocity (m/s),
t = time (s),
x = altitude (m) measured upward from the earth’s surface,
g(0) = the gravitational acceleration at the earth’s surface ( 9.8 m/s2),
R= the earth’s radius ( 6.37 x 106 m).

Recognizing that dx/dt = v, use (Runge Kutta
method) to determine the maximum height that would be obtained if v(t = 0) = 1400 m/s, and
the time that maximum would be reached.
Solution :

V(t= ?) = 0
Initial Condition
t = 0 s
v(t=0) = 1400m/s ; Xmax
x(t=0) = 0m ; ________________

dv = - g (0) ( R )2
dt ( R + x)2

dv = -9.8 (6.37 x 106 ) 2
dt (6.37 x 106 + X)2

= -9.8 (4.05769 x 1013)
(6.37x106 + X)

= (-3.9765362x1014)
(6.37x106 + X) 2


Equation involved

dv = d2x = (-3.9765362x1014) ………….(1)
dt dt2 (6.37x106 + X) 2

dv = V ………………………………….(2)
dt


with initial condition
x=0m ; t=0s ; v =1400m/s

Next Page is Programming with the Output +
Graph for Runge-Kutta 4th for 2nd order derivative..



I try do the C++ program..Please help me..

#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <math.h>

#define dydx(X,Y,Z) Z
#define dzdx(X,Y,Z) -3.98*(10^14)/(6.37*(10^6) + Y)^2

using namespace std;

void main()
{
int j;
float k1, k2, k3,k4, l1,l2,l3,l4,x1,y1,z1;
float x,h,y,z;
float dydx,dzdx;
int bil_step;
FILE *fp;
fp=fopen("c:\\BC5\\rkuta4_2.txt","w");
h=0.1;  //tukar step size
y=0.0;   //tukar initial condition dependent variable
z=1400.0;   //tukar initial condition dependent variable
x=0.0;   //tukar initial condition independent variable
bil_step=101; // tukar bilangan step
for(j=0;j<bil_step;j++)
{
printf("%.2f %f %f\n",x, z,y);
fprintf(fp,"%.2f %f %f\n",x, z,y);
k1=h*(dydx(x,y,z));
l1=h*(dzdx(x,y,z));

x1=x+0.5*h;
y1=y+0.5*k1;
z1=z+0.5*l1;
k2=h*(dydx(x1, y1, z1));
l2=h*(dzdx(x1, y1, z1));

x1=x+0.5*k2;
z1=z+0.5*l2;
k3=h*(dydx(x1, y1, z1));
l3=h*(dzdx(x1, y1, z1));


x1=x+h;
y1=y+k3;
z1=z+l3;
k4=h*(dydx(x1, y1,z1));
l4=h*(dzdx(x1, y1, z1));



y=y+(k1+2.0*k2+2.0*k3+k4)/6.0;
z=z+(l1+2.0*l2+2.0*l3+l4)/6.0;
x=x+h;
}
fclose(fp);
getch();
return;
}

推荐答案

是的.
我们了解无法运行",您需要提供更多信息.

但是,如果查看dzdx的#define,似乎会误用^运算符.从您的代码中可以看出,您试图将^用作幂"运算符.

即a ^ 2 = a * a

这在C语言中是错误的.^运算符是按位异或.
要实现a * a,可以使用pow(a, 2);

在此处检查按位运算符: C语言中的运算符 [
Yes, indeed.
We understand that "It can''t run" You need to provide more info.

HOWEVER looking at the #define for dzdx, it appears that the ^ operator is being misused. It appears from your code that you''re trying to use ^ as a ''power of'' operator.

I.e a^2 = a*a

This is incorrect in C. The ^ operator is a bitwise xor.
To achieve a*a, one would use pow(a, 2);

Check Bitwise Operators here: Operators in C[^]


C/C++中,字符"^ "用于按位异或,您应该改用 pow [ ^ ]函数.
那就是变化
in C/C++ the character ''^'' is used for the bitwise XOR, you should use instead the pow[^] function.
That is change
#define dzdx(X,Y,Z) -3.98*(10^14)/(6.37*(10^6) + Y)^2







to

float dzdx(float x, float y, float z)
{
  return -3.98*pow(10.f,14.f)/((6.37*pow(10.f,6.f) + y)*(6.37*pow(10.f,6.f) + y));
}



删除相应的变量(float dydx,dzdx;).

请注意,使用float s代替double s通常不会提高性能.



and remove the corrensponding variables (float dydx,dzdx;).

Please note there is (usually) no performance gain using floats instead of doubles.


这篇关于帮我解决这个问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆