import%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20app_title%3D%22Computational%20Quiz%20%E2%80%94%20Practice%22)%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%20Computational%20Quiz%20%E2%80%94%20Practice%0A%0A%20%20%20%20**MATH4120%20%E2%80%94%20Mathematical%20Modelling%20and%20Programming**%20Lancaster%20University%2C%202026%E2%80%9327%0A%0A%20%20%20%20---%0A%0A%20%20%20%20**This%20is%20scratch%20space%2C%20not%20the%20submission.**%20Write%20your%20%60riemann_left_sum%60%20and%20%60trapezoidal_rule%60%20here%2C%20run%20the%20check%20below%2C%20and%20once%20both%20say%20%22matches%22%2C%20copy%20your%20two%20function%20definitions%20into%20the%20Moodle%20quiz%20%E2%80%94%20that's%20the%20actual%20submission%2C%20not%20this%20notebook.%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%20Write%20your%20functions%20here%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20riemann_left_sum(f%2C%20a%2C%20b%2C%20n)%3A%0A%20%20%20%20return%200.0%20%20%20%20%23%20%E2%86%90%20write%20your%20implementation%20here%0A%0A%0A%40app.function%0Adef%20trapezoidal_rule(f%2C%20a%2C%20b%2C%20n)%3A%0A%20%20%20%20return%200.0%20%20%20%20%23%20%E2%86%90%20write%20your%20implementation%20here%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%20Check%20against%20the%20worked%20example%0A%0A%20%20%20%20This%20is%20the%20same%20check%20from%20the%20instructions%3A%20for%20%24f(x)%20%3D%20x%5E2%24%20on%20%24%5B0%2C%201%5D%24%20with%20%24n%20%3D%204%24%2C%20a%20correct%20implementation%20gives%20%24R_4%20%3D%200.21875%24%20and%20%24T_4%20%3D%200.34375%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20f_check(x)%3A%0A%20%20%20%20return%20x%20**%202%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20riemann_expected%20%3D%200.21875%0A%20%20%20%20trapezoidal_expected%20%3D%200.34375%0A%0A%20%20%20%20riemann_got%20%3D%20riemann_left_sum(f_check%2C%200.0%2C%201.0%2C%204)%0A%20%20%20%20trapezoidal_got%20%3D%20trapezoidal_rule(f_check%2C%200.0%2C%201.0%2C%204)%0A%0A%20%20%20%20riemann_ok%20%3D%20abs(riemann_got%20-%20riemann_expected)%20%3C%201e-9%0A%20%20%20%20trapezoidal_ok%20%3D%20abs(trapezoidal_got%20-%20trapezoidal_expected)%20%3C%201e-9%0A%20%20%20%20return%20riemann_got%2C%20riemann_ok%2C%20trapezoidal_got%2C%20trapezoidal_ok%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20riemann_got%2C%20riemann_ok%2C%20trapezoidal_got%2C%20trapezoidal_ok)%3A%0A%20%20%20%20riemann_line%20%3D%20f%22riemann_left_sum%3A%20got%20%7Briemann_got%7D%20%E2%80%94%20%7B'matches%20%E2%9C%93'%20if%20riemann_ok%20else%20'does%20not%20match%20yet%20%E2%9C%97'%7D%22%0A%20%20%20%20trapezoidal_line%20%3D%20f%22trapezoidal_rule%3A%20got%20%7Btrapezoidal_got%7D%20%E2%80%94%20%7B'matches%20%E2%9C%93'%20if%20trapezoidal_ok%20else%20'does%20not%20match%20yet%20%E2%9C%97'%7D%22%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%60%60%60%0A%20%20%20%20%7Briemann_line%7D%0A%20%20%20%20%7Btrapezoidal_line%7D%0A%20%20%20%20%60%60%60%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
b2bfb00ba00bc3c91fe051d3f529dd61