该代码用于绘制NACA机翼.打印YC时,我收到了限制错误
The code is for to plot naca airfoil. I received the out of bound error when printing yc
此代码用于循环通过将x的值放在等式中来查找yc的值。错误是"错误:mat :: operator():index out dound of dound of dercation in抛出" std :: logic_error"的实例what():mat :: operator():从范围索引"。
#include<iostream>
#include<armadillo>
#include<vector>
using namespace std;
using namespace arma;
int main()
{
float a[3];
float c;
int gp = 100;
cout << "Please Enter NACA 4 digits" << endl;
cout << "Please Enter 1st digit" << endl;
cin >> a[0] ;
cout << "Please Enter 2nd digit" << endl;
cin >> a[1] ;
cout << "Please Enter last 2 digits" << endl;
cin >> a[2] ;
cout << "Please Enter Chord Length" << endl;
cin >> c;
float m=(a[0]*c)/100;
float p=(a[1]*c)/10;
float t=(a[2]*c)/100;
cout << m << endl;
cout << p << endl;
cout << t << endl;
vec x = linspace<vec>(0, c, gp);
vec yc = linspace<vec>(0, 1, gp);
for(int i=0;i<=100;i=i+1)
{
if (x(i)=0 && x(i) <= p){
cout<< x(i)<<endl;
yc(i)= (m/(p*p))*(2*p*(x(i))-(x(i)*x(i)));
}
else {
yc(i)=(m/((1-p)*(1-p)))*((1-(2*p))+(2*p*x(i))-(x(i)*x(i)));
}
}
cout<<yc<<endl;
return 0;
}
linspace<vec>
很可能是基于零的数组。有100个元素,最后一个索引为99。
因此,替换
for(int i=0;i<=100;i=i+1)
for(int i=0;i<100;++i)
我替换了i=i+1
,因为我发现该符号难以忍受。
相关文章:
- C++ OpenGL 中,绘制形状返回错误
- 使用 SFML 绘制曲线会给出错误的形状
- SFML 2.4.2 - 绘制文本时出现分段错误
- 绘制精灵会导致分割错误
- 在Visual Code 2019中使用graphics.h绘制线条时,如何修复错误E0167和C2019?
- 当我尝试绘制 sf::Text 对象时,SFML 中的分段错误
- CGAL 绘制函数在 Visual Studio 中给出'CGAL_USE_BASIC_VIEWER is not defined'错误
- 将自定义可绘制对象存储在数组中会导致绘制时出现分割错误
- 通过 GdkPixbuf 绘制时会绘制错误的像素坐标
- 即使 OpenGL、SDL 和 GLSL 都没有抛出错误,也没有绘制多边形
- OpenGL 几何着色器三角形不会绘制而没有错误
- 该代码用于绘制NACA机翼.打印YC时,我收到了限制错误
- 尝试绘制精灵地图时出现 SFML 错误
- C++SFML精灵没有绘制,但是没有出现错误
- 绘制 VBO 会导致分割错误
- FLTK 绘制像素图给出段错误
- 在c++中绘制填充立方体,崩溃,没有有用的错误可以跟踪
- 绘制从类返回的文本会导致程序停止而不会出现错误
- 即使没有发生错误,三角形也不会在屏幕openGL上绘制
- 在cocos2dx v3.6中绘制精灵错误