import%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(%0A%20%20%20%20width%3D%22medium%22%2C%0A%20%20%20%20app_title%3D%22Week%206%20%E2%80%94%20The%20beavers%20of%20the%20Tay%3A%20logistic%20growth%22%2C%0A)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Week%206%3A%20The%20beavers%20of%20the%20Tay%20%E2%80%94%20logistic%20growth%20and%20stability%0A%20%20%20%20%23%23%20Computation%20lecture%0A%0A%20%20%20%20**MATH4120%20%E2%80%94%20Mathematical%20Modelling%20and%20Programming**%20Lancaster%20University%2C%202026%E2%80%9327%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Where%20are%20they%3F%0A%0A%20%20%20%20This%20lecture%20is%20about%20the%20beavers%20living%20on%20the%20river%20Tay%20in%20Scotland.%20The%20Tay%20flows%20from%20the%20Highlands%20through%20Perth%20(the%20marker)%20and%20into%20the%20sea%20at%20Dundee%2C%20about%20165%20miles%20north%20of%20Lancaster%20as%20the%20crow%20flies.%20Zoom%20out%20to%20find%20Lancaster%2C%20and%20zoom%20in%20to%20follow%20the%20Tay%20and%20the%20rivers%20that%20flow%20into%20it%2C%20such%20as%20the%20Earn%2C%20the%20Isla%20and%20the%20Tummel.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.Html(%0A%20%20%20%20%20%20%20%20'%3Ciframe%20width%3D%22100%25%22%20height%3D%22450%22%20style%3D%22border%3A1px%20solid%20%23ccc%22%20'%0A%20%20%20%20%20%20%20%20'src%3D%22https%3A%2F%2Fwww.openstreetmap.org%2Fexport%2Fembed.html%3Fbbox%3D-6.0%252C55.6%252C-2.2%252C57.1%26amp%3Blayer%3Dmapnik%26amp%3Bmarker%3D56.396%252C-3.437%22%20'%0A%20%20%20%20%20%20%20%20'title%3D%22Map%20of%20the%20Tay%20area%22%3E%3C%2Fiframe%3E'%0A%20%20%20%20%20%20%20%20'%3Cp%20style%3D%22font-size%3A0.8em%22%3EMap%20%C2%A9%20%3Ca%20href%3D%22https%3A%2F%2Fwww.openstreetmap.org%2Fcopyright%22%20target%3D%22_blank%22%3EOpenStreetMap%3C%2Fa%3E%20contributors.%20'%0A%20%20%20%20%20%20%20%20'%3Ca%20href%3D%22https%3A%2F%2Fwww.openstreetmap.org%2F%3Fmlat%3D56.396%26amp%3Bmlon%3D-3.437%23map%3D8%2F56.4%2F-4.0%22%20target%3D%22_blank%22%3EOpen%20a%20larger%20map%3C%2Fa%3E.%3C%2Fp%3E'%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20here%20are%20the%20animals%20themselves%2C%20in%20a%20short%20film%20by%20NatureScot%20%5B7%5D%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.Html(%0A%20%20%20%20%20%20%20%20'%3Ciframe%20width%3D%22100%25%22%20height%3D%22400%22%20'%0A%20%20%20%20%20%20%20%20'src%3D%22https%3A%2F%2Fwww.youtube-nocookie.com%2Fembed%2FBmDlnkIscLo%22%20'%0A%20%20%20%20%20%20%20%20'title%3D%22Living%20with%20beavers%20(NatureScot)%22%20frameborder%3D%220%22%20'%0A%20%20%20%20%20%20%20%20'allow%3D%22accelerometer%3B%20autoplay%3B%20clipboard-write%3B%20encrypted-media%3B%20gyroscope%3B%20picture-in-picture%3B%20web-share%22%20'%0A%20%20%20%20%20%20%20%20'referrerpolicy%3D%22strict-origin-when-cross-origin%22%20allowfullscreen%3E%3C%2Fiframe%3E'%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20---%0A%0A%20%20%20%20Beavers%20were%20hunted%20to%20extinction%20in%20Britain%20centuries%20ago.%20In%202009%20a%20licensed%20trial%20released%20a%20few%20families%20in%20Knapdale%2C%20Argyll.%20At%20about%20the%20same%20time%2C%20a%20wild%20population%20was%20growing%20on%20the%20river%20Tay%20from%20beavers%20that%20had%20escaped%20or%20been%20released%20without%20a%20licence.%20Scotland%20let%20both%20populations%20stay%2C%20and%20since%202019%20beavers%20have%20been%20a%20protected%20species%3A%20they%20can%20only%20be%20moved%20or%20killed%20under%20licence%20%5B1%2C%206%5D.%0A%0A%20%20%20%20NatureScot%20has%20surveyed%20the%20Tay%20beavers%20three%20times%2C%20in%202012%2C%202017%2F18%20and%202020%2F21%20%5B2%2C%203%2C%204%5D.%20A%20fourth%20survey%20was%20carried%20out%20in%202025%2C%20and%20its%20report%20is%20being%20finalised%20now%20%5B5%5D.%0A%0A%20%20%20%20So%20what%20will%20the%20new%20survey%20show%2C%20and%20what%20would%20that%20tell%20us%20about%20the%20beavers'%20future%3F%20Today%20we%20use%20the%20maths%20from%20this%20week's%20lectures%20to%20make%20our%20own%20forecast%2C%20in%20five%20steps%3A%0A%0A%20%20%20%201.%20plot%20the%20three%20surveys%3B%0A%20%20%20%202.%20warm%20up%20with%20Python%20functions%2C%20and%20work%20out%20the%20growth%20rate%20%24%5Calpha%24%20from%20the%20exponential%20model%20(5.2)%3B%0A%20%20%20%203.%20code%20the%20logistic%20model%20(5.4)%20and%20find%20which%20carrying%20capacities%20%24M%24%20fit%20the%20surveys%3B%0A%20%20%20%204.%20draw%20the%20phase%20portrait%20(Section%205.5)%3B%0A%20%20%20%205.%20use%20stability%20and%20linearisation%20(Section%205.6)%20to%20see%20how%20fast%20the%20beavers%20recover%20after%20a%20flood.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20How%20these%20numbers%20were%20found%0A%0A%20%20%20%20The%20data%20in%20this%20notebook%20were%20found%20and%20processed%20with%20an%20AI%20coding%20assistant%20(Claude%20Code).%20It%20searched%20NatureScot's%20reports%2C%20pulled%20out%20the%20numbers%2C%20and%20helped%20make%20sense%20of%20how%20they%20are%20reported.%20For%20example%2C%20a%20survey%20does%20not%20count%20beavers%3A%20people%20walk%20the%20rivers%20looking%20for%20feeding%20signs%2C%20dams%2C%20lodges%20and%20scent%20marks%2C%20work%20out%20how%20many%20family%20territories%20there%20are%2C%20and%20multiply%20by%20about%203.8%20beavers%20per%20family%20%5B2%5D.%20Every%20number%20below%20is%20from%20a%20published%20report%2C%20listed%20at%20the%20end.%0A%0A%20%20%20%20One%20suggestion%20we%20did%20not%20keep.%20Three%20surveys%20look%20sparse%20on%20a%20plot%2C%20and%20when%20asked%20to%20make%20it%20look%20fuller%2C%20the%20AI%20suggested%20inventing%20values%20for%20the%20years%20in%20between.%20Made-up%20points%20on%20a%20plot%20look%20like%20data%2C%20so%20we%20left%20them%20out.%20Three%20surveys%20in%20nine%20years%20is%20a%20normal%20amount%20of%20data%20for%20a%20wild%20animal%20population.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%0A%20%20%20%20return%20np%2C%20plt%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201.%20The%20data%0A%0A%20%20%20%20Time%20%24t%24%20is%20in%20years%20since%20the%202012%20survey.%20Each%20survey%20gives%20a%20best%20estimate%20and%20a%20range%2C%20because%20the%20number%20of%20beavers%20per%20family%20varies.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20survey_t%20%3D%20np.array(%5B0.0%2C%205.5%2C%208.5%5D)%20%20%20%20%20%20%20%20%20%23%20years%20since%20the%202012%20survey%0A%20%20%20%20survey_N%20%3D%20np.array(%5B146%2C%20433%2C%20954%5D)%20%20%20%20%20%20%20%20%20%23%20best%20estimate%20of%20the%20number%20of%20beavers%0A%20%20%20%20survey_low%20%3D%20np.array(%5B106%2C%20319%2C%20602%5D)%20%20%20%20%20%20%20%23%20lowest%20estimate%20in%20the%20report%0A%20%20%20%20survey_high%20%3D%20np.array(%5B187%2C%20547%2C%201381%5D)%20%20%20%20%20%23%20highest%20estimate%20in%20the%20report%0A%20%20%20%20return%20survey_N%2C%20survey_high%2C%20survey_low%2C%20survey_t%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(np%2C%20plt%2C%20survey_N%2C%20survey_high%2C%20survey_low%2C%20survey_t)%3A%0A%20%20%20%20_fig_d%2C%20_ax_d%20%3D%20plt.subplots(figsize%3D(9%2C%204))%0A%20%20%20%20_err%20%3D%20np.array(%5Bsurvey_N%20-%20survey_low%2C%20survey_high%20-%20survey_N%5D)%0A%20%20%20%20_ax_d.errorbar(2012%20%2B%20survey_t%2C%20survey_N%2C%20yerr%3D_err%2C%20fmt%3D%22o%22%2C%20color%3D%22%231a5276%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markersize%3D9%2C%20capsize%3D6%2C%20linewidth%3D2)%0A%20%20%20%20for%20_tt%2C%20_nn%2C%20_lab%20in%20zip(survey_t%2C%20survey_N%2C%20%5B%222012%22%2C%20%222017%2F18%22%2C%20%222020%2F21%22%5D)%3A%0A%20%20%20%20%20%20%20%20_ax_d.text(2012%20%2B%20_tt%20%2B%200.25%2C%20_nn%2C%20f%22%7B_lab%7D%3A%20%7B_nn%7D%22%2C%20va%3D%22center%22%2C%20fontsize%3D11%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22%231a5276%22)%0A%20%20%20%20_ax_d.set_xlim(2011%2C%202023)%0A%20%20%20%20_ax_d.set_ylim(0%2C%201500)%0A%20%20%20%20_ax_d.set_xlabel(%22year%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_d.set_ylabel(%22beavers%20on%20the%20Tay%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_d.set_title(%22Three%20surveys%3A%20best%20estimate%20and%20range%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_d.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_d.tight_layout()%0A%20%20%20%20_fig_d%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.%20Warm-up%3A%20functions%2C%20and%20the%20growth%20rate%0A%0A%20%20%20%20While%20a%20population%20is%20small%20compared%20with%20what%20its%20environment%20can%20hold%2C%20it%20grows%20like%20the%20exponential%20model%20from%20Monday%2C%20%5C%5B%5Cfrac%7BdN%7D%7Bdt%7D%20%3D%20%5Calpha%20N%2C%20%5Ctag%7B5.1%7D%5C%5D%20whose%20solution%20is%20%5C%5BN(t)%20%3D%20N_0%20e%5E%7B%5Calpha%20t%7D.%20%5Ctag%7B5.2%7D%5C%5D%20If%20it%20goes%20from%20%24N_%5Ctext%7Bstart%7D%24%20to%20%24N_%5Ctext%7Bend%7D%24%20in%20a%20number%20of%20years%2C%20then%20%24N_%5Ctext%7Bend%7D%20%3D%20N_%5Ctext%7Bstart%7D%5C%2C%20e%5E%7B%5Calpha%20%5Ctimes%20%5Ctext%7Byears%7D%7D%24.%20Take%20logs%20and%20solve%20for%20%24%5Calpha%24%3A%20%5C%5B%5Calpha%20%3D%20%5Cfrac%7B%5Cln(N_%5Ctext%7Bend%7D%2FN_%5Ctext%7Bstart%7D)%7D%7B%5Ctext%7Byears%7D%7D.%5C%5D%0A%0A%20%20%20%20A%20**function**%20packages%20a%20formula%20so%20we%20can%20use%20it%20again%20with%20different%20numbers.%20In%20last%20week's%20poll%2C%20about%201%20in%205%20of%20you%20thought%20a%20cell%20like%20the%20one%20below%20shows%20nothing%2C%20because%20there%20is%20no%20%60print%60.%0A%0A%20%20%20%20**Predict**%20what%20the%20cell%20shows%20before%20you%20run%20it.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20def%20growth_rate(N_start%2C%20N_end%2C%20years)%3A%0A%20%20%20%20%20%20%20%20return%20np.log(N_end%20%2F%20N_start)%20%2F%20years%20%20%20%20%23%20equation%20(5.2)%2C%20solved%20for%20alpha%0A%0A%20%20%20%20growth_rate(146%2C%20433%2C%205.5)%0A%20%20%20%20return%20(growth_rate%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20A%20notebook%20cell%20shows%20the%20value%20of%20its%20**last%20line**%2C%20so%20you%20see%20the%20number%20without%20a%20%60print%60.%20%60return%60%20hands%20a%20value%20back%20to%20whoever%20called%20the%20function%3B%20%60print%60%20only%20puts%20text%20on%20the%20screen.%0A%0A%20%20%20%20The%20numbers%20go%20into%20the%20function%20**in%20order**%3A%20the%20first%20becomes%20%60N_start%60%2C%20the%20second%20%60N_end%60%2C%20the%20third%20%60years%60.%20**Predict%3A**%20what%20happens%20if%20we%20swap%20the%20first%20two%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(growth_rate)%3A%0A%20%20%20%20growth_rate(433%2C%20146%2C%205.5)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20same%20size%2C%20but%20negative%3A%20Python%20has%20no%20idea%20which%20number%20you%20meant%20as%20the%20start%2C%20so%20it%20computed%20a%20population%20*shrinking*%20from%20433%20to%20146.%20Now%20the%20two%20intervals%2C%20using%20positions%20in%20the%20arrays%20(counting%20from%200%2C%20as%20last%20week)%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(growth_rate%2C%20np%2C%20survey_N%2C%20survey_t)%3A%0A%20%20%20%20alpha_early%20%3D%20growth_rate(survey_N%5B0%5D%2C%20survey_N%5B1%5D%2C%20survey_t%5B1%5D%20-%20survey_t%5B0%5D)%0A%20%20%20%20alpha_recent%20%3D%20growth_rate(survey_N%5B1%5D%2C%20survey_N%5B2%5D%2C%20survey_t%5B2%5D%20-%20survey_t%5B1%5D)%0A%20%20%20%20print(%22alpha%2C%202012%20to%202017%2F18%3A%20%20%20%22%2C%20round(alpha_early%2C%203))%0A%20%20%20%20print(%22alpha%2C%202017%2F18%20to%202020%2F21%3A%22%2C%20round(alpha_recent%2C%203))%0A%20%20%20%20print(%22growth%20per%20year%2C%202017%2F18%20to%202020%2F21%3A%22%2C%20round(100%20*%20(np.exp(alpha_recent)%20-%201))%2C%20%22%25%22)%0A%20%20%20%20return%20(alpha_recent%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20NatureScot%20reported%2030%25%20a%20year%20between%20the%20last%20two%20surveys%20%5B4%5D.%20Our%20%24%5Calpha%20%3D%200.263%24%20is%20the%20same%20thing%20written%20differently%3A%20growing%20by%2030%25%20a%20year%20means%20multiplying%20by%201.30%20each%20year%2C%20and%20%24e%5E%7B0.263%7D%20%3D%201.30%24.%20The%20%24%5Calpha%24%20in%20(5.1)%20is%20a%20rate%20of%20change%20at%20each%20instant%2C%20%24%5Calpha%20%3D%20(dN%2Fdt)%2FN%24%3B%20the%20percentage%20is%20what%20that%20adds%20up%20to%20over%20a%20whole%20year%2C%20because%20the%20growth%20compounds.%0A%0A%20%20%20%20Notice%20that%20the%20rate%20went%20*up*%20between%20the%20two%20intervals.%20The%20logistic%20model%20says%20it%20should%20go%20down%20as%20the%20population%20grows.%20The%20lab%20asks%20you%20why%20that%20might%20be.%0A%0A%20%20%20%20**What%20if%2030%25%20a%20year%20carried%20on%3F**%20Before%20you%20run%20the%20next%20cell%2C%20guess%20how%20many%20beavers%20there%20would%20be%20on%20the%20Tay%20by%202050.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alpha_recent%2C%20np%2C%20survey_N)%3A%0A%20%20%20%20for%20year%20in%20%5B2025%2C%202030%2C%202040%2C%202050%5D%3A%0A%20%20%20%20%20%20%20%20N_projected%20%3D%20survey_N%5B2%5D%20*%20np.exp(alpha_recent%20*%20(year%20-%202020.5))%0A%20%20%20%20%20%20%20%20print(year%2C%20round(N_projected))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Over%20two%20million%20beavers%20by%202050.%20The%20Tay%20can't%20hold%20that%3A%20each%20family%20needs%20a%20stretch%20of%20river%20with%20enough%20trees%20to%20eat%2C%20and%20the%202020%2F21%20survey%20already%20found%20them%20spreading%20into%20neighbouring%20catchments%20%5B4%5D.%20Sooner%20or%20later%20the%20growth%20has%20to%20slow%20down.%0A%0A%20%20%20%20Is%20there%20any%20sign%20of%20a%20slowdown%20in%20the%20three%20surveys%20yet%3F%20The%20curve%20below%20is%20the%20exponential%20model%20(5.2)%20started%20from%20the%202012%20survey%2C%20so%20%24N_0%20%3D%20146%24%2C%20and%20the%20slider%20sets%20%24%5Calpha%24.%20The%20hollow%20circles%20are%20what%20the%20curve%20predicts%20at%20the%20two%20later%20surveys.%0A%0A%20%20%20%20**Before%20you%20move%20the%20slider%3A**%0A%0A%20%20%20%20-%20Which%20%24%5Calpha%24%20do%20you%20expect%20to%20fit%20best%3A%200.198%20(from%20the%20first%20two%20surveys)%2C%200.263%20(from%20the%20last%20two)%2C%20or%20something%20in%20between%3F%0A%20%20%20%20-%20Is%20there%20any%20%24%5Calpha%24%20for%20which%20the%20curve%20passes%20through%20all%20three%20ranges%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20alpha_exp_slider%20%3D%20mo.ui.slider(0.10%2C%200.40%2C%20step%3D0.01%2C%20value%3D0.26%2C%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22growth%20rate%20%CE%B1%20(per%20year)%22)%0A%20%20%20%20return%20(alpha_exp_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20alpha_exp_slider%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20survey_N%2C%0A%20%20%20%20survey_high%2C%0A%20%20%20%20survey_low%2C%0A%20%20%20%20survey_t%2C%0A)%3A%0A%20%20%20%20_alpha%20%3D%20alpha_exp_slider.value%0A%20%20%20%20_t_curve%20%3D%20np.linspace(0%2C%2013%2C%20300)%0A%20%20%20%20_N_curve%20%3D%20survey_N%5B0%5D%20*%20np.exp(_alpha%20*%20_t_curve)%20%20%20%20%20%20%20%23%20equation%20(5.2)%2C%20N_0%20%3D%20146%0A%20%20%20%20_N_at_surveys%20%3D%20survey_N%5B0%5D%20*%20np.exp(_alpha%20*%20survey_t)%0A%0A%20%20%20%20_fig_e%2C%20_ax_e%20%3D%20plt.subplots(figsize%3D(9%2C%204.5))%0A%20%20%20%20_err_e%20%3D%20np.array(%5Bsurvey_N%20-%20survey_low%2C%20survey_high%20-%20survey_N%5D)%0A%20%20%20%20_ax_e.errorbar(2012%20%2B%20survey_t%2C%20survey_N%2C%20yerr%3D_err_e%2C%20fmt%3D%22o%22%2C%20color%3D%22%231a5276%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markersize%3D9%2C%20capsize%3D6%2C%20linewidth%3D2%2C%20label%3D%22surveys%20(best%20estimate%20and%20range)%22)%0A%20%20%20%20_ax_e.plot(2012%20%2B%20_t_curve%2C%20_N_curve%2C%20color%3D%22%23c0392b%22%2C%20linewidth%3D2.5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3Df%22exponential%20(5.2)%2C%20%CE%B1%20%3D%20%7B_alpha%3A.2f%7D%22)%0A%20%20%20%20_ax_e.plot(2012%20%2B%20survey_t%5B1%3A%5D%2C%20_N_at_surveys%5B1%3A%5D%2C%20%22o%22%2C%20markersize%3D11%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markerfacecolor%3D%22none%22%2C%20markeredgecolor%3D%22%23c0392b%22%2C%20markeredgewidth%3D2)%0A%20%20%20%20_ax_e.set_xlim(2011%2C%202026)%0A%20%20%20%20_ax_e.set_ylim(0%2C%202500)%0A%20%20%20%20_ax_e.set_xlabel(%22year%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_e.set_ylabel(%22beavers%20on%20the%20Tay%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_e.set_title(f%22%CE%B1%20%3D%20%7B_alpha%3A.2f%7D%2C%20that%20is%20%7B100%20*%20(np.exp(_alpha)%20-%201)%3A.0f%7D%25%20a%20year%3A%20%20%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%7B_N_at_surveys%5B1%5D%3A.0f%7D%20in%202017%2F18%2C%20%20%7B_N_at_surveys%5B2%5D%3A.0f%7D%20in%202020%2F21%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_e.legend(loc%3D%22upper%20left%22%2C%20fontsize%3D10)%0A%20%20%20%20_ax_e.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_e.tight_layout()%0A%20%20%20%20mo.vstack(%5Balpha_exp_slider%2C%20_fig_e%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20to%20notice%20(open%20after%20you%20have%20tried%20the%20slider)%0A%0A%20%20%20%20With%20%24%5Calpha%20%3D%200.26%24%20the%20curve%20overshoots%20the%202017%2F18%20range%3A%20it%20predicts%20about%20610%20beavers%20when%20the%20survey%20says%20at%20most%20547.%20Any%20%24%5Calpha%24%20from%20about%200.17%20to%200.24%20passes%20through%20all%20three%20ranges%2C%20and%20%24%5Calpha%20%3D%200.22%24%20hits%20954%20almost%20exactly.%0A%0A%20%20%20%20So%20the%20three%20surveys%20**do%20not**%20show%20a%20slowdown%3A%20an%20exponential%20curve%20fits%20them%20fine.%20With%20only%20three%20surveys%20we%20cannot%20tell%20whether%20the%20growth%20has%20started%20to%20slow.%20We%20come%20back%20to%20this%20at%20the%20end%20of%20Section%203.%20Notice%20also%20how%20far%20apart%20the%20fitting%20curves%20are%20by%202025%3A%20from%20about%201300%20beavers%20(%24%5Calpha%20%3D%200.17%24)%20to%20about%203300%20(%24%5Calpha%20%3D%200.24%24).%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20simplest%20model%20whose%20growth%20slows%20down%20by%20itself%20is%20the%20logistic.%0A%0A%20%20%20%20%23%23%203.%20The%20logistic%20model%0A%0A%20%20%20%20On%20Monday%3A%20%5C%5B%5Cfrac%7BdN%7D%7Bdt%7D%20%3D%20%5Calpha%5Cleft(1%20-%20%5Cfrac%7BN%7D%7BM%7D%5Cright)N%2C%20%5Ctag%7B5.4%7D%5C%5D%20where%20%24M%24%20is%20the%20**carrying%20capacity**.%20Nobody%20knows%20%24M%24%20for%20the%20Tay.%20For%20now%20we%20guess%20%24M%20%3D%203000%24%2C%20and%20use%20%24%5Calpha%20%3D%200.26%24%20from%20the%20two%20most%20recent%20surveys.%0A%0A%20%20%20%20**This%20line%20is%20equation%20(5.4)%3A**%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20alpha_beaver%20%3D%200.26%20%20%20%20%20%23%20per%20year%2C%20from%20the%20two%20most%20recent%20surveys%0A%20%20%20%20M_beaver%20%3D%203000%20%20%20%20%20%20%20%20%20%23%20carrying%20capacity%3A%20a%20guess%20for%20now%0A%0A%20%20%20%20def%20beaver_rate(t%2C%20N)%3A%0A%20%20%20%20%20%20%20%20return%20alpha_beaver%20*%20(1%20-%20N%20%2F%20M_beaver)%20*%20N%20%20%20%20%23%20equation%20(5.4)%0A%0A%20%20%20%20return%20M_beaver%2C%20alpha_beaver%2C%20beaver_rate%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20function%20takes%20%60t%60%20as%20well%20as%20%60N%60%2C%20even%20though%20(5.4)%20doesn't%20use%20%60t%60.%20That%20is%20so%20it%20fits%20the%20Week%204%20loop%2C%20which%20always%20asks%20for%20the%20slope%20at%20a%20time%20and%20a%20value.%0A%0A%20%20%20%20**Predict**%20before%20you%20run%3A%20for%20which%20of%20these%20populations%20is%20the%20rate%20negative%3F%20Which%20gives%20the%20biggest%20rate%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(beaver_rate)%3A%0A%20%20%20%20for%20N_test%20in%20%5B146%2C%201500%2C%203000%2C%204000%5D%3A%0A%20%20%20%20%20%20%20%20print(%22N%20%3D%22%2C%20N_test%2C%20%22%20%20dN%2Fdt%20%3D%22%2C%20round(beaver_rate(0%2C%20N_test)%2C%201))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Answer%0A%0A%20%20%20%20Below%20%24M%20%3D%203000%24%20the%20bracket%20%241%20-%20N%2FM%24%20is%20positive%20and%20the%20population%20grows%3B%20at%20%24M%24%20it%20is%200%3B%20above%20%24M%24%20it%20is%20negative%20and%20the%20population%20shrinks.%20The%20biggest%20rate%20is%20at%20%24N%20%3D%201500%20%3D%20M%2F2%24%2C%20about%20195%20beavers%20a%20year.%20At%20%24N%20%3D%20146%24%20the%20bracket%20is%20%240.95%24%2C%20almost%201%2C%20so%20the%20population%20grows%20almost%20exponentially%3A%20that%20is%20why%20the%20exponential%20model%20was%20good%20for%20estimating%20%24%5Calpha%24%20from%20the%20early%20surveys%20(the%20key%20idea%20in%20Section%205.4).%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%23%203.1%20Follow%20the%20arrows%20(Week%204)%0A%0A%20%20%20%20In%20Week%204%20we%20traced%20a%20solution%20by%20standing%20at%20a%20point%2C%20taking%20a%20small%20step%20%24h%24%20along%20the%20slope%2C%20and%20looking%20again%3A%20%24N_%5Ctext%7Bnew%7D%20%3D%20N%20%2B%20h%20%5Ctimes%20%5Ctext%7Bslope%7D%24.%20**On%20paper%3A**%20one%20step%20of%20a%20whole%20year%2C%20%24h%20%3D%201%24%2C%20starting%20from%20%24N%20%3D%20146%24.%20You%20need%20the%20slope%20at%20146%20from%20the%20cell%20above.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(beaver_rate)%3A%0A%20%20%20%20h_hand%20%3D%201.0%0A%20%20%20%20N_after_one_year%20%3D%20146%20%2B%20h_hand%20*%20beaver_rate(0%2C%20146)%0A%20%20%20%20print(%22after%20one%20step%20of%20h%20%3D%201%20year%3A%22%2C%20round(N_after_one_year%2C%201))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20loop%20from%20Week%204%20does%20the%20same%20with%202000%20small%20steps.%20On%20Monday%20you%20also%20saw%20the%20exact%20solution%2C%20%5C%5BN(t)%20%3D%20%5Cfrac%7BM%20N_0%7D%7B(M%20-%20N_0)e%5E%7B-%5Calpha%20t%7D%20%2B%20N_0%7D.%20%5Ctag%7B5.5%7D%5C%5D%20**This%20line%20is%20equation%20(5.5)%3A**%20%60return%20M%20*%20N0%20%2F%20((M%20-%20N0)%20*%20np.exp(-alpha%20*%20t)%20%2B%20N0)%60.%20The%20two%20should%20agree.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20def%20follow_arrows(f%2C%20t_start%2C%20y_start%2C%20t_stop%2C%20n_steps%3D2000)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Trace%20a%20solution%20curve%3A%20take%20a%20tiny%20step%20along%20the%20arrow%2C%20then%20look%20again.%22%22%22%0A%20%20%20%20%20%20%20%20h%20%3D%20(t_stop%20-%20t_start)%20%2F%20n_steps%0A%20%20%20%20%20%20%20%20t_values%20%3D%20%5Bt_start%5D%0A%20%20%20%20%20%20%20%20y_values%20%3D%20%5By_start%5D%0A%20%20%20%20%20%20%20%20for%20step%20in%20range(n_steps)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20t_now%20%3D%20t_values%5B-1%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20y_now%20%3D%20y_values%5B-1%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20t_values.append(t_now%20%2B%20h)%0A%20%20%20%20%20%20%20%20%20%20%20%20y_values.append(y_now%20%2B%20h%20*%20f(t_now%2C%20y_now))%0A%20%20%20%20%20%20%20%20return%20np.array(t_values)%2C%20np.array(y_values)%0A%0A%20%20%20%20def%20logistic_formula(t%2C%20N0%2C%20alpha%2C%20M)%3A%0A%20%20%20%20%20%20%20%20return%20M%20*%20N0%20%2F%20((M%20-%20N0)%20*%20np.exp(-alpha%20*%20t)%20%2B%20N0)%20%20%20%20%23%20equation%20(5.5)%0A%0A%20%20%20%20return%20follow_arrows%2C%20logistic_formula%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20M_beaver%2C%0A%20%20%20%20alpha_beaver%2C%0A%20%20%20%20beaver_rate%2C%0A%20%20%20%20follow_arrows%2C%0A%20%20%20%20logistic_formula%2C%0A%20%20%20%20np%2C%0A)%3A%0A%20%20%20%20t_loop%2C%20N_loop%20%3D%20follow_arrows(beaver_rate%2C%200.0%2C%20146.0%2C%2025.0)%0A%20%20%20%20N_exact%20%3D%20logistic_formula(t_loop%2C%20146.0%2C%20alpha_beaver%2C%20M_beaver)%0A%20%20%20%20print(%22largest%20gap%20between%20loop%20and%20formula%3A%22%2C%20round(np.max(np.abs(N_loop%20-%20N_exact))%2C%202)%2C%20%22beavers%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20About%202%20beavers%20apart%2C%20on%20a%20population%20of%20up%20to%203000.%20That%20was%20for%20%24%5Calpha%20%3D%200.26%24%20and%20%24M%20%3D%203000%24.%20Does%20the%20loop%20work%20for%20any%20%24%5Calpha%24%20and%20%24M%24%3F%20In%20the%20cell%20below%2C%20%60rate_any%60%20is%20(5.4)%20with%20the%20two%20numbers%20taken%20from%20the%20sliders%2C%20and%20the%20loop%20is%20run%20again.%0A%0A%20%20%20%20**Before%20you%20move%20the%20sliders%3A**%20if%20you%20make%20%24%5Calpha%24%20bigger%2C%20will%20the%20gap%20between%20the%20loop%20and%20the%20formula%20grow%20or%20shrink%3F%20What%20about%20a%20bigger%20%24M%24%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20alpha_arrows_slider%20%3D%20mo.ui.slider(0.05%2C%200.80%2C%20step%3D0.01%2C%20value%3D0.26%2C%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22growth%20rate%20%CE%B1%20(per%20year)%22)%0A%20%20%20%20M_arrows_slider%20%3D%20mo.ui.slider(steps%3D%5B500%2C%20750%2C%201000%2C%201500%2C%202000%2C%203000%2C%204000%2C%206000%2C%2010000%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3D3000%2C%20show_value%3DTrue%2C%20label%3D%22carrying%20capacity%20M%22)%0A%20%20%20%20return%20M_arrows_slider%2C%20alpha_arrows_slider%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20M_arrows_slider%2C%0A%20%20%20%20alpha_arrows_slider%2C%0A%20%20%20%20follow_arrows%2C%0A%20%20%20%20logistic_formula%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plt%2C%0A)%3A%0A%20%20%20%20alpha_any%20%3D%20alpha_arrows_slider.value%0A%20%20%20%20M_any%20%3D%20M_arrows_slider.value%0A%0A%20%20%20%20def%20rate_any(t%2C%20N)%3A%0A%20%20%20%20%20%20%20%20return%20alpha_any%20*%20(1%20-%20N%20%2F%20M_any)%20*%20N%20%20%20%20%23%20equation%20(5.4)%2C%20with%20the%20slider%20values%0A%0A%20%20%20%20t_any%2C%20N_any%20%3D%20follow_arrows(rate_any%2C%200.0%2C%20146.0%2C%2025.0)%0A%20%20%20%20N_any_exact%20%3D%20logistic_formula(t_any%2C%20146.0%2C%20alpha_any%2C%20M_any)%0A%20%20%20%20gap_any%20%3D%20np.max(np.abs(N_any%20-%20N_any_exact))%0A%0A%20%20%20%20_fig_l%2C%20_ax_l%20%3D%20plt.subplots(figsize%3D(9%2C%204))%0A%20%20%20%20_ax_l.plot(2012%20%2B%20t_any%2C%20N_any_exact%2C%20color%3D%22%231a5276%22%2C%20linewidth%3D6%2C%20alpha%3D0.3%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22formula%20(5.5)%22)%0A%20%20%20%20_ax_l.plot(2012%20%2B%20t_any%2C%20N_any%2C%20color%3D%22%23922b21%22%2C%20linewidth%3D1.8%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22following%20the%20arrows%20(2000%20steps)%22)%0A%20%20%20%20_top%20%3D%201.15%20*%20max(np.max(N_any)%2C%20np.max(N_any_exact))%0A%20%20%20%20if%20M_any%20%3C%3D%20_top%3A%0A%20%20%20%20%20%20%20%20_ax_l.axhline(M_any%2C%20color%3D%22grey%22%2C%20linestyle%3D%22%3A%22%2C%20linewidth%3D1.2)%0A%20%20%20%20%20%20%20%20_ax_l.text(2012.3%2C%20M_any%20%2B%200.02%20*%20_top%2C%20f%22M%20%3D%20%7BM_any%7D%22%2C%20color%3D%22grey%22%2C%20fontsize%3D10)%0A%20%20%20%20_ax_l.set_xlim(2012%2C%202037)%0A%20%20%20%20_ax_l.set_ylim(0%2C%20_top)%0A%20%20%20%20_ax_l.set_xlabel(%22year%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_l.set_ylabel(%22beavers%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_l.set_title(f%22largest%20gap%20between%20loop%20and%20formula%3A%20%7Bgap_any%3A.1f%7D%20beavers%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_l.legend(fontsize%3D10%2C%20loc%3D%22lower%20right%22)%0A%20%20%20%20_ax_l.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_l.tight_layout()%0A%20%20%20%20mo.vstack(%5Balpha_arrows_slider%2C%20M_arrows_slider%2C%20_fig_l%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20to%20notice%20(open%20after%20you%20have%20tried%20the%20sliders)%0A%0A%20%20%20%20The%20loop%20works%20for%20every%20%24%5Calpha%24%20and%20%24M%24%3A%20nothing%20in%20%60follow_arrows%60%20knows%20about%20beavers%2C%20it%20only%20asks%20%60rate_any%60%20for%20a%20slope.%20The%20gap%20grows%20with%20both%20%24%5Calpha%24%20and%20%24M%24%2C%20because%20a%20steeper%20curve%20bends%20more%20within%20each%20small%20step%2C%20but%20it%20never%20gets%20above%20about%20half%20a%20percent%20of%20%24M%24.%20With%20%24%5Calpha%20%3D%200.8%24%20and%20%24M%20%3D%2010%7B%2C%7D000%24%20it%20is%20about%2036%20beavers%20out%20of%2010%2C000.%20In%20Chapter%206%20you%20will%20see%20why%20the%20gap%20behaves%20like%20this%2C%20and%20how%20to%20make%20it%20smaller.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20loop%20and%20the%20formula%20agree%2C%20so%20from%20here%20on%20we%20use%20whichever%20is%20handier.%0A%0A%20%20%20%20%23%23%23%203.2%20Which%20%24M%24%20fits%20the%20surveys%3F%0A%0A%20%20%20%20Keep%20%24%5Calpha%20%3D%200.26%24%20and%20start%20from%20the%202012%20survey.%20The%20slider%20changes%20%24M%24.%20The%20dashed%20line%20is%20the%20exponential%20model%20(%24M%24%20infinitely%20large)%2C%20and%20the%20hollow%20circle%20is%20what%20the%20curve%20predicts%20for%20the%202025%20survey.%0A%0A%20%20%20%20**Before%20you%20move%20the%20slider%3A**%0A%0A%20%20%20%201.%20Can%20a%20small%20%24M%24%2C%20say%201000%2C%20still%20pass%20through%20all%20three%20ranges%3F%0A%20%20%20%202.%20Which%20%24M%24%20goes%20closest%20to%20the%202020%2F21%20estimate%20of%20954%3F%0A%20%20%20%203.%20How%20much%20do%20the%20possible%20%24M%24%20disagree%20about%20the%202025%20survey%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20M_fit_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20steps%3D%5B700%2C%20800%2C%20900%2C%201000%2C%201250%2C%201500%2C%201750%2C%202000%2C%202500%2C%203000%2C%203500%2C%204000%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%205000%2C%206000%2C%208000%2C%2010000%2C%2020000%5D%2C%0A%20%20%20%20%20%20%20%20value%3D1500%2C%20show_value%3DTrue%2C%20label%3Dr%22Carrying%20capacity%20%24M%24%22)%0A%20%20%20%20return%20(M_fit_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20M_fit_slider%2C%0A%20%20%20%20logistic_formula%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20survey_N%2C%0A%20%20%20%20survey_high%2C%0A%20%20%20%20survey_low%2C%0A%20%20%20%20survey_t%2C%0A)%3A%0A%20%20%20%20_M%20%3D%20M_fit_slider.value%0A%20%20%20%20_alpha%20%3D%200.26%0A%20%20%20%20_t%20%3D%20np.linspace(0%2C%2023%2C%20500)%0A%20%20%20%20_N%20%3D%20logistic_formula(_t%2C%20146.0%2C%20_alpha%2C%20_M)%0A%20%20%20%20_N_surveys%20%3D%20logistic_formula(survey_t%2C%20146.0%2C%20_alpha%2C%20_M)%0A%20%20%20%20_inside%20%3D%20(_N_surveys%20%3E%3D%20survey_low)%20%26%20(_N_surveys%20%3C%3D%20survey_high)%0A%20%20%20%20_N_2025%20%3D%20logistic_formula(13.5%2C%20146.0%2C%20_alpha%2C%20_M)%0A%0A%20%20%20%20_fig_m%2C%20_ax_m%20%3D%20plt.subplots(figsize%3D(10%2C%204.8))%0A%20%20%20%20_err%20%3D%20np.array(%5Bsurvey_N%20-%20survey_low%2C%20survey_high%20-%20survey_N%5D)%0A%20%20%20%20_ax_m.plot(2012%20%2B%20_t%2C%20146%20*%20np.exp(_alpha%20*%20_t)%2C%20%22--%22%2C%20color%3D%22grey%22%2C%20linewidth%3D1.3%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22exponential%20(no%20limit)%22)%0A%20%20%20%20_ax_m.plot(2012%20%2B%20_t%2C%20_N%2C%20color%3D%22%231e8449%22%2C%20linewidth%3D2.5%2C%20label%3Df%22logistic%2C%20M%20%3D%20%7B_M%7D%22)%0A%20%20%20%20_ax_m.axhline(_M%2C%20color%3D%22%231e8449%22%2C%20linestyle%3D%22%3A%22%2C%20linewidth%3D1)%0A%20%20%20%20for%20_i%20in%20range(3)%3A%0A%20%20%20%20%20%20%20%20_col%20%3D%20%22%231a5276%22%20if%20_inside%5B_i%5D%20else%20%22%23922b21%22%0A%20%20%20%20%20%20%20%20_ax_m.errorbar(2012%20%2B%20survey_t%5B_i%5D%2C%20survey_N%5B_i%5D%2C%20yerr%3D_err%5B%3A%2C%20_i%3A_i%20%2B%201%5D%2C%20fmt%3D%22o%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3D_col%2C%20markersize%3D9%2C%20capsize%3D6%2C%20linewidth%3D2%2C%20zorder%3D5)%0A%20%20%20%20_ax_m.plot(2012%20%2B%2013.5%2C%20_N_2025%2C%20%22o%22%2C%20markersize%3D12%2C%20markerfacecolor%3D%22white%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markeredgecolor%3D%22%231e8449%22%2C%20markeredgewidth%3D2.5%2C%20zorder%3D6)%0A%20%20%20%20_ax_m.text(2012%20%2B%2013.5%2C%20_N_2025%20%2B%20220%2C%20f%222025%20survey%3F%5Cn%7B_N_2025%3A.0f%7D%22%2C%20ha%3D%22center%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fontsize%3D10%2C%20color%3D%22%231e8449%22)%0A%20%20%20%20_ax_m.set_xlim(2011%2C%202035)%0A%20%20%20%20_ax_m.set_ylim(0%2C%205000)%0A%20%20%20%20_ax_m.set_xlabel(%22year%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_m.set_ylabel(%22beavers%22%2C%20fontsize%3D12)%0A%20%20%20%20_verdict%20%3D%20%22inside%20all%20three%20ranges%22%20if%20_inside.all()%20else%20f%22misses%20%7B3%20-%20_inside.sum()%7D%20of%20the%203%20ranges%20(red)%22%0A%20%20%20%20_ax_m.set_title(rf%22%24%5Calpha%20%3D%200.26%24%2C%20%24M%20%3D%20%7B_M%7D%24%3A%20%7B_verdict%7D%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_m.legend(fontsize%3D10%2C%20loc%3D%22upper%20left%22)%0A%20%20%20%20_ax_m.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_m.tight_layout()%0A%20%20%20%20mo.vstack(%5BM_fit_slider%2C%20_fig_m%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20to%20notice%20(open%20after%20you%20have%20tried%20the%20slider)%0A%0A%20%20%20%201.%20Every%20%24M%24%20from%20about%201000%20to%204000%20passes%20through%20all%20three%20ranges.%20Below%20that%2C%20the%20curve%20flattens%20too%20early%20to%20reach%20the%202020%2F21%20range%3B%20above%20it%2C%20it%20overshoots.%0A%20%20%20%202.%20%24M%20%5Capprox%203000%24%20goes%20through%20954%20almost%20exactly.%0A%20%20%20%203.%20Those%20curves%20disagree%20a%20lot%20about%202025%3A%20from%20about%20850%20beavers%20(%24M%20%3D%201000%24%2C%20already%20levelling%20off)%20to%20over%202200%20(%24M%20%3D%204000%24).%20The%20three%20surveys%20can't%20tell%20them%20apart%2C%20but%20the%202025%20survey%20will.%20In%20the%20lab%20you%20also%20change%20%24%5Calpha%24%2C%20and%20find%20that%20the%20range%20of%20possible%20%24M%24%20gets%20wider%20still.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%203.3%20What%20NatureScot%20has%20said%20since%0A%0A%20%20%20%20The%202025%20survey%20report%20is%20not%20out%20yet%2C%20but%20NatureScot's%20management%20report%20for%202025%2F26%20%5B5%5D%20gave%20one%20hint%20about%20what%20the%20surveyors%20found%20on%20the%20Tay.%0A%0A%20%20%20%20**Before%20you%20open%20it%3A**%20which%20of%20these%20do%20you%20think%20it%20said%3F%20Which%20curves%20from%20the%20slider%20above%20could%20go%20with%20each%3F%0A%0A%20%20%20%20-%20(a)%20still%20growing%20at%20about%2030%25%20a%20year%3B%0A%20%20%20%20-%20(b)%20still%20growing%2C%20but%20more%20slowly%3B%0A%20%20%20%20-%20(c)%20levelled%20off%3B%0A%20%20%20%20-%20(d)%20falling.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20NatureScot%20said%20(2026)%0A%0A%20%20%20%20The%20population%20is%20still%20increasing%2C%20but%20not%20at%20the%2030%25%20a%20year%20previously%20reported.%20Its%20growth%20appears%20to%20follow%20a%20natural%20curve%2C%20as%20in%20other%20reintroduced%20beaver%20populations%20in%20Europe.%20The%202025%20survey%20is%20complete%20and%20its%20report%20is%20being%20finalised%20%5B5%5D.%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20this%20tells%20us%20(open%20after%20the%20reveal)%0A%0A%20%20%20%20Answer%20(b).%20That%20rules%20out%20the%20exponential%20model%20carrying%20on%20at%2030%25%20a%20year%2C%20which%20would%20mean%20about%203100%20beavers%20by%202025.%20It%20is%20just%20what%20the%20logistic%20model%20predicts%3A%20as%20%24N%24%20grows%2C%20the%20factor%20%241%20-%20N%2FM%24%20in%20(5.4)%20shrinks%2C%20and%20so%20does%20the%20growth%20rate.%20On%20the%20curves%20from%20the%20slider%20(%24%5Calpha%20%3D%200.26%24%2C%20%24M%24%20from%201000%20to%204000)%2C%20the%20growth%20in%202025%20is%20down%20to%20between%20about%204%25%20a%20year%20(%24M%20%3D%201000%24)%20and%2012%25%20a%20year%20(%24M%20%3D%204000%24).%0A%0A%20%20%20%20But%20%22more%20slowly%22%20doesn't%20say%20*how%20much*%20more%20slowly%2C%20so%20it%20can't%20tell%20us%20%24M%24.%20The%20number%20in%20the%20survey%20report%20will.%20Below%2C%20you%20can%20try%20out%20what%20that%20number%20might%20be.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%20Waiting%20for%20the%20fourth%20point%0A%0A%20%20%20%20The%20slider%20sets%20how%20fast%20the%20population%20grew%20each%20year%20between%20the%202020%2F21%20survey%20and%20the%202025%20survey.%20That%20gives%20a%20*what%20if*%20fourth%20point%20(the%20hollow%20star)%3A%20it%20is%20not%20data%2C%20just%20a%20number%20we%20try%20out.%20The%20green%20curve%20is%20the%20logistic%20curve%2C%20started%20from%20146%20in%202012%2C%20that%20passes%20closest%20to%20all%20four%20points.%0A%0A%20%20%20%20**Before%20you%20move%20the%20slider%3A**%20it%20starts%20at%20the%20old%20rate%2C%2030%25%20a%20year.%20What%20%24M%24%20do%20you%20expect%20the%20best%20curve%20to%20have%20there%3F%20As%20you%20slide%20down%20towards%201%25%20a%20year%2C%20what%20happens%20to%20%24M%24%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20growth_2025_slider%20%3D%20mo.ui.slider(1%2C%2030%2C%20step%3D1%2C%20value%3D30%2C%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22growth%20per%20year%2C%202020%2F21%20to%202025%20(%25)%22)%0A%20%20%20%20return%20(growth_2025_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20growth_2025_slider%2C%0A%20%20%20%20logistic_formula%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20survey_N%2C%0A%20%20%20%20survey_high%2C%0A%20%20%20%20survey_low%2C%0A%20%20%20%20survey_t%2C%0A)%3A%0A%20%20%20%20_pct%20%3D%20growth_2025_slider.value%0A%20%20%20%20_N4%20%3D%20survey_N%5B2%5D%20*%20(1%20%2B%20_pct%20%2F%20100)%20**%205%20%20%20%20%20%20%20%20%20%20%23%20five%20years%20after%20the%202020%2F21%20survey%0A%20%20%20%20_t4%20%3D%20np.append(survey_t%2C%2013.5)%0A%20%20%20%20_N_all%20%3D%20np.append(survey_N%2C%20_N4)%0A%0A%20%20%20%20%23%20try%20many%20(alpha%2C%20M)%20pairs%20and%20keep%20the%20one%20closest%20to%20all%20four%20points%0A%20%20%20%20_A%2C%20_Mg%20%3D%20np.meshgrid(np.linspace(0.10%2C%200.80%2C%20141)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20np.exp(np.linspace(np.log(500)%2C%20np.log(100000)%2C%20400))%2C%20indexing%3D%22ij%22)%0A%20%20%20%20_miss%20%3D%20np.zeros_like(_A)%0A%20%20%20%20for%20_tk%2C%20_Nk%20in%20zip(_t4%2C%20_N_all)%3A%0A%20%20%20%20%20%20%20%20_miss%20%3D%20_miss%20%2B%20(np.log(logistic_formula(_tk%2C%20146.0%2C%20_A%2C%20_Mg))%20-%20np.log(_Nk))%20**%202%0A%20%20%20%20_best%20%3D%20np.unravel_index(np.argmin(_miss)%2C%20_miss.shape)%0A%20%20%20%20_a_best%2C%20_M_best%20%3D%20_A%5B_best%5D%2C%20_Mg%5B_best%5D%0A%0A%20%20%20%20_fig_w%2C%20_ax_w%20%3D%20plt.subplots(figsize%3D(10%2C%204.8))%0A%20%20%20%20_err_w%20%3D%20np.array(%5Bsurvey_N%20-%20survey_low%2C%20survey_high%20-%20survey_N%5D)%0A%20%20%20%20_t_w%20%3D%20np.linspace(0%2C%2023%2C%20500)%0A%20%20%20%20_ax_w.plot(2012%20%2B%20_t_w%2C%20logistic_formula(_t_w%2C%20146.0%2C%20_a_best%2C%20_M_best)%2C%20color%3D%22%231e8449%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20linewidth%3D2.5%2C%20label%3D%22logistic%20curve%20closest%20to%20all%20four%20points%22)%0A%20%20%20%20if%20_M_best%20%3C%205000%3A%0A%20%20%20%20%20%20%20%20_ax_w.axhline(_M_best%2C%20color%3D%22%231e8449%22%2C%20linestyle%3D%22%3A%22%2C%20linewidth%3D1)%0A%20%20%20%20_ax_w.errorbar(2012%20%2B%20survey_t%2C%20survey_N%2C%20yerr%3D_err_w%2C%20fmt%3D%22o%22%2C%20color%3D%22%231a5276%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markersize%3D9%2C%20capsize%3D6%2C%20linewidth%3D2%2C%20zorder%3D5%2C%20label%3D%22the%20three%20surveys%22)%0A%20%20%20%20_ax_w.plot(2012%20%2B%2013.5%2C%20_N4%2C%20%22*%22%2C%20markersize%3D22%2C%20markerfacecolor%3D%22white%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20markeredgecolor%3D%22%23c0392b%22%2C%20markeredgewidth%3D2%2C%20zorder%3D6%2C%20label%3D%22what%20if%3F%20(not%20data)%22)%0A%20%20%20%20_ax_w.text(2012%20%2B%2014.0%2C%20_N4%2C%20f%22%7B_N4%3A.0f%7D%3F%22%2C%20va%3D%22center%22%2C%20fontsize%3D11%2C%20color%3D%22%23c0392b%22)%0A%20%20%20%20_ax_w.set_xlim(2011%2C%202035)%0A%20%20%20%20_ax_w.set_ylim(0%2C%205000)%0A%20%20%20%20_ax_w.set_xlabel(%22year%22%2C%20fontsize%3D12)%0A%20%20%20%20_ax_w.set_ylabel(%22beavers%22%2C%20fontsize%3D12)%0A%20%20%20%20if%20_M_best%20%3E%2050000%3A%0A%20%20%20%20%20%20%20%20_M_text%20%3D%20%22M%20above%2050%2C000%3A%20no%20limit%20in%20sight%22%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_M_text%20%3D%20f%22M%20%E2%89%88%20%7B_M_best%3A%2C.0f%7D%22%0A%20%20%20%20_ax_w.set_title(f%22%7B_pct%7D%25%20a%20year%20gives%20%7B_N4%3A.0f%7D%20beavers%20in%202025.%20%20%20Best%20fit%3A%20%CE%B1%20%E2%89%88%20%7B_a_best%3A.2f%7D%2C%20%7B_M_text%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fontsize%3D12)%0A%20%20%20%20_ax_w.legend(fontsize%3D10%2C%20loc%3D%22upper%20left%22)%0A%20%20%20%20_ax_w.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_w.tight_layout()%0A%20%20%20%20mo.vstack(%5Bgrowth_2025_slider%2C%20_fig_w%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20to%20notice%20(open%20after%20you%20have%20tried%20the%20slider)%0A%0A%20%20%20%20At%2030%25%20a%20year%20(about%203500%20beavers%20in%202025)%20the%20best%20curve%20has%20no%20limit%20in%20sight%3A%20it%20is%20the%20exponential%20model%20again.%20Slide%20down%20and%20%24M%24%20comes%20down%20with%20it%3A%20about%204700%20at%2015%25%20a%20year%2C%202400%20at%2010%25%2C%201600%20at%205%25%20and%201200%20at%201%25.%20The%20slower%20the%20growth%2C%20the%20closer%20the%20population%20already%20is%20to%20its%20carrying%20capacity.%0A%0A%20%20%20%20So%20the%20single%20number%20in%20the%20survey%20report%20will%20tell%20us%20far%20more%20than%20%22more%20slowly%22%20did.%20Write%20down%20the%20growth%20rate%20you%20expect%3B%20the%20lab%20asks%20for%20your%20forecast%20too.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204.%20The%20phase%20portrait%0A%0A%20%20%20%20The%20logistic%20equation%20is%20**autonomous**%3A%20the%20right-hand%20side%20depends%20on%20%24N%24%20only%2C%20%24dN%2Fdt%20%3D%20f(N)%24%20as%20in%20(5.6).%20So%20we%20can%20learn%20a%20lot%20from%20the%20graph%20of%20%24f%24%20alone%2C%20without%20solving%20anything%20(Section%205.5)%3A%0A%0A%20%20%20%20-%20where%20%24f(N)%20%3E%200%24%20the%20population%20grows%3A%20arrow%20to%20the%20right%3B%0A%20%20%20%20-%20where%20%24f(N)%20%3C%200%24%20it%20shrinks%3A%20arrow%20to%20the%20left%3B%0A%20%20%20%20-%20where%20%24f(N)%20%3D%200%24%20it%20stays%20put%3A%20an%20**equilibrium**.%20For%20the%20logistic%20model%2C%20%24N%20%3D%200%24%20and%20%24N%20%3D%20M%24.%0A%0A%20%20%20%20Below%2C%20%24M%20%3D%203000%24%20and%20%24%5Calpha%20%3D%200.26%24%20again.%20Four%20populations%20start%20at%20146%20(the%202012%20survey)%2C%20954%20(2020%2F21)%2C%202000%20and%204500.%20The%20last%20one%20is%20above%20%24M%24%3A%20more%20beavers%20than%20the%20river%20can%20feed.%20Drag%20the%20time%20slider.%20Each%20population%20is%20a%20dot%20on%20the%20phase%20line%20(left)%20and%20on%20its%20curve%20%24N(t)%24%20(right).%0A%0A%20%20%20%20**Before%20you%20drag%3A**%0A%0A%20%20%20%201.%20Which%20way%20does%20each%20dot%20move%2C%20and%20where%20does%20it%20stop%3F%0A%20%20%20%202.%20The%20dot%20that%20starts%20at%20146%3A%20where%20on%20the%20phase%20line%20does%20it%20move%20fastest%3F%20What%20does%20%24N(t)%24%20look%20like%20at%20that%20moment%3F%0A%20%20%20%203.%20Can%20the%20dot%20from%204500%20end%20up%20below%203000%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20t_phase_slider%20%3D%20mo.ui.slider(0.0%2C%2030.0%2C%20step%3D0.25%2C%20value%3D0.0%2C%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3Dr%22Years%20since%20the%20start%20%24t%24%22)%0A%20%20%20%20return%20(t_phase_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20M_beaver%2C%0A%20%20%20%20alpha_beaver%2C%0A%20%20%20%20beaver_rate%2C%0A%20%20%20%20logistic_formula%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plt%2C%0A%20%20%20%20t_phase_slider%2C%0A)%3A%0A%20%20%20%20_t_now%20%3D%20t_phase_slider.value%0A%20%20%20%20_starts%20%3D%20%5B146.0%2C%20954.0%2C%202000.0%2C%204500.0%5D%0A%20%20%20%20_cols%20%3D%20%5B%22%231a5276%22%2C%20%22%237d3c98%22%2C%20%22%23e67e22%22%2C%20%22%23922b21%22%5D%0A%0A%20%20%20%20_fig_p%2C%20(_axf%2C%20_axn)%20%3D%20plt.subplots(1%2C%202%2C%20figsize%3D(13%2C%204.8)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20gridspec_kw%3D%7B%22width_ratios%22%3A%20%5B1.15%2C%201%5D%7D)%0A%20%20%20%20%23%20left%3A%20f(N)%20and%20the%20phase%20line%0A%20%20%20%20_N_grid%20%3D%20np.linspace(-200%2C%205000%2C%20500)%0A%20%20%20%20_axf.plot(_N_grid%2C%20beaver_rate(0%2C%20_N_grid)%2C%20color%3D%22%23555%22%2C%20linewidth%3D2)%0A%20%20%20%20_axf.axhline(0%2C%20color%3D%22black%22%2C%20linewidth%3D1.2)%0A%20%20%20%20for%20_x0%2C%20_x1%20in%20%5B(400%2C%20900)%2C%20(1700%2C%202200)%2C%20(4300%2C%203800)%5D%3A%0A%20%20%20%20%20%20%20%20_axf.annotate(%22%22%2C%20xy%3D(_x1%2C%200)%2C%20xytext%3D(_x0%2C%200)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20arrowprops%3D%7B%22arrowstyle%22%3A%20%22-%7C%3E%22%2C%20%22color%22%3A%20%22black%22%2C%20%22lw%22%3A%201.5%7D)%0A%20%20%20%20_axf.plot(0%2C%200%2C%20%22o%22%2C%20markersize%3D11%2C%20markerfacecolor%3D%22white%22%2C%20markeredgecolor%3D%22black%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20markeredgewidth%3D2%2C%20zorder%3D6)%0A%20%20%20%20_axf.plot(M_beaver%2C%200%2C%20%22o%22%2C%20markersize%3D11%2C%20color%3D%22black%22%2C%20zorder%3D6)%0A%20%20%20%20_axf.text(0%2C%20-70%2C%20%220%22%2C%20ha%3D%22center%22%2C%20va%3D%22top%22%2C%20fontsize%3D11)%0A%20%20%20%20_axf.text(M_beaver%2C%20-70%2C%20%22M%22%2C%20ha%3D%22center%22%2C%20va%3D%22top%22%2C%20fontsize%3D11)%0A%20%20%20%20for%20_N0%2C%20_c%20in%20zip(_starts%2C%20_cols)%3A%0A%20%20%20%20%20%20%20%20_N_now%20%3D%20logistic_formula(_t_now%2C%20_N0%2C%20alpha_beaver%2C%20M_beaver)%0A%20%20%20%20%20%20%20%20_axf.plot(_N_now%2C%200%2C%20%22o%22%2C%20color%3D_c%2C%20markersize%3D11%2C%20zorder%3D7)%0A%20%20%20%20%20%20%20%20_axf.plot(_N_now%2C%20beaver_rate(0%2C%20_N_now)%2C%20%22o%22%2C%20color%3D_c%2C%20markersize%3D7%2C%20alpha%3D0.6%2C%20zorder%3D7)%0A%20%20%20%20%20%20%20%20_axf.plot(%5B_N_now%2C%20_N_now%5D%2C%20%5B0%2C%20beaver_rate(0%2C%20_N_now)%5D%2C%20color%3D_c%2C%20linewidth%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alpha%3D0.6)%0A%20%20%20%20_axf.set_xlim(-200%2C%205000)%0A%20%20%20%20_axf.set_ylim(-650%2C%20260)%0A%20%20%20%20_axf.set_xlabel(r%22%24N%24%22%2C%20fontsize%3D12)%0A%20%20%20%20_axf.set_ylabel(r%22%24f(N)%20%3D%20dN%2Fdt%24%20%20(beavers%20per%20year)%22%2C%20fontsize%3D11)%0A%20%20%20%20_axf.set_title(%22phase%20line%3A%20where%20each%20population%20is%20now%22%2C%20fontsize%3D12)%0A%20%20%20%20_axf.grid(True%2C%20alpha%3D0.3)%0A%0A%20%20%20%20%23%20right%3A%20N(t)%20for%20each%20start%0A%20%20%20%20_t_all%20%3D%20np.linspace(0%2C%2030%2C%20400)%0A%20%20%20%20_past%20%3D%20_t_all%20%3C%3D%20_t_now%0A%20%20%20%20for%20_N0%2C%20_c%20in%20zip(_starts%2C%20_cols)%3A%0A%20%20%20%20%20%20%20%20_N_all%20%3D%20logistic_formula(_t_all%2C%20_N0%2C%20alpha_beaver%2C%20M_beaver)%0A%20%20%20%20%20%20%20%20_axn.plot(_t_all%2C%20_N_all%2C%20color%3D_c%2C%20linewidth%3D1.2%2C%20alpha%3D0.3)%0A%20%20%20%20%20%20%20%20_axn.plot(_t_all%5B_past%5D%2C%20_N_all%5B_past%5D%2C%20color%3D_c%2C%20linewidth%3D2.5%2C%20label%3Df%22start%20%7B_N0%3A.0f%7D%22)%0A%20%20%20%20%20%20%20%20_axn.plot(_t_now%2C%20logistic_formula(_t_now%2C%20_N0%2C%20alpha_beaver%2C%20M_beaver)%2C%20%22o%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20color%3D_c%2C%20markersize%3D9%2C%20zorder%3D5)%0A%20%20%20%20_axn.axhline(M_beaver%2C%20color%3D%22grey%22%2C%20linestyle%3D%22%3A%22%2C%20linewidth%3D1)%0A%20%20%20%20_axn.axhline(M_beaver%20%2F%202%2C%20color%3D%22grey%22%2C%20linestyle%3D%22%3A%22%2C%20linewidth%3D1)%0A%20%20%20%20_axn.text(30.3%2C%20M_beaver%20%2F%202%2C%20%22M%2F2%22%2C%20va%3D%22center%22%2C%20fontsize%3D10%2C%20color%3D%22grey%22)%0A%20%20%20%20_axn.text(30.3%2C%20M_beaver%2C%20%22M%22%2C%20va%3D%22center%22%2C%20fontsize%3D10%2C%20color%3D%22grey%22)%0A%20%20%20%20_axn.set_xlim(0%2C%2030)%0A%20%20%20%20_axn.set_ylim(0%2C%204700)%0A%20%20%20%20_axn.set_xlabel(r%22%24t%24%20(years)%22%2C%20fontsize%3D12)%0A%20%20%20%20_axn.set_ylabel(r%22%24N%24%22%2C%20fontsize%3D12)%0A%20%20%20%20_axn.set_title(rf%22%24t%20%3D%20%7B_t_now%3Ag%7D%24%20years%22%2C%20fontsize%3D12)%0A%20%20%20%20_axn.legend(fontsize%3D9%2C%20loc%3D%22upper%20right%22)%0A%20%20%20%20_axn.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_p.tight_layout()%0A%20%20%20%20mo.vstack(%5Bt_phase_slider%2C%20_fig_p%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20to%20notice%0A%0A%20%20%20%201.%20The%20dots%20below%20%24M%24%20move%20right%20and%20the%20one%20above%20moves%20left%3B%20all%20of%20them%20end%20at%20%24M%24.%20None%20of%20them%20can%20reach%20%24M%24%20in%20finite%20time%2C%20and%20none%20can%20cross%20it%3A%20at%20%24M%24%20the%20speed%20is%200.%0A%20%20%20%202.%20A%20dot's%20speed%20is%20the%20height%20of%20the%20curve%20above%20it.%20The%20dot%20from%20146%20is%20slow%20at%20first%2C%20fastest%20as%20it%20passes%20%24N%20%3D%20M%2F2%20%3D%201500%24%20(the%20top%20of%20the%20parabola)%2C%20then%20slows%20down%20near%20%24M%24.%20So%20%24N(t)%24%20is%20steepest%20when%20it%20crosses%20%24M%2F2%24%3A%20that%20is%20the%20bend%20in%20the%20middle%20of%20the%20S-shape.%0A%20%20%20%203.%20The%20dot%20from%204500%20falls%20fast%20at%20first%20(the%20curve%20is%20far%20below%20the%20axis%20there)%20and%20slows%20down%20as%20it%20nears%203000%2C%20but%20never%20goes%20below%20it.%0A%20%20%20%204.%20%24N%20%3D%200%24%20is%20an%20equilibrium%20too%2C%20but%20the%20arrows%20point%20away%20from%20it%3A%20any%20small%20population%20grows.%20%24N%20%3D%20M%24%20is%20the%20one%20everything%20heads%20towards.%20Section%205.6%20makes%20this%20precise.%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%205.%20Stability%3A%20recovering%20from%20a%20flood%0A%0A%20%20%20%20Suppose%20the%20beavers%20have%20reached%20%24M%24%2C%20and%20a%20bad%20flood%20takes%20away%20part%20of%20the%20population.%20How%20quickly%20does%20it%20recover%3F%0A%0A%20%20%20%20Near%20an%20equilibrium%2C%20the%20curve%20%24f(N)%24%20is%20close%20to%20its%20tangent%20line.%20Write%20%24%5Ctilde%20N%20%3D%20N%20-%20M%24%20for%20the%20gap%20from%20%24M%24.%20The%20linearisation%20(5.7)%20says%20%5C%5B%5Cfrac%7Bd%5Ctilde%20N%7D%7Bdt%7D%20%3D%20f'(M)%5C%2C%5Ctilde%20N.%5C%5D%20Differentiating%20(5.4)%20gives%20%24f'(N)%20%3D%20%5Calpha(1%20-%202N%2FM)%24.%20**This%20line%20is%20%24f'(N)%24%3A**%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M_beaver%2C%20alpha_beaver)%3A%0A%20%20%20%20def%20beaver_rate_slope(N)%3A%0A%20%20%20%20%20%20%20%20return%20alpha_beaver%20*%20(1%20-%202%20*%20N%20%2F%20M_beaver)%20%20%20%20%23%20f'(N)%2C%20from%20differentiating%20(5.4)%0A%0A%20%20%20%20print(%22f'(0)%20%3D%22%2C%20beaver_rate_slope(0))%0A%20%20%20%20print(%22f'(M)%20%3D%22%2C%20beaver_rate_slope(M_beaver))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%24f'(M)%20%3D%20-%5Calpha%20%3C%200%24%2C%20so%20%24M%24%20is%20**stable**%3A%20the%20gap%20obeys%20%24d%5Ctilde%20N%2Fdt%20%3D%20-%5Calpha%20%5Ctilde%20N%24%2C%20so%20it%20shrinks%20like%20%24e%5E%7B-%5Calpha%20t%7D%24%20and%20halves%20every%20%24%5Cln%202%2F%5Calpha%20%5Capprox%202.7%24%20years.%20%24f'(0)%20%3D%20%5Calpha%20%3E%200%24%2C%20so%20%240%24%20is%20**unstable**%2C%20and%20near%200%20the%20linearisation%20is%20%24d%5Ctilde%20N%2Fdt%20%3D%20%5Calpha%20%5Ctilde%20N%24%3A%20exactly%20the%20exponential%20model%20again.%0A%0A%20%20%20%20The%20slider%20sets%20how%20much%20of%20the%20population%20the%20flood%20takes.%20On%20the%20left%2C%20the%20tangent%20line%20at%20%24M%24%20(slope%20%24-%5Calpha%24)%20is%20what%20the%20linearisation%20uses%20instead%20of%20the%20curve.%20On%20the%20right%2C%20the%20recovery%20from%20the%20full%20model%20(5.4)%20and%20from%20the%20linearisation.%0A%0A%20%20%20%20**Before%20you%20move%20it%3A**%20for%20a%20small%20flood%2C%20will%20the%20linearisation%20be%20close%3F%20What%20about%20a%20flood%20that%20takes%2080%25%20of%20the%20beavers%3A%20will%20the%20linearisation%20say%20the%20recovery%20is%20faster%20or%20slower%20than%20it%20really%20is%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20flood_slider%20%3D%20mo.ui.slider(5%2C%2090%2C%20step%3D5%2C%20value%3D20%2C%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Beavers%20lost%20in%20the%20flood%20(%25)%22)%0A%20%20%20%20return%20(flood_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20M_beaver%2C%0A%20%20%20%20alpha_beaver%2C%0A%20%20%20%20beaver_rate%2C%0A%20%20%20%20flood_slider%2C%0A%20%20%20%20logistic_formula%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plt%2C%0A)%3A%0A%20%20%20%20_p%20%3D%20flood_slider.value%20%2F%20100%0A%20%20%20%20_N_start%20%3D%20(1%20-%20_p)%20*%20M_beaver%0A%20%20%20%20_t%20%3D%20np.linspace(0%2C%2025%2C%20500)%0A%20%20%20%20_N_full%20%3D%20logistic_formula(_t%2C%20_N_start%2C%20alpha_beaver%2C%20M_beaver)%0A%20%20%20%20_N_lin%20%3D%20M_beaver%20-%20_p%20*%20M_beaver%20*%20np.exp(-alpha_beaver%20*%20_t)%0A%0A%20%20%20%20def%20_back_within_5pc(N_curve)%3A%0A%20%20%20%20%20%20%20%20_ok%20%3D%20np.abs(N_curve%20-%20M_beaver)%20%3C%3D%200.05%20*%20M_beaver%0A%20%20%20%20%20%20%20%20_bad%20%3D%20np.where(~_ok)%5B0%5D%0A%20%20%20%20%20%20%20%20return%200.0%20if%20len(_bad)%20%3D%3D%200%20else%20_t%5Bmin(_bad%5B-1%5D%20%2B%201%2C%20len(_t)%20-%201)%5D%0A%0A%20%20%20%20_fig_s%2C%20(_axt%2C%20_axr)%20%3D%20plt.subplots(1%2C%202%2C%20figsize%3D(13%2C%204.6)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20gridspec_kw%3D%7B%22width_ratios%22%3A%20%5B1%2C%201.15%5D%7D)%0A%20%20%20%20_N_grid%20%3D%20np.linspace(0%2C%203600%2C%20400)%0A%20%20%20%20_axt.plot(_N_grid%2C%20beaver_rate(0%2C%20_N_grid)%2C%20color%3D%22%23555%22%2C%20linewidth%3D2%2C%20label%3Dr%22%24f(N)%24%22)%0A%20%20%20%20_axt.plot(_N_grid%2C%20-alpha_beaver%20*%20(_N_grid%20-%20M_beaver)%2C%20%22--%22%2C%20color%3D%22%23e67e22%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20linewidth%3D2%2C%20label%3Dr%22tangent%20at%20%24M%24%3A%20%24-%5Calpha(N%20-%20M)%24%22)%0A%20%20%20%20_axt.axhline(0%2C%20color%3D%22black%22%2C%20linewidth%3D1)%0A%20%20%20%20_axt.plot(M_beaver%2C%200%2C%20%22o%22%2C%20color%3D%22black%22%2C%20markersize%3D10%2C%20zorder%3D6)%0A%20%20%20%20_axt.plot(_N_start%2C%20beaver_rate(0%2C%20_N_start)%2C%20%22o%22%2C%20color%3D%22%231a5276%22%2C%20markersize%3D10%2C%20zorder%3D6)%0A%20%20%20%20_axt.plot(_N_start%2C%20-alpha_beaver%20*%20(_N_start%20-%20M_beaver)%2C%20%22o%22%2C%20color%3D%22%23e67e22%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20markersize%3D10%2C%20zorder%3D6)%0A%20%20%20%20_axt.axvline(_N_start%2C%20color%3D%22%231a5276%22%2C%20linewidth%3D1%2C%20alpha%3D0.5)%0A%20%20%20%20_axt.set_xlim(0%2C%203600)%0A%20%20%20%20_axt.set_ylim(-200%2C%20750)%0A%20%20%20%20_axt.set_xlabel(r%22%24N%24%22%2C%20fontsize%3D12)%0A%20%20%20%20_axt.set_ylabel(r%22%24dN%2Fdt%24%22%2C%20fontsize%3D12)%0A%20%20%20%20_axt.set_title(f%22just%20after%20the%20flood%3A%20N%20%3D%20%7B_N_start%3A.0f%7D%22%2C%20fontsize%3D12)%0A%20%20%20%20_axt.legend(fontsize%3D10%2C%20loc%3D%22upper%20left%22)%0A%20%20%20%20_axt.grid(True%2C%20alpha%3D0.3)%0A%0A%20%20%20%20_axr.axhspan(0.95%20*%20M_beaver%2C%201.05%20*%20M_beaver%2C%20color%3D%22%231e8449%22%2C%20alpha%3D0.12)%0A%20%20%20%20_axr.plot(_t%2C%20_N_full%2C%20color%3D%22%231a5276%22%2C%20linewidth%3D2.5%2C%20label%3D%22full%20model%20(5.4)%22)%0A%20%20%20%20_axr.plot(_t%2C%20_N_lin%2C%20%22--%22%2C%20color%3D%22%23e67e22%22%2C%20linewidth%3D2.2%2C%20label%3D%22linearisation%20(5.7)%22)%0A%20%20%20%20_axr.axhline(M_beaver%2C%20color%3D%22grey%22%2C%20linestyle%3D%22%3A%22%2C%20linewidth%3D1)%0A%20%20%20%20_axr.set_xlim(0%2C%2025)%0A%20%20%20%20_axr.set_ylim(0%2C%203300)%0A%20%20%20%20_axr.set_xlabel(%22years%20after%20the%20flood%22%2C%20fontsize%3D12)%0A%20%20%20%20_axr.set_ylabel(r%22%24N%24%22%2C%20fontsize%3D12)%0A%20%20%20%20_axr.set_title(f%22back%20within%205%25%20of%20M%20(green)%3A%20full%20%7B_back_within_5pc(_N_full)%3A.1f%7D%20yr%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22linearised%20%7B_back_within_5pc(_N_lin)%3A.1f%7D%20yr%22%2C%20fontsize%3D11)%0A%20%20%20%20_axr.legend(fontsize%3D10%2C%20loc%3D%22lower%20right%22)%0A%20%20%20%20_axr.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20_fig_s.tight_layout()%0A%20%20%20%20mo.vstack(%5Bflood_slider%2C%20_fig_s%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20What%20to%20notice%0A%0A%20%20%20%20-%20For%20a%20small%20flood%20(5%E2%80%9320%25)%20the%20two%20curves%20almost%20coincide%3A%20close%20to%20%24M%24%20the%20parabola%20and%20its%20tangent%20line%20are%20nearly%20the%20same%2C%20so%20the%20linearisation%20is%20a%20good%20model.%0A%20%20%20%20-%20For%20a%20big%20flood%20the%20linearisation%20is%20far%20too%20optimistic.%20Look%20at%20the%20left%20plot%3A%20below%20%24M%24%20the%20tangent%20line%20sits%20*above*%20the%20parabola%2C%20so%20it%20overestimates%20how%20fast%20the%20beavers%20come%20back%2C%20and%20the%20further%20from%20%24M%24%2C%20the%20bigger%20the%20error.%20After%20an%2080%25%20flood%20the%20linearisation%20says%20about%2010%20years%3B%20the%20full%20model%20says%20about%2017.%0A%20%20%20%20-%20After%20a%20big%20flood%20the%20population%20is%20small%20compared%20with%20%24M%24%2C%20so%20for%20a%20while%20it%20grows%20like%20the%20*other*%20linearisation%2C%20the%20one%20at%200%3A%20exponential%20growth%20at%20rate%20%24%5Calpha%24.%20A%20population%20knocked%20far%20down%20behaves%20like%20the%20early%20Tay%20beavers.%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20-%20A%20function%20packages%20a%20formula%3A%20%60def%60%2C%20then%20%60return%60.%20A%20cell%20shows%20the%20value%20of%20its%20last%20line.%20Arguments%20go%20in%20by%20position%2C%20so%20their%20order%20matters.%0A%20%20%20%20-%20From%20two%20surveys%20and%20the%20exponential%20model%20(5.2)%2C%20%24%5Calpha%20%3D%20%5Cln(N_%5Ctext%7Bend%7D%2FN_%5Ctext%7Bstart%7D)%2F%5Ctext%7Byears%7D%24%3A%20about%200.26%20per%20year%2C%20the%20same%20as%20NatureScot's%2030%25%20a%20year.%0A%20%20%20%20-%20The%20logistic%20model%20(5.4)%20is%20one%20line%20of%20code.%20Following%20the%20arrows%20reproduces%20the%20formula%20(5.5).%0A%20%20%20%20-%20The%20three%20surveys%20fit%20a%20wide%20range%20of%20carrying%20capacities%20%24M%24%2C%20and%20those%20%24M%24%20disagree%20a%20lot%20about%202025.%20The%202025%20survey%20will%20narrow%20it%20down.%0A%20%20%20%20-%20NatureScot's%202026%20report%20says%20the%20growth%20has%20slowed%2C%20as%20the%20logistic%20model%20predicts%2C%20but%20not%20by%20how%20much.%0A%20%20%20%20-%20The%20phase%20portrait%20shows%20where%20the%20population%20goes%20without%20solving%20anything%3B%20the%20sign%20of%20%24f'%24%20at%20an%20equilibrium%20decides%20whether%20it%20is%20stable%20(5.7).%0A%0A%20%20%20%20**In%20the%20lab%3A**%20you%20advise%20NatureScot%20on%20how%20many%20beavers%20it%20can%20safely%20remove%20each%20year.%20After%20some%20warm-ups%20that%20follow%20this%20lecture%20(including%20your%20own%20forecast%20for%20the%202025%20survey)%2C%20you%20add%20the%20real%20removals%20under%20licence%20to%20the%20model%2C%20which%20is%20where%20next%20week's%20lectures%20go%20(harvesting%2C%20Section%205.7).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20References%0A%0A%20%20%20%20%5B1%5D%20Scottish%20Wildlife%20Trust%2C%20%5B*Policy%20briefing%3A%20Beaver%20conservation%20and%20conflict*%5D(https%3A%2F%2Fscottishwildlifetrust.org.uk%2Fwp-content%2Fuploads%2F2025%2F01%2FScottish-Wildlife-Trust_Policy-Briefing_Beaver-conservation-and-conflict_December-2024.pdf)%20(December%202024).%0A%0A%20%20%20%20%5B2%5D%20R.%20Campbell%2C%20A.%20Harrington%2C%20A.%20Ross%20and%20L.%20Harrington%2C%20%5B*Distribution%2C%20population%20assessment%20and%20activities%20of%20beavers%20in%20Tayside*%5D(https%3A%2F%2Fwww.nature.scot%2Fnaturescot-commissioned-report-540-distribution-population-assessment-and-activities-beavers-tayside)%2C%20Scottish%20Natural%20Heritage%20Commissioned%20Report%20540%20(2012)%3A%2038%E2%80%9339%20family%20groups%2C%20about%20146%20beavers%20(106%E2%80%93187)%2C%20at%203.8%20beavers%20per%20group.%0A%0A%20%20%20%20%5B3%5D%20%5B*Survey%20of%20the%20Tayside%20area%20beaver%20population%202017%E2%80%932018*%5D(https%3A%2F%2Fwww.nature.scot%2Fdoc%2Fnaturescot-research-report-1013-survey-tayside-area-beaver-population-2017-2018)%2C%20NatureScot%20Research%20Report%201013%3A%20114%20territories%2C%20about%20433%20beavers%20(319%E2%80%93547).%0A%0A%20%20%20%20%5B4%5D%20R.%20Campbell-Palmer%20et%20al.%2C%20%5B*Survey%20of%20the%20Tayside%20area%20beaver%20population%202020%E2%80%932021*%5D(https%3A%2F%2Fwww.nature.scot%2Fdoc%2Fnaturescot-research-report-1274-survey-tayside-area-beaver-population-2020-2021)%2C%20NatureScot%20Research%20Report%201274%3A%20251%20territories%2C%20about%20954%20beavers%20(602%E2%80%931381).%0A%0A%20%20%20%20%5B5%5D%20%5B*Beaver%20Management%20Report%202025%2F26*%5D(https%3A%2F%2Fwww.nature.scot%2Fdoc%2Fbeaver-management-report-202526)%2C%20NatureScot%3A%20the%202025%20survey%20of%20Tayside%20and%20surrounding%20catchments%20is%20complete%20and%20its%20report%20is%20being%20finalised%3B%20the%20population%20is%20still%20increasing%2C%20but%20not%20at%20the%2030%25%20a%20year%20previously%20reported%2C%20and%20its%20growth%20appears%20to%20follow%20a%20natural%20curve.%0A%0A%20%20%20%20%5B6%5D%20%5B*Beaver%20Management%20Report%20for%202020*%5D(https%3A%2F%2Fwww.nature.scot%2Fdoc%2Fbeaver-management-report-2020)%2C%20NatureScot.%0A%0A%20%20%20%20%5B7%5D%20NatureScot%2C%20%5B*Living%20with%20beavers*%5D(https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBmDlnkIscLo)%20(video%2C%20February%202026).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
e449ec04d7ed6074e2a4c21a60468044