How to fit a series of datapoints using 3 piecewise linear fit lines

1 view (last 30 days)
I have the following datapoints:
xdata = [-4.09434456 -3.40119738 -2.99573227 -2.7080502 -2.48490665 -2.30258509 -2.14843441 -2.01490302 -1.89711998 -1.79175947 -1.69644929 -1.60943791 -1.5293952 -1.45528723 -1.38629436 -1.32175584 -1.26113122 -1.2039728 -1.14990558 -1.09861229 -1.04982212 -1.00330211 -0.95885035 -0.91629073 -0.87546874 -0.83624802 -0.7985077 -0.76214005 -0.72704873 -0.69314718 -0.66035736 -0.62860866 -0.597837 -0.56798404 -0.5389965 -0.51082562 -0.48342665 -0.4567584 -0.43078292 -0.40546511 -0.3807725 -0.35667494 -0.33314445 -0.31015493 -0.28768207 -0.26570317 -0.24419696 -0.22314355 -0.20252426 -0.18232156 -0.16251893 -0.14310084 -0.12405265 -0.10536052 -0.08701138 -0.06899287 -0.05129329 -0.03390155 -0.01680712 0. 0.0165293 0.03278982 0.04879016 0.06453852 0.08004271 0.09531018 0.11034806 0.12516314 0.13976194 0.15415068 0.16833531 0.18232156 0.19611488 0.20972053 0.22314355 0.23638878 0.24946086 0.26236426 0.27510329 0.28768207 0.30010459 0.31237469 0.32449605 0.33647224 0.34830669 0.36000273 0.37156356 0.38299225 0.39429181 0.40546511 0.41651494 0.42744401 0.43825493 0.44895022 0.45953233 0.47000363 0.48036642 0.49062292 0.50077529 0.51082562 0.52077595 0.53062825 0.54038443 0.55004634 0.55961579 0.56909453 0.57848427 0.58778666 0.59700332 0.6061358 0.61518564 0.62415431 0.63304326 0.64185389 0.65058757 0.65924563 0.66782937 0.67634006 0.68477893 0.69314718 0.70144598 0.70967648 0.71783979 0.725937 0.73396918 0.74193734 0.74984252 0.7576857 0.76546784 0.77318989 0.78085276 0.78845736 0.79600457 0.80349524 0.81093022 0.81831032 0.82563636 0.83290912 0.84012937 0.84729786 0.85441533 0.8614825 0.86850007 0.87546874 0.88238918 0.88926206 0.89608802 0.90286771 0.90960174 0.91629073 0.92293527 0.92953596 0.93609336 0.94260804 0.94908055 0.95551145 0.96190124 0.96825047 0.97455964 0.98082925 0.9870598 0.99325177 0.99940564 1.00552187 1.01160091 1.01764323 1.02364925 1.02961942 1.03555415 1.04145387 1.04731899 1.05314991 1.05894703 1.06471074 1.07044141 1.07613943 1.08180517 1.08743899 1.09304124 1.09861229 1.10415247 1.10966212 1.11514159 1.1205912 1.12601126 1.13140211 1.13676405 1.1420974 1.14740245 1.15267951 1.15792887 1.16315081 1.16834563 1.1735136 1.178655 1.1837701 1.18885917 1.19392247 1.19896026 1.2039728 1.20896035 1.21392314 1.21886142 1.22377543 1.22866542 1.23353161 1.23837423 1.24319352 1.24798969 1.25276297 1.25751357 1.26224171 1.2669476 1.27163145 1.27629347 1.28093385 1.28555279 1.2901505 1.29472717 1.29928298 1.30381814 1.30833282 1.31282721 1.31730149 1.32175584 1.32619044 1.33060546 1.33500107 1.33937744 1.34373475 1.34807315 1.35239281 1.35669389 1.36097655 1.36524095 1.36948724 1.37371558 1.37792611 1.38211899 1.38629436 1.39045237 1.39459316 1.39871688 1.40282366 1.40691365 1.41098697 1.41504377 1.41908418 1.42310833 1.42711636 1.43110838 1.43508453 1.43904493 1.4429897 1.44691898 1.45083288 1.45473152 1.45861502 1.4624835 1.46633707 1.47017585 1.47399994 1.47780947 1.48160454 1.48538526 1.48915175 1.4929041 1.49664242 1.50036682 1.5040774 1.50777426 1.5114575 1.51512723 1.51878354 1.52242654 1.5260563 1.52967294 1.53327655 1.53686722 1.54044504 1.54401011 1.54756251 1.55110234 1.55462968 1.55814462 1.56164725 1.56513765 1.56861592 1.57208213 1.57553636 1.5789787 1.58240924 1.58582805 1.58923521 1.59263079 1.59601489 1.59938758 1.60274892 1.60609901 1.60943791 1.6127657 1.61608246 1.61938824 1.62268314 1.62596721 1.62924054 1.63250319 1.63575522 1.63899671 1.64222774 1.64544835 1.64865863 1.65185863 1.65504842 1.65822808 1.66139765 1.66455721 1.66770682 1.67084654 1.67397643 1.67709656 1.68020698 1.68330776 1.68639895 1.68948062 1.69255282 1.69561561 1.69866905 1.70171319 1.70474809 1.70777381 1.71079041 1.71379793 1.71679643 1.71978597 1.7227666 1.72573837 1.72870133 1.73165555 1.73460106 1.73753792 1.74046617 1.74338588 1.7462971 1.74919985 1.75209421 1.75498022 1.75785792 1.76072736 1.76358859 1.76644166 1.76928661 1.77212349 1.77495235 1.77777323 1.78058617 1.78339122 1.78618842 1.78897783 1.79175947 1.7945334 1.79729965 1.80005827 1.80280931 1.80555279 1.80828877 1.81101729 1.81373838 1.81645208 1.81915844 1.8218575 1.82454929 1.82723386 1.82991124 1.83258146 1.83524458 1.83790063 1.84054963 1.84319164 1.84582669 1.84845481 1.85107605 1.85369043 1.85629799 1.85889877 1.86149281 1.86408013 1.86666078 1.86923478 1.87180218 1.874363 1.87691728 1.87946505 1.88200635 1.8845412 1.88706965 1.88959172 1.89210744 1.89461685 1.89711998 1.89961687 1.90210753 1.904592 1.90707032 1.9095425 1.9120086 1.91446862 1.91692261 1.91937059 1.9218126 1.92424865 1.92667879 1.92910303 1.93152141 1.93393396 1.9363407 1.93874166 1.94113687 1.94352636 1.94591015 1.94828827 1.95066075 1.95302762 1.95538889 1.95774461 1.96009478 1.96243945 1.96477863 1.96711236 1.96944065 1.97176353 1.97408103 1.97639317 1.97869997 1.98100147 1.98329768 1.98558863 1.98787435 1.99015485 1.99243016 1.99470031 1.99696532 1.99922521 2.00148 2.00372972 2.00597439 2.00821403 2.01044867 2.01267833 2.01490302 2.01712278 2.01933762 2.02154756 2.02375264 2.02595286 2.02814825 2.03033883 2.03252462 2.03470565 2.03688193 2.03905348 2.04122033 2.04338249 2.04553999 2.04769284 2.04984107 2.0519847 2.05412373 2.05625821 2.05838813 2.06051353 2.06263442 2.06475083 2.06686276 2.06897024 2.07107329 2.07317193 2.07526617 2.07735604 2.07944154 2.08152271 2.08359955 2.08567209 2.08774034 2.08980433 2.09186406 2.09391956 2.09597084 2.09801793 2.10006083 2.10209957 2.10413415 2.10616461 2.10819095 2.1102132 2.11223136 2.11424546 2.11625551 2.11826153 2.12026354 2.12226154 2.12425556 2.12624561 2.12823171 2.13021387 2.13219211 2.13416644 2.13613689 2.13810345 2.14006616 2.14202503 2.14398006 2.14593128 2.1478787 2.14982234 2.1517622 2.15369831 2.15563068 2.15755932 2.15948425 2.16140548 2.16332303 2.1652369 2.16714712 2.1690537 2.17095665 2.17285599 2.17475172 2.17664387 2.17853244 2.18041746 2.18229893 2.18417686 2.18605128 2.18792218 2.1897896 2.19165353 2.193514 2.19537101 2.19722458 2.19907472 2.20092144 2.20276476 2.20460468 2.20644123 2.20827441 2.21010424 2.21193072 2.21375388 2.21557372 2.21739025 2.21920348 2.22101344 2.22282012 2.22462355 2.22642373 2.22822068 2.2300144 2.23180491 2.23359222 2.23537634 2.23715729 2.23893507 2.24070969 2.24248117 2.24424952 2.24601474 2.24777686 2.24953587 2.2512918 2.25304465 2.25479443 2.25654115 2.25828483 2.26002548 2.2617631 2.2634977 2.26522931 2.26695792 2.26868354 2.27040619 2.27212589 2.27384262 2.27555642 2.27726729 2.27897523 2.28068026 2.28238239 2.28408162 2.28577797 2.28747146 2.28916207 2.29084984 2.29253476 2.29421684 2.2958961 2.29757255 2.29924619 2.30091704 2.30258509 2.30425037 2.30591288 2.30757263 2.30922964 2.3108839 2.31253542 2.31418423 2.31583032 2.31747371 2.31911439 2.3207524 2.32238772 2.32402037 2.32565037 2.32727771 2.3289024 2.33052446 2.3321439 2.33376071 2.33537492 2.33698652 2.33859553 2.34020196 2.34180581 2.34340709 2.34500581 2.34660198 2.3481956 2.34978669 2.35137526 2.3529613 2.35454483 2.35612586 2.35770439 2.35928044 2.360854 2.36242509 2.36399372 2.36555989 2.36712361 2.36868489 2.37024374 2.37180016 2.37335416 2.37490575 2.37645494 2.37800173 2.37954613 2.38108815 2.3826278 2.38416508 2.3857 2.38723257 2.38876279 2.39029067 2.39181623 2.39333946 2.39486037 2.39637897 2.39789527 2.39940928 2.40092099 2.40243043 2.40393759 2.40544248 2.40694511 2.40844548 2.40994361 2.4114395 2.41293315 2.41442457 2.41591378 2.41740077 2.41888555 2.42036813 2.42184851 2.42332671 2.42480273 2.42627657 2.42774824 2.42921774 2.4306851 2.4321503 2.43361336 2.43507428 2.43653307 2.43798973 2.43944428 2.44089671 2.44234704 2.44379526 2.44524139 2.44668544 2.4481274 2.44956728 2.4510051 2.45244085 2.45387454 2.45530618 2.45673577 2.45816332 2.45958884 2.46101233 2.46243379 2.46385324 2.46527068 2.4666861 2.46809953 2.46951096 2.47092041 2.47232787 2.47373335 2.47513686 2.4765384 2.47793798 2.4793356 2.48073128 2.48212501 2.4835168 2.48490665 2.48629458 2.48768058 2.48906466 2.49044683 2.49182709 2.49320545 2.49458192 2.49595649 2.49732917 2.49869997 2.5000689 2.50143595 2.50280114 2.50416447 2.50552594 2.50688556 2.50824333 2.50959926 2.51095336 2.51230562 2.51365606 2.51500468 2.51635148 2.51769647 2.51903966 2.52038104 2.52172062 2.52305842 2.52439442 2.52572864 2.52706109 2.52839176 2.52972067 2.53104781 2.53237319 2.53369681 2.53501869 2.53633882 2.53765722 2.53897387 2.5402888 2.54160199 2.54291347 2.54422323 2.54553127 2.54683761 2.54814224 2.54944517 2.55074641 2.55204595 2.55334381 2.55463999 2.55593449 2.55722731 2.55851847 2.55980796 2.56109579 2.56238196 2.56366648 2.56494936 2.56623059 2.56751018 2.56878813 2.57006446 2.57133916 2.57261223 2.57388369 2.57515353 2.57642176 2.57768838 2.57895341 2.58021683 2.58147866 2.5827389 2.58399755 2.58525462 2.58651012 2.58776404 2.58901638 2.59026717 2.59151638 2.59276405 2.59401015 2.59525471 2.59649772 2.59773918 2.59897911 2.6002175 2.60145435 2.60268969 2.60392349 2.60515578 2.60638655 2.6076158 2.60884355 2.61006979 2.61129453 2.61251777 2.61373952 2.61495978 2.61617855 2.61739583 2.61861164 2.61982597 2.62103882 2.62225021 2.62346013 2.62466859 2.62587559 2.62708114 2.62828523 2.62948788 2.63068908 2.63188884 2.63308716 2.63428405 2.63547951 2.63667354 2.63786614 2.63905733 2.6402471 2.64143545 2.6426224 2.64380793 2.64499207 2.6461748 2.64735613 2.64853607 2.64971462 2.65089179 2.65206757 2.65324196 2.65441499 2.65558663 2.65675691 2.65792581 2.65909336 2.66025954 2.66142436 2.66258783 2.66374994 2.66491071 2.66607013 2.66722821 2.66838494 2.66954035 2.67069441 2.67184715 2.67299856 2.67414865 2.67529741 2.67644486 2.67759099 2.67873581 2.67987932 2.68102153 2.68216243 2.68330203 2.68444034 2.68557735 2.68671306 2.68784749 2.68898064 2.6901125 2.69124308 2.69237239 2.69350042 2.69462718 2.69575267 2.6968769 2.69799987 2.69912157 2.70024202 2.70136121 2.70247916 2.70359585 2.7047113 2.70582551 2.70693847 2.7080502 2.7091607 2.71026996 2.71137799 2.7124848 2.71359038 2.71469474 2.71579789 2.71689982 2.71800053 2.71910004 2.72019834 2.72129543 2.72239132 2.72348601 2.7245795 2.7256718 2.72676291 2.72785283 2.72894156 2.73002911 2.73111547 2.73220066 2.73328467 2.73436751 2.73544918 2.73652967 2.737609 2.73868717 2.73976418 2.74084002 2.74191472 2.74298825 2.74406064 2.74513188 2.74620197 2.74727091 2.74833872 2.74940539 2.75047092 2.75153531 2.75259858 2.75366071 2.75472172 2.7557816 2.75684037 2.75789801 2.75895453 2.76000994 2.76106424 2.76211742 2.7631695 2.76422047 2.76527034 2.76631911 2.76736678 2.76841335 2.76945883 2.77050322 2.77154651 2.77258872 2.77362985 2.77466989 2.77570885 2.77674673 2.77778354 2.77881927 2.77985393 2.78088753 2.78192005 2.78295151 2.78398191 2.78501124 2.78603952 2.78706674 2.78809291 2.78911802 2.79014209 2.79116511 2.79218708 2.79320801 2.7942279 2.79524675 2.79626456 2.79728133 2.79829708 2.79931179 2.80032548 2.80133814 2.80234977 2.80336038 2.80436997 2.80537855 2.8063861 2.80739264 2.80839817 2.8094027 2.81040621 2.81140871 2.81241022 2.81341072 2.81441022 2.81540872 2.81640623 2.81740274 2.81839826 2.81939279 2.82038633 2.82137889 2.82237046 2.82336105 2.82435066 2.82533929 2.82632694 2.82731362 2.82829933 2.82928407 2.83026783 2.83125063 2.83223247 2.83321334 2.83419326 2.83517221 2.8361502 2.83712724 2.83810333 2.83907846 2.84005265 2.84102588 2.84199817 2.84296952 2.84393992 2.84490938 2.84587791 2.84684549 2.84781214 2.84877786 2.84974265 2.8507065 2.85166943 2.85263143 2.85359251 2.85455266 2.85551189 2.85647021 2.8574276 2.85838408 2.85933965 2.8602943 2.86124805 2.86220088 2.86315281 2.86410383 2.86505395 2.86600317 2.86695148 2.8678989 2.86884542 2.86979105 2.87073578 2.87167962 2.87262258 2.87356464 2.87450582 2.87544611 2.87638552 2.87732404 2.87826169 2.87919846 2.88013435 2.88106937 2.88200351 2.88293678 2.88386918 2.88480071 2.88573138 2.88666118 2.88759011 2.88851819 2.8894454 2.89037176 2.89129726 2.8922219 2.89314568 2.89406862 2.8949907 2.89591194 2.89683232 2.89775187 2.89867056 2.89958841 2.90050542 2.90142159 2.90233693 2.90325142 2.90416508 2.90507791 2.9059899 2.90690106 2.90781139 2.9087209 2.90962957 2.91053743 2.91144446 2.91235066 2.91325605 2.91416062 2.91506437 2.91596731 2.91686943 2.91777073 2.91867123 2.91957091 2.92046979 2.92136786 2.92226512 2.92316158 2.92405724 2.92495209 2.92584615 2.9267394 2.92763186 2.92852352 2.92941439 2.93030447 2.93119375 2.93208225 2.93296995 2.93385687 2.934743 2.93562835 2.93651291 2.9373967 2.9382797 2.93916192 2.94004337 2.94092404 2.94180393 2.94268305 2.9435614 2.94443898 2.94531579 2.94619183 2.9470671 2.94794161 2.94881535 2.94968834 2.95056055 2.95143201 2.95230272 2.95317266 2.95404185 2.95491028 2.95577796 2.95664488 2.95751106 2.95837649 2.95924116 2.9601051 2.96096828 2.96183072 2.96269242 2.96355338 2.96441359 2.96527307 2.9661318 2.9669898 2.96784707 2.9687036 2.9695594 2.97041447 2.9712688 2.97212241 2.97297529 2.97382744 2.97467886 2.97552957 2.97637955 2.9772288 2.97807734 2.97892516 2.97977225 2.98061864 2.9814643 2.98230925 2.98315349 2.98399702 2.98483983 2.98568194 2.98652333 2.98736402 2.98820401 2.98904329 2.98988186 2.99071973 2.9915569 2.99239337 2.99322914 2.99406422 2.99489859 2.99573227 2.99656526 2.99739755 2.99822915 2.99906006 2.99989028 3.00071982 3.00154866 3.00237682 3.00320429 3.00403108 3.00485718 3.0056826 3.00650735 3.00733141 3.00815479 3.0089775 3.00979953 3.01062089 3.01144157 3.01226158 3.01308091 3.01389958 3.01471757 3.0155349 3.01635156 3.01716755 3.01798288 3.01879755 3.01961155 3.02042489 3.02123756 3.02204958 3.02286094 3.02367164 3.02448169 3.02529108 3.02609981 3.02690789 3.02771532 3.0285221 3.02932822 3.0301337 3.03093853 3.03174271 3.03254625 3.03334914 3.03415138 3.03495299 3.03575395 3.03655427 3.03735395 3.03815299 3.03895139 3.03974916 3.04054629 3.04134278 3.04213865 3.04293388 3.04372847 3.04452244 3.04531577 3.04610848 3.04690056 3.04769201 3.04848284 3.04927304 3.05006262 3.05085157 3.05163991 3.05242762 3.05321471 3.05400118 3.05478704 3.05557227 3.0563569 3.0571409 3.05792429 3.05870707 3.05948924 3.06027079 3.06105174 3.06183208 3.0626118 3.06339092 3.06416944 3.06494734 3.06572465 3.06650134 3.06727744 3.06805294 3.06882783 3.06960212 3.07037582 3.07114891 3.07192141 3.07269331 3.07346462 3.07423534 3.07500545 3.07577498 3.07654392 3.07731226 3.07808001 3.07884718 3.07961376 3.08037975 3.08114515 3.08190997 3.0826742 3.08343785 3.08420092 3.08496341 3.08572531 3.08648664 3.08724738 3.08800755 3.08876714 3.08952615 3.09028459 3.09104245 3.09179974 3.09255646 3.0933126 3.09406817 3.09482318 3.09557761 3.09633147 3.09708477 3.0978375 3.09858966 3.09934126 3.10009229 3.10084276 3.10159266 3.10234201 3.10309079 3.10383901 3.10458668 3.10533378 3.10608033 3.10682632 3.10757176 3.10831663 3.10906096 3.10980473 3.11054795 3.11129061 3.11203273 3.11277429 3.11351531 3.11425578 3.11499569 3.11573507 3.11647389 3.11721217 3.11794991 3.1186871 3.11942375 3.12015985 3.12089542 3.12163044 3.12236492 3.12309887 3.12383228 3.12456515 3.12529748 3.12602927 3.12676054 3.12749126 3.12822146 3.12895112 3.12968025 3.13040884 3.13113691 3.13186445 3.13259146 3.13331794 3.13404389 3.13476932 3.13549422 3.13621859 3.13694244 3.13766577 3.13838857 3.13911086 3.13983262 3.14055386 3.14127458 3.14199478 3.14271446 3.14343363 3.14415228 3.14487041 3.14558803 3.14630513 3.14702172 3.1477378 3.14845336 3.14916841 3.14988295 3.15059698 3.15131051 3.15202352 3.15273602 3.15344802 3.15415951 3.15487049 3.15558097 3.15629095 3.15700042 3.15770939 3.15841786 3.15912582 3.15983328 3.16054025 3.16124671 3.16195268 3.16265814 3.16336311 3.16406759 3.16477157 3.16547505 3.16617804 3.16688053 3.16758253 3.16828404 3.16898506 3.16968558 3.17038562 3.17108516 3.17178422 3.17248279 3.17318087 3.17387846 3.17457557 3.17527219 3.17596832 3.17666398 3.17735914 3.17805383 3.17874803 3.17944176 3.180135 3.18082776 3.18152004 3.18221184 3.18290316 3.18359401 3.18428438 3.18497427 3.18566369 3.18635263 3.1870411 3.1877291 3.18841662 3.18910367 3.18979024 3.19047635 3.19116199 3.19184715 3.19253185 3.19321608 3.19389984 3.19458313 3.19526596 3.19594832 3.19663022 3.19731165 3.19799261 3.19867312 3.19935316 3.20003274 3.20071185 3.20139051 3.20206871 3.20274644 3.20342372 3.20410054 3.2047769 3.2054528 3.20612825 3.20680324 3.20747778 3.20815186 3.20882549 3.20949866 3.21017138 3.21084365 3.21151547 3.21218684 3.21285775 3.21352822 3.21419824 3.2148678 3.21553692 3.2162056 3.21687382 3.2175416 3.21820894 3.21887582]
ydata = [-0.0099837 -1.05442706 -1.5202561 -1.81414942 -2.01808184 -3.69379016 -3.7072908 -3.80605633 -3.90308969 -3.87876588 -3.80557402 -3.80137222 -3.91789001 -4.0169047 -4.06649635 -3.98152302 -3.8831951 -3.7721121 -3.78629227 -3.89084964 -3.89995725 -3.81455865 -3.68053851 -3.62433347 -3.67207376 -3.7789903 -3.90425213 -3.9941593 -4.06177008 -4.17560648 -4.25676636 -4.46702885 -4.63887445 -4.80360774 -4.81919147 -4.82425718 -4.77096096 -4.80431246 -4.6813231 -4.57544895 -4.54460952 -4.51078687 -4.48216864 -4.43304894 -4.3438634 -4.33313888 -4.25775723 -4.35047868 -4.47085255 -4.52259114 -4.57844969 -4.60529191 -4.6669173 -4.77359903 -4.71854765 -4.6724319 -4.64318445 -4.71459052 -4.63510729 -4.60921916 -4.61479347 -4.67824856 -4.67386194 -4.79085736 -4.86302418 -4.8155826 -4.70709947 -4.87983782 -4.89138674 -4.87184513 -4.82414936 -4.75900373 -4.73840608 -4.82591677 -4.84795387 -4.90286152 -4.81721911 -4.80061562 -4.78346772 -4.76659861 -4.80227158 -4.7893063 -4.77454193 -4.78548686 -4.84386651 -4.87955979 -4.88665431 -4.92854579 -4.96014414 -4.91580386 -4.90738124 -4.7700104 -4.67191243 -4.55513291 -4.58708037 -4.63135161 -4.6192469 -4.60907779 -4.56969793 -4.58893316 -4.68697393 -4.82645527 -5.02222584 -4.95932143 -4.80995625 -4.72867506 -4.7625117 -4.98236876 -5.04013227 -5.08172956 -5.06379707 -5.05875345 -5.0454159 -5.06662671 -5.13331273 -5.04900215 -4.91762521 -4.86431151 -4.84831688 -4.82301212 -4.82217584 -4.84721571 -4.94453534 -4.99512337 -4.96177797 -4.99246524 -5.0798884 -5.16068435 -5.18372176 -5.15167872 -5.15737246 -5.13605467 -5.19865965 -5.24159432 -5.18642799 -5.16615771 -5.12196085 -5.21792468 -5.25016333 -5.23928647 -5.37158865 -5.26554569 -5.25671256 -5.4050854 -5.44671322 -5.50587964 -5.40803111 -5.33447019 -5.38295578 -5.31835152 -5.39972514 -5.45531464 -5.4019273 -5.3832647 -5.38902949 -5.46220233 -5.64974601 -5.70581077 -5.75890961 -5.81449309 -6.03690717 -6.14774802 -6.06936218 -5.91898418 -5.95820943 -5.89711865 -5.81906801 -5.74487468 -5.55466495 -5.39109756 -5.26463557 -5.2523067 -5.25899033 -5.25707462 -5.24138763 -5.26459783 -5.29417657 -5.33707079 -5.3849606 -5.52244754 -5.53691333 -5.50090929 -5.46640414 -5.48773053 -5.5376501 -5.46526597 -5.56989944 -5.54132973 -5.53076822 -5.624926 -5.72035275 -5.86043996 -5.78873884 -5.72639036 -5.76061336 -5.61637452 -5.59414129 -5.62602597 -5.55510556 -5.40286698 -5.25223067 -5.23442338 -5.23246035 -5.23145807 -5.19993209 -5.14979917 -5.11284344 -5.07097839 -5.15963068 -5.20991966 -5.19669439 -5.17857279 -5.19284968 -5.27955159 -5.44531367 -5.55605987 -5.58277225 -5.58896617 -5.62482734 -5.72225961 -5.72632755 -5.80808195 -5.79168032 -5.84139518 -5.74917708 -5.74344566 -5.77660821 -5.79757089 -5.81249616 -5.85198408 -5.78206427 -5.88723067 -5.80348852 -5.80258922 -5.77413482 -5.59919481 -5.55314705 -5.54376132 -5.51788546 -5.43082997 -5.39054649 -5.40368403 -5.47031713 -5.43593545 -5.46330297 -5.40599535 -5.39853592 -5.43084673 -5.47405299 -5.49751174 -5.50870818 -5.51129141 -5.63537799 -5.72907341 -5.88158841 -5.89456505 -5.79360693 -5.82860733 -5.85062719 -5.86906474 -5.88304671 -5.89256698 -5.95770146 -6.02309882 -6.00793052 -6.13175448 -6.16449853 -6.02452509 -5.90910859 -5.87327404 -5.87897635 -5.84901438 -5.82267157 -5.81588511 -5.84578951 -5.86981369 -6.00496523 -6.15496251 -6.16203699 -6.16152638 -6.23427623 -6.21462981 -6.21857764 -6.23069266 -6.31507325 -6.23985833 -6.20291438 -6.25582762 -6.24233347 -6.30336823 -6.40974495 -6.50817863 -6.46434255 -6.33122731 -6.37083934 -6.33622895 -6.21086988 -6.21270534 -6.00291224 -5.871114 -5.81013228 -5.80324833 -5.85416261 -5.87200947 -5.92163946 -5.9716694 -6.05515835 -6.24211954 -6.39699815 -6.56309762 -6.41983553 -6.49471906 -6.45369432 -6.29204525 -6.32283078 -6.1005148 -5.98679729 -5.91353846 -5.88410001 -5.90023478 -5.90034481 -5.89214011 -5.97700877 -5.99923031 -6.14548249 -6.26364756 -6.34156696 -6.28649085 -6.38602414 -6.38144372 -6.35990203 -6.26426223 -6.13672933 -6.21216503 -6.21744289 -6.2545395 -6.21386975 -6.14720586 -6.09231563 -6.19015355 -6.25105828 -6.20343891 -6.22109825 -6.17959866 -6.15327207 -6.28520819 -6.4198413 -6.32921688 -6.22517881 -6.30585574 -6.53092359 -6.404012 -6.46337171 -6.45420476 -6.40198229 -6.47076743 -6.63034 -6.63971231 -6.56854222 -6.56548071 -6.55526475 -6.48994901 -6.42336464 -6.48644155 -6.32216216 -6.35345985 -6.36723524 -6.47914278 -6.39266046 -6.44516054 -6.41534529 -6.46105999 -6.38940296 -6.45081833 -6.381519 -6.42274901 -6.38146646 -6.47708711 -6.4023433 -6.36225224 -6.37751755 -6.38556794 -6.41394248 -6.37321818 -6.28731775 -6.20917232 -6.21849664 -6.33506065 -6.38201669 -6.39922562 -6.33794209 -6.29809632 -6.36733951 -6.43844774 -6.40875374 -6.29090056 -6.23852903 -6.29975447 -6.32999658 -6.3975063 -6.38186764 -6.41827899 -6.35005154 -6.39851542 -6.40500829 -6.4832624 -6.51182768 -6.5185264 -6.42963179 -6.4977257 -6.44005193 -6.64163267 -6.66331811 -6.72396021 -6.62220987 -6.54116403 -6.38156817 -6.46908804 -6.45999397 -6.44136244 -6.36249748 -6.36888837 -6.41281563 -6.49694802 -6.50700821 -6.66662838 -6.71413621 -6.80804854 -6.9197052 -6.95510924 -7.13048479 -7.07352043 -7.05141311 -7.01450119 -7.0159257 -6.95704229 -6.81705919 -6.75232998 -6.73561631 -6.67461739 -6.67353878 -6.66492282 -6.6602869 -6.6054663 -6.67503892 -6.79928169 -6.75057853 -6.83795359 -6.80925012 -6.80670123 -6.70663965 -6.82024153 -6.86314121 -6.80714263 -6.79486765 -6.9000079 -6.79402601 -6.73410842 -6.76977239 -6.84365226 -6.69351596 -6.57419722 -6.55451442 -6.39417919 -6.40449797 -6.42672188 -6.35041345 -6.36087915 -6.38122133 -6.45435758 -6.52019617 -6.57330361 -6.69371918 -6.63106401 -6.57747649 -6.72409208 -6.71156792 -6.68224875 -6.72401133 -6.83945592 -6.8538804 -6.86297786 -6.94504331 -7.050657 -7.19723094 -7.09265033 -7.14890885 -7.08295359 -6.96599815 -6.93757716 -7.03799218 -6.96627365 -6.92326981 -6.78174343 -6.83061537 -6.79748892 -6.87915842 -6.73802478 -6.5833201 -6.49001728 -6.4667408 -6.46913608 -6.43251489 -6.49042516 -6.43535022 -6.36623965 -6.52921675 -6.55799001 -6.47701473 -6.53599929 -6.56299438 -6.73501288 -6.69100143 -6.68164677 -6.60773869 -6.55896662 -6.6630278 -6.68831958 -6.72268526 -6.7668399 -6.69115825 -6.68913944 -6.81825065 -6.99347286 -7.00473029 -6.93999432 -7.12476369 -7.15422882 -7.15860484 -7.16613827 -7.25218511 -7.10874019 -7.0900979 -6.99218238 -7.0195932 -7.0019966 -6.87095445 -6.78346948 -6.77297681 -6.81139963 -6.80954543 -6.75676121 -6.82722756 -6.73046761 -6.79655516 -6.92305481 -7.0442018 -6.91629878 -6.90162045 -6.94480611 -6.96360468 -7.0112568 -7.05205415 -6.96143413 -6.92079775 -6.75318012 -6.7553558 -6.67425391 -6.69611443 -6.68340997 -6.5813031 -6.6572038 -6.68774684 -6.5736424 -6.60593027 -6.69689709 -6.70078735 -6.68512197 -6.7387967 -6.91599076 -6.80218934 -6.84787087 -6.91515179 -6.92639744 -6.94008918 -6.99780823 -7.03836146 -7.00024551 -6.88426437 -6.86582425 -6.75183708 -6.79280561 -6.87195836 -6.85166128 -6.85029509 -6.83473322 -6.9235125 -7.01584739 -7.17753463 -7.16470409 -7.18170473 -7.18992404 -7.23983792 -7.26502705 -7.27414438 -7.26350928 -7.1435741 -7.08627853 -7.25165414 -7.19585657 -7.19706282 -7.18726457 -7.08946043 -7.05308662 -7.0248617 -7.00169948 -7.02254363 -6.9291301 -6.86655177 -6.84028268 -6.78850845 -6.8331523 -6.74715234 -6.74529798 -6.81257735 -6.91245557 -6.86456316 -6.96100049 -6.9618873 -7.07514195 -7.08787046 -6.95851948 -6.94803704 -7.01153265 -6.8765595 -6.83798713 -6.87138443 -6.7898923 -6.7107475 -6.66348871 -6.80558231 -6.80559993 -6.72058377 -6.76723436 -6.93263082 -6.88241899 -6.86910802 -6.9138763 -6.86304108 -6.86901963 -6.88436891 -6.84218701 -6.84808237 -6.81846298 -6.90744679 -7.06953009 -7.14832834 -7.25496782 -7.30004435 -7.20800045 -7.28101713 -7.24502446 -7.29326689 -7.05440426 -6.95125544 -6.88722541 -6.89125677 -6.9106972 -6.86528585 -6.91379627 -6.98256796 -6.95313646 -7.04407023 -7.19172183 -7.13902305 -7.0146337 -7.00712795 -7.16435879 -6.99131935 -6.93057071 -6.91472627 -6.86743471 -6.8032381 -6.74221533 -6.80845343 -6.65947807 -6.58201743 -6.62868072 -6.67031637 -6.67809711 -6.7327771 -6.72308104 -6.87261177 -6.96192522 -7.22353254 -7.34690863 -7.54802995 -7.50775349 -7.49527805 -7.39813066 -7.44134278 -7.14724456 -7.05661958 -7.04724227 -7.04950204 -6.91115511 -6.84638173 -6.78607764 -6.81290459 -6.71873271 -6.82901065 -6.89617389 -6.81826634 -6.78490039 -6.78051183 -6.85603905 -6.8445551 -6.79597682 -6.87034976 -6.88987681 -6.81106813 -6.86679036 -6.81554765 -6.83082787 -6.72831905 -6.78866214 -6.93309173 -6.88832943 -6.96353711 -6.91063791 -6.83948811 -6.82635715 -6.84374645 -6.88803123 -6.80468023 -6.72033193 -6.78952117 -6.65603732 -6.66564928 -6.73255858 -6.74541925 -6.78293711 -6.80633131 -6.90192936 -6.95364663 -6.92496929 -7.03204277 -7.00962351 -6.94842345 -6.94450434 -6.91405917 -6.98184983 -6.94336068 -6.91937647 -6.79704696 -6.71764097 -6.70982738 -6.71395054 -6.81537228 -6.84068852 -6.78271143 -6.79432013 -6.72810985 -6.85344194 -6.85761189 -6.99046304 -7.00228541 -6.98878053 -6.97541034 -7.04613594 -6.91656038 -6.99226508 -6.93783916 -7.00571808 -6.95833768 -6.99310793 -6.85790768 -6.86350906 -6.80720862 -6.93094993 -6.90857311 -6.9513318 -6.93663151 -6.94077778 -6.89104796 -6.97671179 -7.01620926 -7.05103717 -6.98848243 -7.05190609 -7.04221385 -7.10234777 -7.15907913 -7.26927697 -7.21355858 -7.2535677 -7.29436415 -7.39755518 -7.27017302 -7.30733402 -7.36236659 -7.32807861 -7.18967027 -7.27509835 -7.29541508 -7.20614213 -7.17597616 -7.24324756 -7.15456607 -7.14425657 -7.06576537 -7.16035628 -7.23331919 -7.11409454 -7.15789919 -7.07901036 -7.11892925 -7.12915709 -7.09147975 -7.06178819 -6.98126613 -6.87714869 -6.85428689 -6.81529327 -6.95101232 -6.90966838 -6.87590372 -6.85944249 -6.97754968 -6.99948271 -7.02675187 -7.01544303 -7.02883619 -6.95136694 -6.95063266 -6.96600358 -7.00556349 -6.87126804 -6.87523549 -6.84181296 -6.8857914 -6.90890784 -6.82192354 -6.80141404 -6.77942492 -6.74480585 -6.89338635 -6.89236721 -6.86997868 -6.86596278 -6.79232396 -6.90234069 -6.93004424 -6.96447641 -6.9549867 -6.88839529 -6.86722169 -6.95042292 -6.94602953 -6.99897705 -7.00105657 -6.92827186 -7.00375558 -7.01374209 -7.05129459 -7.17146702 -7.06317863 -7.06739132 -7.10522962 -7.08474161 -7.15823803 -7.16681449 -7.17977984 -7.20463754 -7.1257249 -7.23067863 -7.34048256 -7.33991268 -7.32537386 -7.38344369 -7.26126752 -7.30743977 -7.25393035 -7.19498798 -7.25683447 -7.19500076 -7.26289664 -7.32357046 -7.29359773 -7.23354483 -7.26969373 -7.16787996 -7.26746474 -7.20522378 -7.18288404 -7.03152346 -6.97139207 -6.96368388 -7.12963309 -7.00256388 -6.91958661 -6.89051058 -6.87083082 -6.95559495 -7.07622504 -7.07954264 -7.13638809 -7.15727433 -7.18146077 -7.36939049 -7.42831748 -7.39722622 -7.23949969 -7.24339407 -7.25056803 -7.1656177 -7.08678742 -7.09896903 -7.05782299 -6.97854271 -7.05143894 -7.10082572 -6.93177741 -6.9285373 -6.99941189 -7.05844254 -7.06201191 -7.15767271 -7.19809858 -7.09083836 -7.10038314 -7.28252672 -7.25734112 -7.1841628 -7.06825609 -7.07428731 -7.03839229 -7.03161604 -7.07643648 -7.08983692 -7.10396609 -7.09832251 -7.16038514 -7.29268254 -7.41353793 -7.28702654 -7.35794412 -7.33613179 -7.25136487 -7.1656813 -7.09280335 -7.06078689 -7.02628201 -6.96760472 -6.93646962 -6.91166213 -6.9852597 -7.03194141 -7.12295608 -7.22497493 -7.14829268 -7.08893424 -7.02928934 -7.18449814 -7.16273382 -7.09124386 -7.08816304 -7.07379294 -7.17321127 -7.15591255 -7.2120439 -7.22753069 -7.18766117 -7.23938373 -7.31513383 -7.31688058 -7.24174659 -7.02901262 -6.99694996 -6.94580404 -6.99666319 -7.03677918 -6.95263581 -6.86059183 -6.85806276 -6.88396271 -6.89156122 -6.9259917 -6.99283743 -6.96337619 -6.87059664 -6.91637055 -6.98268317 -6.90269044 -6.90036372 -6.97777774 -7.0501844 -6.94885766 -6.88516007 -7.00736856 -7.06134258 -7.03411324 -7.19552826 -7.17730274 -7.19535827 -7.21074423 -7.22093038 -7.38580448 -7.23680608 -7.16600737 -7.25224794 -7.11882883 -7.10453846 -7.09723738 -7.13123701 -7.22337665 -7.21662197 -7.26564813 -7.10341585 -7.01051386 -6.88019838 -6.88570189 -6.89008484 -6.88350213 -6.86711854 -6.74014777 -6.72668124 -6.80484374 -6.83541217 -6.94820903 -6.94899345 -7.01333484 -6.94155421 -6.91340296 -7.01025244 -7.05715013 -7.05083559 -7.04948387 -7.17308099 -7.20906981 -7.16058036 -7.13344341 -7.24977707 -7.28223418 -7.26431339 -7.26008973 -7.29730033 -7.34648459 -7.37874042 -7.38805044 -7.44717035 -7.3648855 -7.27739542 -7.23413773 -7.25635153 -7.28593554 -7.25721678 -7.24473622 -7.29287177 -7.26193246 -7.2354717 -7.24458386 -7.31733164 -7.39694831 -7.4162436 -7.1642414 -7.13299228 -7.09809164 -7.16272539 -7.02349244 -7.06113291 -7.06955756 -6.96863192 -6.96513145 -7.15323215 -7.11263131 -7.10126686 -7.05786561 -7.1800112 -7.2418268 -7.11100916 -7.0833128 -7.0462749 -6.97218042 -6.99308298 -6.99423235 -7.00885453 -7.0585777 -7.049797 -7.22478668 -7.4324803 -7.34333656 -7.28533984 -7.23693652 -7.28531717 -7.23256966 -7.13319671 -7.08506637 -6.9898353 -7.00446172 -7.0936559 -7.20105825 -7.32483511 -7.21017672 -7.32919646 -7.46901044 -7.54378759 -7.45800482 -7.44552427 -7.2000562 -7.07966141 -7.0215044 -6.96559519 -6.84542607 -6.74059741 -6.69042197 -6.77759093 -6.74669454 -6.78391355 -6.87826728 -6.86795158 -7.01287201 -7.05087504 -7.14440345 -7.20379152 -7.16995927 -7.22525979 -7.39243795 -7.33111979 -7.34667501 -7.13512926 -7.2433648 -7.30561681 -7.33699531 -7.26706459 -7.19625673 -7.16761574 -7.16548175 -7.12960387 -7.30345634 -7.10721618 -7.00771354 -6.9008286 -6.96427734 -7.0167269 -6.97830391 -6.95741411 -7.01816874 -7.03422491 -7.20813641 -7.20110319 -7.27542908 -7.13108691 -7.08224781 -7.0854044 -7.09849159 -7.07452888 -6.99325515 -6.99385478 -7.08305354 -7.12918257 -7.25900448 -7.1722291 -7.20676112 -7.15027742 -7.20378506 -7.18005411 -7.10319191 -7.08138929 -7.05715535 -6.98440782 -7.04745702 -6.99384621 -7.05651174 -6.91961018 -6.9471761 -7.04280311 -7.08340754 -7.09646909 -7.20607515 -7.16587416 -7.24202514 -7.29697511 -7.5402879 -7.63644419 -7.55424511 -7.47585225 -7.34474142 -7.31707872 -7.30543422 -7.25674908 -7.06336075 -7.00321435 -6.94779501 -6.96627766 -6.93322725 -7.02679823 -6.90262916 -6.79257822 -6.8195819 -6.83919438 -6.87320409 -6.86087939 -6.76685026 -6.85755837 -6.77455639 -6.83929804 -6.96085967 -6.99892839 -7.08671336 -7.04733324 -7.03135239 -7.16596539 -7.05554068 -7.23530707 -7.32972434 -7.3676871 -7.38108956 -7.45375648 -7.30448612 -7.42405326 -7.35851679 -7.48463482 -7.33395798 -7.1250141 -7.09291655 -7.08054108 -7.09931591 -7.11269005 -7.08202375 -7.14284603 -7.07673598 -7.06335977 -7.12614428 -7.2592847 -7.0796437 -7.01768843 -7.05662303 -7.07566837 -7.03161961 -6.94418391 -6.97556196 -7.02083897 -6.89483952 -6.91970901 -6.95820151 -6.97559351 -6.9808531 -7.02335314 -7.16953533 -7.18164162 -7.1975084 -7.37766027 -7.43941114 -7.40516835 -7.25302458 -7.15839669 -7.02910817 -7.00194167 -6.99293619 -7.07618749 -7.04333457 -7.10010092 -7.10642652 -7.24002985 -7.38371233 -7.50110588 -7.41438187 -7.44269208 -7.36738966 -7.2221355 -7.16072794 -7.17970121 -7.17033023 -7.13702701 -7.06103112 -7.14934037 -7.1671191 -7.07721619 -7.15726248 -7.25788482 -7.21693313 -7.15585667 -7.17327913 -7.17928339 -7.19289901 -7.05272084 -7.13469346 -7.16401332 -7.05566799 -7.09615066 -7.13079956 -7.12841392 -7.15427724 -7.13683954 -7.27219997 -7.35540922 -7.31405245 -7.42573354 -7.26894918 -7.42350027 -7.41089472 -7.47400138 -7.44297723 -7.41151417 -7.32054871 -7.40856701 -7.28447976 -7.40055128 -7.25923931 -7.22091338 -7.24727907 -7.28597975 -7.34017377 -7.42793044 -7.29045531 -7.26353384 -7.31795604 -7.43946956 -7.51955761 -7.43360855 -7.42415211 -7.2558191 -7.18906472 -7.25924191 -7.41077435 -7.47017435 -7.47962582 -7.45637134 -7.44841042 -7.43116586 -7.48242732 -7.35322368 -7.12078314 -7.00092674 -6.92781714 -6.91825566 -6.85754961 -6.84351909 -6.80694891 -6.85747181 -6.94101044 -7.08731581 -7.22318879 -7.22382951 -7.24230349 -7.23250388 -7.35157771 -7.37805474 -7.40101244 -7.31730106 -7.30572666 -7.15098968 -7.1854302 -7.1937952 -7.18230708 -7.12085814 -7.14590924 -7.12665594 -7.12524923 -7.23949233 -7.29350355 -7.27634422 -7.0989086 -7.21675545 -7.2918303 -7.28066405 -7.25596387 -7.24457429 -7.23924444 -7.16828138 -7.16191221 -7.22999017 -7.11239778 -7.06909377 -7.04196969 -7.05921035 -7.17335842 -7.06604999 -7.11444887 -7.03884331 -7.11940485 -7.18115981 -7.19035526 -7.09733573 -7.0488113 -6.92594725 -6.93231138 -6.97189943 -6.99360675 -6.97312822 -7.00057723 -7.04869803 -7.17441361 -7.21481293 -7.37050253 -7.48489195 -7.54217026 -7.49518515 -7.38649924 -7.38003672 -7.39221754 -7.45759781 -7.36167557 -7.29250899 -7.21335162 -7.21851635 -7.37584894 -7.47242511 -7.37095014 -7.31306837 -7.23677564 -7.42595849 -7.29967736 -7.18370897 -7.00318922 -6.95703746 -6.95094877 -6.9171524 -6.88197278 -6.92002187 -6.84507376 -6.93522432 -6.95871534 -7.19662008 -7.13040484 -7.06908982 -7.22521389 -7.13633881 -7.18314564 -7.2412407 -7.2523541 -7.35728547 -7.26060261 -7.27925093 -7.24352088 -7.19025064 -7.33116753 -7.16754508 -7.1538864 -7.10417569 -7.14596676 -7.13771863 -7.22442183 -7.21438782 -7.21211593 -7.19167027 -7.35589485 -7.42994272 -7.55943239 -7.48866001 -7.5757363 -7.63526706 -7.75540144 -7.61873886 -7.56603797 -7.4489218 -7.43911318 -7.38290381 -7.31424452 -7.23681166 -7.21116445 -7.26012285 -7.35041118 -7.36865028 -7.33489368 -7.19351897 -7.20416526 -7.30851344 -7.19681706 -7.12633179 -7.05785285 -7.06121122 -7.0095034 -6.92212412 -6.90930865 -6.81161574 -6.80614685 -6.89481737 -6.83413243 -6.8385721 -6.83415324 -6.92784632 -7.05684606 -7.07612114 -6.99251506 -6.9889723 -6.97625521 -7.01126416 -7.13841498 -7.14160045 -7.12684359 -7.13387375 -7.29584595 -7.4892254 -7.43816084 -7.57240991 -7.55191582 -7.5343124 -7.61126284 -7.57210818 -7.60749131 -7.41529549 -7.44530986 -7.46745012 -7.34077004 -7.5164581 -7.36274328 -7.23994679 -7.42800488 -8.26556753 ]
which would give a spectrum (as shown). I would like to fit it using 3 piecewise linear lines and also find the first 'break-point' (just after the first zero slope line). Can anyone help me with that?
Thanks

Accepted Answer

Bruno Luong
Bruno Luong on 29 Dec 2020
Edited: Bruno Luong on 29 Dec 2020
Use this FEX
load data.mat % attached above
ydata(end) = []; % your xdata/ydata do not match in length !
slope0 = struct('p', 1, 'x', [min(xdata) max(xdata)], 'v', [0 0]);
% Download BSFK function here
% https://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
pp = BSFK(xdata,ydata, 2, 3, [], struct('KnotRemoval', 'none', 'pntcon', slope0));
% Check
figure
xi = linspace(min(xdata),max(xdata));
yi = ppval(pp,xi)
plot(xdata,ydata,'b',xi,yi,'r');
for xb=pp.breaks
xline(xb);
end
grid on
  12 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by