html中sin函数输出NaN,使用sin和cos函数迭代时的Nan结果

我正在使用Code :: Blocks 10.05编译此程序,但通常我会在每次输出中开始生成Nan之前完成大约10次迭代。我想知道这是否是由于使用cos和sin函数而引起的问题,以及是否有体面的工作来避免这种情况?使用sin和cos函数迭代时的Nan结果

我必须产生很多迭代,因为我正在为大学开展一个项目,所以它也必须是准确的。我查阅了一些关于如何避免使用罪恶和罪恶的文章,尽管我需要严格遵循几个公式,否则我产生的结果可能不准确,所以我不确定是否妥协。

struct Particle // Need to define what qualities our particle has

{

double dPosition;

double dAngle;

};

Particle Subject;

void M1(double &x, double &y) //Defines movement if particle doesn't touch inner boundary

{

x = x + 2*y;

}

double d = 0.25; //This can and will be changed when I need to find a distance between

// the two cricles at a later stage

void M2(double &x,double &y, double d) //Defines movement of a particle if it impacts the inner boundary

{

double z = asin(-(sin(y)+d*cos(x + y))/0.35);

double y1 = y;

y = asin(-0.35*sin(z) + d*cos(x + y + 2*z));

x = y + y1 + x + 2*z;

}

int main()

{

cout << "Please tell me where you want this particle to start positions-wise? (Between 0 and 2PI" << endl;

cin >> Subject.dPosition;

cout << "Please tell me the angle that you would like it to make with the normal? (Between 0 and PI/2)" << endl;

cin >> Subject.dAngle;

cout << "How far would you like the distances of the two middle circles to be?" << endl;

double d;

cin >> d;

// These two functions are to understand where the experiment begins from.

// I may add a function to change where the circle starts however I will use radius = 0.35 throughout

cout << "So position is: " << Subject.dPosition << endl;

cout << "And angle with the normal is: " << Subject.dAngle <

int n=0;

while (n <= 100) //This is used to iterate the process and create an array of Particle data points

{ // in order to use this data to build up Poincare diagrams.

{

while (Subject.dPosition > 2*M_PI)

Subject.dPosition = Subject.dPosition - 2*M_PI;

}

{

if (0.35 >= abs(0.35*cos(Subject.dPosition + Subject.dAngle)+sin(Subject.dAngle))) //This is the condition of hitting the inner boundary

M2(Subject.dPosition, Subject.dAngle, d); //Inner boundary collision

else

M1(Subject.dPosition, Subject.dAngle); // Outer boundary collision

};

cout << "So position is: " << Subject.dPosition << endl;

cout << "And angle with the normal is: " << Subject.dAngle <

n++;

}

return 0;

}

+1

我把我的钱放在'asin()'函数成为问题。 Arcsin没有为所有输入定义。我的意思是它的行为是正确的,但结果是不受欢迎的。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值