Apollo 10.0
自动驾驶开放平台
integral.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <array>
20
21#include "cyber/common/log.h"
22
23namespace apollo {
24namespace common {
25namespace math {
26
27double IntegrateBySimpson(const std::vector<double>& func, const double dx,
28 const std::size_t nsteps) {
29 CHECK_EQ(1U, nsteps & 1);
30 double sum1 = 0.0;
31 double sum2 = 0.0;
32 for (std::size_t i = 1; i + 1 < nsteps; ++i) {
33 if ((i & 1) != 0) {
34 sum1 += func[i];
35 } else {
36 sum2 += func[i];
37 }
38 }
39 return dx / 3.0 * (4.0 * sum1 + 2.0 * sum2 + func[0] + func[nsteps - 1]);
40}
41
42double IntegrateByTrapezoidal(const std::vector<double>& func, const double dx,
43 const std::size_t nsteps) {
44 double sum = 0;
45 for (std::size_t i = 1; i + 1 < nsteps; ++i) {
46 sum += func[i];
47 }
48 return dx * sum + 0.5 * dx * (func[0] + func[nsteps - 1]);
49}
50
51} // namespace math
52} // namespace common
53} // namespace apollo
Functions to compute integral.
double IntegrateByTrapezoidal(const std::vector< double > &func, const double dx, const std::size_t nsteps)
Definition integral.cc:42
double IntegrateBySimpson(const std::vector< double > &func, const double dx, const std::size_t nsteps)
Definition integral.cc:27
class register implement
Definition arena_queue.h:37