如何将方程式放入矩阵中
How to put equations into a matrix?
本文关键字:方程式 更新时间:2023-10-16
我正在编写一个程序来求解多个方程,但这与此无关。我遇到的问题是解方程式。
例如,我有一个名为data.txt
的文件,其内容如下:
2x - 5y + 3z = 10
5x + y - 2z = 4
我已经尝试了很长一段时间来解释它,但没有成功,因为我认为C++会有类似str.split()的东西
2 -5 3 10
5 1 -2 4
我该怎么做?
vector>数据
逐行读取data.txt:字符串行
使用分隔符"\t+-="拆分行:矢量标记
将令牌转换为数字格式:vector v
将v推送到数据:data.push_back(v)
更新:
vector<string> split(const string &s, const string &d)
{
vector<string> t;
string::size_type i = s.find_first_not_of(d);
string::size_type j = s.find_first_of(d,i);
while (string::npos != i || string::npos != j) {
t.push_back(s.substr(i,j-i));
i = s.find_first_not_of(d,j);
j = s.find_first_of(d,i);
}
return t;
}
int main()
{
vector<vector<double> > x;
ifstream ifs("data.txt");
string ls;
while (getline(ifs,ls))
{
vector<string> ts = split(ls," t+-=");
vector<dobule> v;
for (auto& s : ts)
v.push_back( atof(s.c_str()) );
x.push_back(v);
}
return 0;
}
相关文章:
- 如何在 WxWidgets 中显示方程式的答案?
- 如何使用istream_iterators拆分方程式
- 如何将我的输出用于另一个方程式
- 如何在Visual Studio 2017 IDE中替换数学方程式
- 将3个变量方程式分为C 中的双打和字符
- 优化一个简单的方程式,用于C 中的执行速度
- CPP代码方程式返回相同值,无论输入如何
- 移动方程式deltAheight =(sin(runningtime deltatime) - sin(runni
- 如何从方程式提取变量
- 没有从方程式中得到正确的答案.还有无限循环
- 我的OpenGL/Glut.h代码上的参数方程式错误
- 我无法理解方程式的解决方案,该方程式说找到了最小的数字,因此x plus y等于x bitwise或y
- 初学者C 教科书不同意我在编译数学方程式时获得的实际输出
- 如何将方程式放入矩阵中
- 如何让C++求解输入值的方程式
- If/Else语句或方程式
- 从文本中读取方程式
- 如何将字符串转换为数学方程式
- vs2008中的方程式演算错误
- 用于方程式的面向对象API