如何从数据中整合曲线

How to integrate curve from data

这是我的 x 值:

[2600.2 2601.2 2602.2 2603.1 2604.1 2605.1 2606.  2607.  2607.9 2608.9
 2609.9 2610.8 2611.8 2612.8 2613.7 2614.7 2615.7 2616.6 2617.6 2618.6
 2619.5 2620.5 2621.4 2622.4 2623.4 2624.3 2625.3 2626.3 2627.2 2628.2
 2629.2 2630.1 2631.1 2632.1 2633.  2634.  2635.  2635.9 2636.9 2637.8
 2638.8 2639.8 2640.7 2641.7 2642.7 2643.6 2644.6 2645.6 2646.5 2647.5
 2648.5 2649.4 2650.4 2651.3 2652.3 2653.3 2654.2 2655.2 2656.2 2657.1
 2658.1 2659.1 2660.  2661.  2662.  2662.9 2663.9 2664.9 2665.8 2666.8
 2667.7 2668.7 2669.7 2670.6 2671.6 2672.6 2673.5 2674.5 2675.5 2676.4
 2677.4 2678.4 2679.3 2680.3 2681.2 2682.2 2683.2 2684.1 2685.1 2686.1
 2687.  2688.  2689.  2689.9 2690.9 2691.9 2692.8 2693.8 2694.7 2695.7
 2696.7 2697.6 2698.6 2699.6 2700.5 2701.5 2702.5 2703.4 2704.4 2705.4
 2706.3 2707.3 2708.3 2709.2 2710.2 2711.1 2712.1 2713.1 2714.  2715.
 2716.  2716.9 2717.9 2718.9 2719.8 2720.8 2721.8 2722.7 2723.7 2724.6
 2725.6 2726.6 2727.5 2728.5 2729.5 2730.4 2731.4 2732.4 2733.3 2734.3
 2735.3 2736.2 2737.2 2738.2 2739.1 2740.1 2741.  2742.  2743.  2743.9
 2744.9 2745.9 2746.8 2747.8 2748.8 2749.7 2750.7 2751.7 2752.6 2753.6
 2754.5 2755.5 2756.5 2757.4 2758.4 2759.4 2760.3 2761.3 2762.3 2763.2
 2764.2 2765.2 2766.1 2767.1 2768.1 2769.  2770.  2770.9 2771.9 2772.9
 2773.8 2774.8 2775.8 2776.7 2777.7 2778.7 2779.6 2780.6 2781.6 2782.5
 2783.5 2784.4 2785.4 2786.4 2787.3 2788.3 2789.3 2790.2 2791.2 2792.2
 2793.1 2794.1 2795.1 2796.  2797.  2797.9 2798.9 2799.9 2800.8 2801.8
 2802.8 2803.7 2804.7 2805.7 2806.6 2807.6 2808.6 2809.5 2810.5 2811.5
 2812.4 2813.4 2814.3 2815.3 2816.3 2817.2 2818.2 2819.2 2820.1 2821.1
 2822.1 2823.  2824.  2825.  2825.9 2826.9 2827.8 2828.8 2829.8 2830.7
 2831.7 2832.7 2833.6 2834.6 2835.6 2836.5 2837.5 2838.5 2839.4 2840.4
 2841.4 2842.3 2843.3 2844.2 2845.2 2846.2 2847.1 2848.1 2849.1 2850.
 2851.  2852.  2852.9 2853.9 2854.9 2855.8 2856.8 2857.7 2858.7 2859.7
 2860.6 2861.6 2862.6 2863.5 2864.5 2865.5 2866.4 2867.4 2868.4 2869.3
 2870.3 2871.2 2872.2 2873.2 2874.1 2875.1 2876.1 2877.  2878.  2879.
 2879.9 2880.9 2881.9 2882.8 2883.8 2884.8 2885.7 2886.7 2887.6 2888.6
 2889.6 2890.5 2891.5 2892.5 2893.4 2894.4 2895.4 2896.3 2897.3 2898.3
 2899.2 2900.2 2901.1 2902.1 2903.1 2904.  2905.  2906.  2906.9 2907.9
 2908.9 2909.8 2910.8 2911.8 2912.7 2913.7 2914.7 2915.6 2916.6 2917.5
 2918.5 2919.5 2920.4 2921.4 2922.4 2923.3 2924.3 2925.3 2926.2 2927.2
 2928.2 2929.1 2930.1 2931.  2932.  2933.  2933.9 2934.9 2935.9 2936.8
 2937.8 2938.8 2939.7 2940.7 2941.7 2942.6 2943.6 2944.5 2945.5 2946.5
 2947.4 2948.4 2949.4 2950.3 2951.3 2952.3 2953.2 2954.2 2955.2 2956.1
 2957.1 2958.1 2959.  2960.  2960.9 2961.9 2962.9 2963.8 2964.8 2965.8
 2966.7 2967.7 2968.7 2969.6 2970.6 2971.6 2972.5 2973.5 2974.4 2975.4
 2976.4 2977.3 2978.3 2979.3 2980.2 2981.2 2982.2 2983.1 2984.1 2985.1
 2986.  2987.  2988.  2988.9 2989.9 2990.8 2991.8 2992.8 2993.7 2994.7
 2995.7 2996.6 2997.6 2998.6 2999.5 3000.5 3001.5 3002.4 3003.4 3004.3
 3005.3 3006.3 3007.2 3008.2 3009.2 3010.1 3011.1 3012.1 3013.  3014.
 3015.  3015.9 3016.9 3017.9 3018.8 3019.8]

和 y 值:

[-7.44466803e-04 -6.38664122e-04 -5.34609823e-04 -4.42448211e-04
 -3.41690555e-04 -2.42654847e-04 -1.54987591e-04 -5.91990560e-05
  2.55600336e-05  1.18132985e-04  2.09025991e-04  2.89400351e-04
  3.77124735e-04  4.63193491e-04  5.39246590e-04  6.22192168e-04
  7.03505639e-04  7.75298863e-04 -2.01875984e-04  9.30157920e-04
 -5.76584966e-05  1.59295034e-05  8.08012121e-05  1.51379342e-04
  2.20383942e-04  2.81148660e-04  3.47183293e-04  4.11664999e-04
 -5.85919853e-04 -5.24369726e-04 -4.64352721e-04 -4.11642743e-04
 -3.54520443e-04 -2.98912259e-04 -2.50154195e-04 -1.97405361e-04
 -1.46152432e-04 -1.01298756e-04 -5.28713359e-05 -1.05509367e-05
  3.50723226e-05  7.92280634e-05  1.17718164e-04 -8.94084909e-04
 -8.54153425e-04 -8.19451625e-04 -7.82263155e-04 -7.46510819e-04
 -7.15557404e-04 -6.82519783e-04 -6.50903801e-04 -6.23660938e-04
 -5.94732888e-04 -5.69901563e-04  5.09541266e-04 -5.18787274e-04
 -4.97608457e-04 -4.75397944e-04 -4.54574454e-04  6.16170144e-04
  6.34369460e-04  6.51193332e-04  6.65161962e-04  6.79382903e-04
  6.92239181e-04  7.02645966e-04  7.12919040e-04  7.21837433e-04
  7.28708431e-04  7.35061830e-04  7.39629406e-04  7.43428919e-04
 -3.07297461e-04  7.46958864e-04  7.46880284e-04  7.45469661e-04
  7.43063292e-04  7.39128670e-04 -3.19316915e-04 -3.25181546e-04
  7.20233508e-04  7.11143871e-04  7.01837339e-04  6.90247525e-04
  6.78693826e-04  6.64610321e-04  6.49216731e-04  6.34243638e-04
  6.16365002e-04  5.97180431e-04  5.78798777e-04  5.57136288e-04
  5.34171219e-04  5.12389754e-04  4.86952378e-04  4.60214976e-04
  4.35040369e-04  4.05834757e-04  3.78439674e-04  3.46767714e-04
  3.13798203e-04  2.83016440e-04  2.47582168e-04  2.10850784e-04
  1.76683478e-04  1.37487404e-04  9.69938540e-05  5.94400641e-05
  1.64803804e-05 -2.77779379e-05 -6.87212380e-05 -1.15448651e-04
 -1.63476655e-04 -2.07814574e-04 -2.58316150e-04 -3.04881898e-04
 -3.57860800e-04 -4.12145285e-04 -4.62118682e-04 -5.18887480e-04
 -5.76965937e-04 -6.30357620e-04 -6.90928891e-04 -7.52814695e-04
 -8.09637384e-04 -8.74026019e-04 -9.39734858e-04 -1.00000336e-03
 -1.39302040e-05 -7.64653255e-05 -1.47211271e-04 -2.19288563e-04
 -2.85298568e-04 -3.59912644e-04 -4.35865855e-04 -5.05371076e-04
 -5.83876630e-04 -6.63729907e-04 -7.36752757e-04 -8.19175452e-04
 -9.02955255e-04 -9.79520230e-04 -1.06588804e-03 -1.15362314e-03
 -1.23375682e-03 -2.68690973e-04 -3.51178179e-04 -4.44143508e-04
 -5.38494735e-04 -6.24599214e-04 -7.21595167e-04 -8.19989322e-04
 -9.09743181e-04 -1.01080619e-03 -1.11328051e-03 -1.20671793e-03
 -1.31188675e-03 -1.41848077e-03 -4.59113905e-04 -5.68429590e-04
 -6.68044666e-04 -7.80100637e-04 -8.93606563e-04 -9.97006096e-04
 -1.11328198e-03 -1.23102384e-03 -2.80608069e-04 -4.01151072e-04
 -5.23176860e-04 -6.34272793e-04 -7.59132433e-04 -8.85492469e-04
  5.82568375e-05 -7.09712713e-05 -2.01718186e-04 -3.20694386e-04
 -4.54345109e-04  4.83937944e-04  3.47359177e-04  2.09229380e-04
  8.35806570e-05 -5.75154297e-05 -2.00183075e-04  7.31074418e-04
  5.85400722e-04  4.38134142e-04  1.36636107e-03  1.21604716e-03
  1.06411824e-03  9.25994929e-04  1.83424021e-03  1.69332288e-03
  1.53518486e-03  2.43978952e-03  2.29455679e-03  2.13160111e-03
  3.03249801e-03  2.88288661e-03  2.71504221e-03  3.61216191e-03
  3.45810648e-03  4.35310574e-03  4.17857074e-03  5.08895105e-03
  4.91110676e-03  5.81963759e-03  5.63845053e-03  6.52672784e-03
  6.36053995e-03  7.24657091e-03  8.13195214e-03  7.96106363e-03
  8.84414958e-03  9.72656200e-03  9.55089781e-03  1.04309645e-02
  1.13103332e-02  1.22091471e-02  1.20067872e-02  1.28830348e-02
  1.37792517e-02  1.46542196e-02  1.55495062e-02  1.64231655e-02
  1.72960620e-02  1.81898177e-02  1.90613600e-02  2.10232224e-02
  2.19165774e-02  2.27871255e-02  2.47527537e-02  2.56456629e-02
  2.76146667e-02  2.95864701e-02  3.04801022e-02  3.24552956e-02
  3.44570839e-02  3.64381330e-02  3.73090546e-02  3.93176951e-02
  4.01883136e-02  3.99413472e-02  3.97172410e-02  3.83507327e-02
  3.69832945e-02  3.45288224e-02  3.31609323e-02  3.06840301e-02
  2.71317309e-02  2.46628156e-02  2.21965029e-02  2.08567884e-02
  1.94892933e-02  1.81480845e-02  1.78733224e-02  1.75962456e-02
  1.62501951e-02  1.59686819e-02  1.67795042e-02  1.65219970e-02
  1.62336140e-02  1.59428341e-02  1.56790710e-02  1.53836971e-02
  1.50858840e-02  1.48157546e-02  1.45132663e-02  1.53347956e-02
  1.39316877e-02  1.36219595e-02  1.33410446e-02  1.30265037e-02
  1.27094074e-02  1.24218231e-02  1.20998289e-02  1.06805433e-02
  1.03861716e-02  1.00565924e-02  9.72436664e-03  8.32959359e-03
  7.99229514e-03  7.68642420e-03  6.25169507e-03  5.90654091e-03
  5.59355915e-03  5.24318304e-03  4.89003437e-03  3.47870860e-03
  3.12024578e-03  2.75896150e-03  2.43137920e-03  2.06468706e-03
  1.69512373e-03  1.36004754e-03  9.84981135e-04  6.06993019e-04
  2.64291109e-04 -1.19296827e-04 -4.67067393e-04 -8.56319352e-04
 -1.57470803e-04 -5.13089904e-04 -9.11112209e-04 -1.31219422e-03
 -5.83499839e-04 -9.90445890e-04 -1.40050508e-03 -6.78741650e-04
 -1.09476716e-03 -4.19269184e-04 -7.99266490e-04 -1.28638967e-04
 -5.14130274e-04  1.51560600e-04 -2.83100227e-04  4.21200445e-04
  1.07979970e-03  6.35578391e-04  1.33364405e-03  1.98499815e-03
  1.53105139e-03  2.22274354e-03  1.76233437e-03  1.29849487e-03
  1.98245206e-03  1.51203930e-03  1.03813746e-03  6.08625763e-04
  1.28038297e-04 -3.07523898e-04 -7.94871439e-04 -1.28580703e-03
 -1.73073413e-03 -2.22854468e-03 -2.73000414e-03 -2.07887167e-03
 -2.58732249e-03 -1.99267690e-03 -2.45681242e-03 -1.86804972e-03
 -1.71336659e-04  4.66408985e-04  2.16330903e-03  2.79823358e-03
  3.37734816e-03  3.95383298e-03  5.70282896e-03  6.27564610e-03
  5.72281539e-03  6.34484289e-03  5.78445904e-03  5.22006708e-03
  4.70866859e-03  3.01363377e-03  2.43748942e-03  7.93751865e-04
 -9.10645379e-04 -2.55893384e-03 -4.26871417e-03 -4.86473696e-03
 -5.40475552e-03 -6.00879559e-03 -5.49914640e-03 -4.93107329e-03
 -4.42706670e-03 -3.92612623e-03 -3.36556562e-03 -2.87038286e-03
 -1.25156694e-03 -6.97404716e-04 -2.09949744e-04  1.40618052e-03
  1.95380580e-03  2.43337333e-03  2.97583880e-03  3.44934833e-03
  3.91956988e-03  4.45395838e-03  4.91800203e-03  4.23648918e-03
  4.76133123e-03  4.07090402e-03  3.37574816e-03  2.74604376e-03
  2.04183294e-03  1.33281906e-03  1.83408931e-03  1.11587836e-03
  4.65318351e-04 -2.62183596e-04 -9.94613493e-04 -1.65803553e-03
 -2.39990105e-03 -2.00195122e-03 -2.67843498e-03 -2.28875480e-03
 -3.05028833e-03 -2.59258856e-03 -2.21508630e-03 -1.84142275e-03
 -1.39322682e-03 -1.02679037e-03 -6.64262378e-04  9.30989361e-04
  1.28749758e-03  1.72095891e-03  2.07002683e-03  3.57853978e-03
  4.00338438e-03  4.34221377e-03  3.50941007e-03  3.92274433e-03
  3.07950391e-03  3.39963667e-03  2.63098462e-03  1.77161722e-03
  9.06633181e-04  1.23321618e-04 -7.52413122e-04 -3.75171969e-04
 -1.26176158e-03 -2.15410634e-03 -1.79051506e-03 -1.52085428e-03
 -2.43005406e-03 -2.07895302e-03 -1.82355060e-03 -2.74985271e-03
 -2.41145220e-03 -2.17054397e-03 -1.93425688e-03 -4.24643055e-04
 -1.95669324e-04  2.86093317e-05  3.45181395e-04  5.60606434e-04]

如何在 Python 中对 x = 2672.6 到 30005.3 的曲线进行积分?

您可以从找到 x 数组中在整数范围内的索引开始:

idx = np.where((np.array(x)>=2672.6) & (np.array(x)<=30005.3))[0]

然后使用 np.trapz 使用梯形法则积分:

np.trapz(x=np.array(x)[idx],y=np.array(y)[idx])

scipy's integration methods for integrating with fixed samples之一:

# same as numpy.trapz
sp.integrate.trapz(x=np.array(x)[idx],y=np.array(y)[idx])
# example using simpson's rule
sp.integrate.simps(x=np.array(x)[idx],y=np.array(y)[idx])

输出:

import scipy as sp
import numpy as np

idx = np.where((np.array(x)>=2672.6) & (np.array(x)<=30005.3))[0]

>>> np.trapz(x=np.array(x)[idx],y=np.array(y)[idx])
1.4913432492153544
>>> sp.integrate.trapz(x=np.array(x)[idx],y=np.array(y)[idx])
1.4913432492153544
>>> sp.integrate.simps(x=np.array(x)[idx],y=np.array(y)[idx])
1.4892436835956682

代表积分:

请注意,根据您的数据,我怀疑您的意思是上限是 3005.3 而不是 30005.3,但这由您决定:-)