求一个曲线微分运算中,算出的结果与标准答案不一致,哪位能帮我实现一下代码:
已知:
曲线x轴数据为:vector xTestValue{0,0.04,0.08,0.12,0.16,0.2,0.24,0.28,0.32,0.36,0.4,0.44,0.48,0.52,0.56,0.6,0.64,0.68,0.72,0.76,0.8,0.84,0.88,0.92,0.96,1,1.04,1.08,1.12,1.16,1.2,1.24,1.28,1.32,1.36,1.4,1.44,1.48,1.52,1.56,1.6,1.64,1.68,1.72,1.76,1.8,1.84,1.88,1.92,1.96,2};
y轴数据为:vector yTestValue{78.663,76.6812,70.881,61.501,49.0311,34.093,17.2773,0.398,18.0689,34.6276,49.7299,62.1964,71.5271,77.2401,79.0513,76.8787,70.8361,61.2236,48.5125,33.3267,16.4178,1.3669,19.1249,35.9457,50.9619,63.4,72.6246,78.1722,79.7716,77.3519,71.0391,61.1462,48.1581,32.712,15.5725,2.401,20.2958,37.1937,52.2231,64.6098,73.7216,79.1011,80.4865,77.8177,71.2332,61.0588,47.7929,32.0862,14.7165,3.4449,21.4751};
求改组数据的微分运算结果result,并使得result为:{-1.5124, -97.5738, -191.8419, -273.5776, -352.5908, -371.6553, -542.3236, 13.8252, 546.3998, 367.7909, 357.0105, 271.8291, 190.4617, 94.6038, -4.5604, -103.4705, -197.6991, -279.8679, -357.1013, -383.9905, -514.0355, 43.147, 544.4804, 372.3394, 353.932, 271.0056, 186.7504, 89.9056, -10.35, -110.0286, -204.473, -287.5023, -361.5929, -398.6597, -487.5443, 75.5487, 539.5978, 375.5104, 352.9053, 269.0776, 183.169, 85.0927, -16.1688, -116.6703, -211.1481, -295.655, -364.2518, -420.2826, -435.3484, 13.5777, 887.9301};
本人在尝试多种微分运算后,仍然无法得到想要的result结果,哪位能帮帮我。
#include <iostream>
#include <vector>
int main() {
// 曲线x轴数据
std::vector<double> xTestValue = {0,0.04,0.08,0.12,0.16,0.2,0.24,0.28,0.32,0.36,0.4,0.44,0.48,0.52,0.56,0.6,0.64,0.68,0.72,0.76,0.8,0.84,0.88,0.92,0.96,1,1.04,1.08,1.12,1.16,1.2,1.24,1.28,1.32,1.36,1.4,1.44,1.48,1.52,1.56,1.6,1.64,1.68,1.72,1.76,1.8,1.84,1.88,1.92,1.96,2};
// 曲线y轴数据
std::vector<double> yTestValue = {78.663,76.6812,70.881,61.501,49.0311,34.093,17.2773,0.398,18.0689,34.6276,49.7299,62.1964,71.5271,77.2401,79.0513,76.8787,70.8361,61.2236,48.5125,33.3267,16.4178,1.3669,19.1249,35.9457,50.9619,63.4,72.6246,78.1722,79.7716,77.3519,71.0391,61.1462,48.1581,32.712,15.5725,2.401,20.2958,37.1937,52.2231,64.6098,73.7216,79.1011,80.4865,77.8177,71.2332,61.0588,47.7929,32.0862,14.7165,3.4449,21.4751};
// 计算微分结果
std::vector<double> result;
for (int i = 0; i < yTestValue.size() - 1; i++) {
double diff = yTestValue[i + 1] - yTestValue[i];
result.push_back(diff);
}
// 输出结果
for (double value : result) {
std::cout << value << ", ";
}
std::cout << std::endl;
return 0;
}
希望对你有所帮助