# MATLAB: The accuracy of cumtrapz (numerical integration)???

cumtrapznumerical integration

I have a problem where I have to integrate a vector to get another vector. (this problem related to noncircular gear design). I am trying to find phi 2 the output angle depending on the integration in equation 2.4.5.
I know that the last value of phi 2 should be pi=3.14 almost. but when I am using cumtrapz function as in the code down, the values of phi 2 is not ok.
I think that because of the approximation of the function (cumtrapz), isn't it?
is there any methodolgy or another function to numerically integrate the vector.
% this program is for calculating the NCG (non-circular gear) with no approximationclear, clcdisp('This program generates NCG depending on the imported speed ratio form Excel file')disp('and entered center distance')Ratio=xlsread('speed_ratio.xlsx','A:A');Ratio=Ratio';Center_dis=89.305;m=3;disp('*')disp('*')disp('The solution depends on the main equation of NCG design and geanaration')disp('*')disp('*')% the input angle is equal parts since the driving gear angular velocity is% constant, so depending on the number of the speed ration elements, we% can divide the one rotation (2*pi) to the same number of elementsInput_ang=0:0.0001*pi:2*pi;% plot the speed ratio variations figure(1)% plot the centerplot(0,0,'or','LineWidth',5)hold onplot(Input_ang,Ratio,'LineWidth',3)title('The speed ratio variations of the NC-gearset')xlabel('input angle')ylabel('W_2/ W_1')axis equalgrid on% generating the first centrode with its evolute, base curve, tip and root curve. R_c1=(Center_dis)./(1+Ratio);X_c1=R_c1.*cos(Input_ang);Y_c1=R_c1.*sin(Input_ang);       % plot it with clear zero point       figure(2)       % plot the center       plot(0,0,'or','LineWidth',5)         hold on       plot(X_c1,Y_c1,'k')        title('The first centrode')        xlabel('X')        ylabel('Y')        axis equal        grid on% generating the second centrode with its evolute, base curve, tip and root curve.% R_c2=Center_dis-R_c1;                    % first choiceR_c2=(Center_dis.*Ratio)./(1+Ratio);       % second choice% finding the rotating angle of the second gear >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> here is my problem >>>>> the last value of this output angle must be equal to -piRatio_2=1./Ratio;out_ang_trap=cumtrapz(Input_ang,Ratio_2);out_ang_trap=pi-out_ang_trap;X_c2=R_c2.*cos(out_ang_trap);Y_c2=R_c2.*sin(out_ang_trap);       % plot it with clear zero point       figure(3)       % plot the center       plot(0,0,'or','LineWidth',5)         hold on       plot(X_c2,Y_c2,'k')        title('The second centrode')        xlabel('X')        ylabel('Y')        axis equal        grid on
{"ft_lang_label":"__label__en","ft_lang_prob":0.66428256,"math_prob":0.98831844,"size":2479,"snap":"2021-21-2021-25","text_gpt3_token_len":684,"char_repetition_ratio":0.12323232,"word_repetition_ratio":0.08945687,"special_character_ratio":0.29205325,"punctuation_ratio":0.14545454,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.999326,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-12T16:49:15Z\",\"WARC-Record-ID\":\"<urn:uuid:01f61903-dcc6-4161-b965-c4e8967d8d79>\",\"Content-Length\":\"29817\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7926b7eb-e4d2-46c3-be67-5e9087604c5d>\",\"WARC-Concurrent-To\":\"<urn:uuid:6afc1444-9ea5-4e9e-96f5-651502417cad>\",\"WARC-IP-Address\":\"45.76.174.189\",\"WARC-Target-URI\":\"https://itectec.com/matlab/matlab-the-accuracy-of-cumtrapz-numerical-integration/\",\"WARC-Payload-Digest\":\"sha1:GZ5O56IWHLI6B5QYPMKXVQJZ7INTIF3U\",\"WARC-Block-Digest\":\"sha1:WQD2GF47MX5QFFRPD2LGT7RH44KZY2VG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243989766.27_warc_CC-MAIN-20210512162538-20210512192538-00012.warc.gz\"}"}