{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":975,"title":"Gauss Eliminate 2-by-2 example","description":"Use forward elimination to make the coefficient matrix, A, an upper triangular matrix, and then solve using back substitution, for a sample 2-by-2 system.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 348.5px 8px; transform-origin: 348.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eUse forward elimination to make the coefficient matrix, A, an upper triangular matrix, and then solve using back substitution, for a sample 2-by-2 system.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [Ab,x] = GaussEliminate2eqs(A,b)\r\n% A is 2-by-2 system coefficient matrix of the linear system\r\n% b is the 2-by-1 right-hand-side column vector\r\n% Ab is the 2-by-3 Augmented matrix of [A,b] after forward elimination\r\n% x  is the 2-by-1 solution vector\r\n\r\nend","test_suite":"%%\r\nA = [3 2; -1, 2];\r\nb = [18; 2];\r\n[Ab,x]=GaussEliminate2eqs(A,b);\r\nAb_correct = [A,b];\r\nAb_correct(2,:) = [0 8/3 8];\r\nx_correct = [4; 3];\r\nassert(isequal(Ab,Ab_correct))\r\nassert(isequal(x, x_correct))\r\n\r\n%%\r\nA = [3 6; -2 -3];\r\nb = [9;12];\r\n[Ab,x]=GaussEliminate2eqs(A,b);\r\nAb_correct = [3 6 9;-1 -1 15];\r\nx_correct = [-33;18];\r\nassert(isequal(Ab,Ab_correct))\r\nassert(isequal(x, x_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":279,"edited_by":223089,"edited_at":"2022-12-04T08:25:24.000Z","deleted_by":null,"deleted_at":null,"solvers_count":126,"test_suite_updated_at":"2022-12-04T08:25:24.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-08T05:33:17.000Z","updated_at":"2026-03-11T11:45:42.000Z","published_at":"2012-10-08T05:33:17.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUse forward elimination to make the coefficient matrix, A, an upper triangular matrix, and then solve using back substitution, for a sample 2-by-2 system.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1846,"title":"Free Fall analytical solution (Chapra 2012 textbook Example 1.1)","description":"Analytical solution to bungee jumper problem.\r\n\r\nGiven time series as a vector, parameters mass and drag coefficient, and gravity coefficient, compute values of bungee jumper velocity (downward speed) at given times. Assume input values are in consistent units.\r\n\r\n*Problem Statement* (Chapra, page 7):  A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon. Use Eq. (1.9) to compute velocity for the first 12 s of free fall. Also determine the terminal velocity that will be attained for an infinitely long cord (or alternatively, the jumpmaster is having a particularly bad day!). Use a drag coefficient of 0.25 kg/m.","description_html":"\u003cp\u003eAnalytical solution to bungee jumper problem.\u003c/p\u003e\u003cp\u003eGiven time series as a vector, parameters mass and drag coefficient, and gravity coefficient, compute values of bungee jumper velocity (downward speed) at given times. Assume input values are in consistent units.\u003c/p\u003e\u003cp\u003e\u003cb\u003eProblem Statement\u003c/b\u003e (Chapra, page 7):  A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon. Use Eq. (1.9) to compute velocity for the first 12 s of free fall. Also determine the terminal velocity that will be attained for an infinitely long cord (or alternatively, the jumpmaster is having a particularly bad day!). Use a drag coefficient of 0.25 kg/m.\u003c/p\u003e","function_template":"function v = Chapra_Example_1p1_velocity(t,m,c_d,g)\r\n% Input\r\n% t:    vector of time values (seconds) at which velocity is computed\r\n% m:    mass (kg) of falling bungee jumper\r\n% c_d:  drag coefficient of falling bungee jumper\r\n% g:    gravitational instant (m/s^2)\r\n%\r\n% Output\r\n% v:    velocity vector\r\n  v = t;\r\nend","test_suite":"%% AOE 2074 Week 1 -- Cody Example\r\n%  Chapra Example 1.1\r\n%  Analytical Solution to the Bungee Jumper Problem\r\n\r\n% Initialize state variable, time (t), parameters (p), and right-side force (f)\r\n% Time, t, is a vector of values taken from the table on page 8 of Chapra's textbook.\r\nt = 0:2:12; % seconds\r\n\r\n% Parameters are the bungee jumper's mass (m) and drag coefficient (c_d)\r\nm   = 68.1; % kg\r\nc_d = 0.25; % kg/m\r\n\r\n% Right-hand-side force is the gravitational force with gravitational constant (g)\r\ng = 9.81;   % m/s^2\r\n\r\n% Compute analytical solution for velocity (downward speed) at given values of time.\r\nv = Chapra_Example_1p1_velocity( t, m, c_d, g );\r\n\r\n% Check error against textbook solution given in table on page 8.\r\nVelocity = [0\r\n\t18.7292\r\n\t33.1118\r\n\t42.0762\r\n\t46.9575\r\n\t49.4214\r\n\t50.6175];\r\nassert(norm(Velocity-v(:),inf)\u003c1e-4)\r\n\r\n%% Steady-state solution\r\nv = Chapra_Example_1p1_velocity( inf, 68.1, 0.25, 9.81 );\r\nassert(abs(v-51.6938)\u003c1e-4)\r\n\r\n%% Chapra Example 1.1 for t=30\r\nv = Chapra_Example_1p1_velocity( 30, 68.1, 0.25, 9.81 );\r\nassert(abs(v-51.6926)\u003c1e-4)\r\n\r\n%% Cheating check\r\nassert(isempty(regexp(fileread('Chapra_Example_1p1_velocity.m'),'assert.m','once')))","published":true,"deleted":false,"likes_count":1,"comments_count":6,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-25T01:43:42.000Z","updated_at":"2026-03-04T14:17:32.000Z","published_at":"2013-08-25T01:47:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnalytical solution to bungee jumper problem.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven time series as a vector, parameters mass and drag coefficient, and gravity coefficient, compute values of bungee jumper velocity (downward speed) at given times. Assume input values are in consistent units.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem Statement\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (Chapra, page 7): A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon. Use Eq. (1.9) to compute velocity for the first 12 s of free fall. Also determine the terminal velocity that will be attained for an infinitely long cord (or alternatively, the jumpmaster is having a particularly bad day!). Use a drag coefficient of 0.25 kg/m.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1890,"title":"Fixed-Point Iteration","description":"Perform fixed-point iteration to estimate the root of a nonlinear equation.","description_html":"\u003cp\u003ePerform fixed-point iteration to estimate the root of a nonlinear equation.\u003c/p\u003e","function_template":"function x = fixed_point(g,x0,maxit)\r\n%% Input\r\n%  g:     function handle to root equation such that x=g(x) (handle)\r\n%  x0:    initial guess for fixed-point, x (scalar)\r\n%  maxit: maximum number of fixed-point iterations (scalar integer)\r\n%\r\n%% Output\r\n%  x:     estimate\r\n   x = x0;\r\nend","test_suite":"%%\r\nx_fixed_point = fixed_point(@(x) 2./(2*x+1),0,5)\r\nassert(abs(0.8923-x_fixed_point)\u003c1e-4)\r\n%%\r\nx_fixed_point = fixed_point(@(x) 2./(2*x+1),0,20)\r\nassert(abs(0.7807-x_fixed_point)\u003c1e-4)\r\n%%\r\nx_fixed_point = fixed_point(@(x) exp(-x),0,2)\r\nassert(abs(0.3679-x_fixed_point)\u003c1e-4)\r\n%%\r\nx_fixed_point = fixed_point(@(x) exp(-x),0,10)\r\nassert(abs(0.5649-x_fixed_point)\u003c1e-4)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-09-24T18:48:50.000Z","updated_at":"2026-03-02T14:20:41.000Z","published_at":"2013-09-24T18:48:50.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePerform fixed-point iteration to estimate the root of a nonlinear equation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":973,"title":"Partial pivoting for Gauss Elimination","description":"Write a function to implement partial pivoting for Gauss elimination, given the pivot element.","description_html":"\u003cp\u003eWrite a function to implement partial pivoting for Gauss elimination, given the pivot element.\u003c/p\u003e","function_template":"function Ab = PartialPivot(A,b,pivot)\r\n% A = m-by-n coefficient matrix\r\n% b = m-by-1 right-hand-side vector\r\n% pivot = pivot row and column\r\n% Ab = m-by-(n+1) Augmented matrix after pivot step\r\n  Ab = \r\nend","test_suite":"%%\r\nA = [0 2; 1 3];\r\nb = [4; 2];\r\nAb = [1 3 2; 0 2 4];\r\nassert(isequal(PartialPivot(A,b,1),Ab))\r\n%%\r\nA = [0 2 3; 4 6 7; 2, -3, 6];\r\nb = [8; -3; 5];\r\nAb = [A([2 1 3],:), b([2 1 3])];\r\nassert(isequal(PartialPivot(A,b,1),Ab))\r\n%%\r\nA = [4 6 7; 0 2 3; 0, -6, 5/2];\r\nb = [-3; 8; 13/2];\r\nAb = [A([1 3 2],:), b([1 3 2])];\r\nassert(isequal(PartialPivot(A,b,2),Ab))\r\n%%\r\nA = [0 2 5; 2 1 1; 3 1 0];\r\nb = [1; 1; 2];\r\nAb = [A([3 2 1],:), b([3 2 1])];\r\nassert(isequal(PartialPivot(A,b,1),Ab))\r\n%%\r\nA = eye(4);\r\nb = ones(4,1);\r\nassert(isequal(PartialPivot(A,b,3),[A,b]))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2012-10-10T03:30:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-08T00:42:34.000Z","updated_at":"2025-06-08T19:31:51.000Z","published_at":"2012-10-08T01:51:50.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to implement partial pivoting for Gauss elimination, given the pivot element.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":965,"title":"False position (linear interpolation) method of finding a root.","description":"Test the false position algorithm described in Chapter 5 of Steven C. Chapra's textbook, Applied Numerical Methods with MATLAB for Engineers and Scientists. The first test case uses the following problem on the interval [1 3].\r\nf(x)=x^2-4=0\r\nThe first test will be a single iteration of false position. Other tests for varying termination criteria, intervals, and other functions will be added later.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 124.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 62.2167px; transform-origin: 407px 62.2167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 275.5px 8px; transform-origin: 275.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTest the false position algorithm described in Chapter 5 of Steven C. Chapra's textbook,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 98.5px 8px; transform-origin: 98.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 211px 8px; transform-origin: 211px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. The first test case uses the following problem on the interval [1 3].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 48px 8.5px; tab-size: 4; transform-origin: 48px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ef(x)=x^2-4=0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 368px 8px; transform-origin: 368px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe first test will be a single iteration of false position. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function root = false_position(func,x_lower,x_upper,es,maxiter)\r\n% falsepos: root location of zeroes of a function\r\n%   root=false_position(func,x_lower,x_uupper,es,maxit,p1,p2,...):\r\n%      uses false position to find the root of func\r\n% input:\r\n%   func = name of function \r\n%   x_lower, x_upper = lower and upper guesses that bracket the root\r\n%   es = desired relative error (default = 0.0001%) stopping criterion\r\n%   maxiter = maximum allowable iterations (default = 50)\r\n%   p1,p2,... = additional parameters used by function\r\n% output:\r\n%   root = real root\r\n  root = x;\r\nend","test_suite":"%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 3;\r\nes = 0;\r\nmaxit=1;\r\ny_correct = 1.75;\r\nassert(isequal(false_position(f,x_lower,x_upper,es,maxit),y_correct))\r\n\r\n%%\r\nf=@(x) 2*x-5;\r\nx_lower = 1;\r\nx_upper = 5;\r\nes = 0;\r\nmaxit=5;\r\ny_correct = 2.5;\r\nassert(isequal(false_position(f,x_lower,x_upper,es,maxit),y_correct))\r\n\r\n%%\r\nf=@(x) sind(3*x);\r\nx_lower = -90;\r\nx_upper = 90;\r\nes = 0;\r\nmaxit=3;\r\ny_correct = 0;\r\nassert(isequal(false_position(f,x_lower,x_upper,es,maxit),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":7,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2022-01-05T16:37:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-02T04:09:49.000Z","updated_at":"2026-03-22T12:15:04.000Z","published_at":"2012-10-02T04:13:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the false position algorithm described in Chapter 5 of Steven C. Chapra's textbook,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The first test case uses the following problem on the interval [1 3].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[f(x)=x^2-4=0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first test will be a single iteration of false position. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":974,"title":"Forward Elimination for Gauss Elimination","description":"Perform forward elimination for a given pivot column in the augmented matrix, Ab=[A,b]","description_html":"\u003cp\u003ePerform forward elimination for a given pivot column in the augmented matrix, Ab=[A,b]\u003c/p\u003e","function_template":"function Ab = ForwardEliminate(Ab,pivot)\r\n% Ab = m-by-(n+1) Augmented matrix after pivot step\r\n% pivot = pivot row and column\r\n\r\nend","test_suite":"%%\r\nA = [4 6 7; 0 2 3; 2, -3, 6];\r\nb = [-3; 8; 5];\r\nAb = [A,b];\r\nAb(end,:)=[0, -6, 5/2, 13/2];\r\nassert(isequal(ForwardEliminate([A,b],1),Ab))\r\n%%\r\nA = [4 6 7; 0 2 3; 2, -3, 6];\r\nb = [-3; 8; 5];\r\nAb = [A,b];\r\nAb(end,:)=[0, -6, 5/2, 13/2];\r\nAb2 = Ab;\r\nAb2(3,:) = Ab(3,:) + 3*Ab(2,:);\r\nassert(isequal(ForwardEliminate(Ab,2),Ab2))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-08T03:02:44.000Z","updated_at":"2025-12-07T18:23:27.000Z","published_at":"2012-10-08T03:02:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePerform forward elimination for a given pivot column in the augmented matrix, Ab=[A,b]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1017,"title":"Lagrange Interpolation","description":"Given a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Lagrange interpolation. Output is the interpolated value for a given value of x, as well as the vector of Lagrange polynomial coefficients.","description_html":"\u003cp\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Lagrange interpolation. Output is the interpolated value for a given value of x, as well as the vector of Lagrange polynomial coefficients.\u003c/p\u003e","function_template":"function [y,L] = Lagrange_Interp(X,Y,x)\r\n% X is a vector of independent variable values\r\n% Y is a vector of measurements of dependent variable values\r\n% x is the value of the independent variable to be interpolated\r\n% y is the interpolated value, evaluated at x\r\n% L is a vector of Lagrange polynomial values at x\r\n  y = x;\r\nend","test_suite":"%% Check linear interpolation\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851]*1e-1;\r\nx = 5000;\r\ny = Lagrange_Interp(X,Y,x)\r\ny_correct = 0.73650;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\n%% Check Lagrange polynomial coefficients\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851];\r\nx = 5000;\r\ny_correct = 7.3650;\r\nL_correct = [1, 2]/3;\r\n[y,L] = Lagrange_Interp(X,Y,x)\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(L-L_correct)\u003c1e-3)\r\n%% Check quadratic interpolation\r\nX = [300, 400, 500];\r\nY = [0.616, 0.525, 0.457];\r\nx = 350;\r\n[y,L] = Lagrange_Interp(X,Y,x)\r\ny_correct = 0.567625;\r\nL_correct = [3, 6, -1]/8;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(L-L_correct)\u003c1e-3)\r\n%% Check quadratic interpolation for log\r\nX = [1, 4 6];\r\nY = log(X);\r\nx = 2;\r\n[y,L] = Lagrange_Interp(X,Y,x)\r\ny_correct = 0.5658;\r\nL_correct = [8/15, 2/3, -1/5];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(L-L_correct)\u003c1e-3)","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2012-10-30T18:40:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-30T17:43:01.000Z","updated_at":"2025-06-21T13:59:01.000Z","published_at":"2012-10-30T17:43:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Lagrange interpolation. Output is the interpolated value for a given value of x, as well as the vector of Lagrange polynomial coefficients.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1011,"title":"Newton Interpolation","description":"Given a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Newton interpolation. Output is the interpolated value for a given value of x, as well as the vector of divided differences, b, that are the coefficients of the Newton polynomial.","description_html":"\u003cp\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Newton interpolation. Output is the interpolated value for a given value of x, as well as the vector of divided differences, b, that are the coefficients of the Newton polynomial.\u003c/p\u003e","function_template":"function [y,b] = Newton_Interp(X,Y,x)\r\n% X is a vector of independent variable values\r\n% Y is a vector of measurements of dependent variable values\r\n% x is the value of the independent variable to be interpolated\r\n% y is the interpolated value, evaluated at x\r\n% b is a vector of divided difference coefficients in the Newton polynomial\r\n  y = x;\r\nend","test_suite":"%% Check linear interpolation\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851]*1e-1;\r\nx = 5000;\r\ny = Newton_Interp(X,Y,x)\r\ny_correct = 0.73650;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\n%% Check Newton polynomial coefficients\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851];\r\nx = 5000;\r\ny_correct = 7.3650;\r\nb_correct = [7.5247, -0.00079867];\r\n[y,b] = Newton_Interp(X,Y,x)\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(b-b_correct)\u003c1e-3)\r\n%% Check quadratic interpolation\r\nX = [300, 400, 500];\r\nY = [0.616, 0.525, 0.457];\r\nx = 350;\r\n[y,b] = Newton_Interp(X,Y,x)\r\ny_correct = 0.567625;\r\nb_correct = [0.616, -0.00091, 0.00000115];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(b-b_correct)\u003c1e-3)\r\n%% Check quadratic interpolation for log\r\nX = [1, 4 6];\r\nY = log(X);\r\nx = 2;\r\n[y,b] = Newton_Interp(X,Y,x)\r\ny_correct = 0.5658;\r\nb_correct = [0, 0.4620981, -0.0518731];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(b-b_correct)\u003c1e-3)","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":"2012-10-30T18:36:47.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-30T03:15:39.000Z","updated_at":"2025-12-10T10:32:01.000Z","published_at":"2012-10-30T16:49:49.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Newton interpolation. Output is the interpolated value for a given value of x, as well as the vector of divided differences, b, that are the coefficients of the Newton polynomial.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1031,"title":"Composite Trapezoidal Rule for Numeric Integration","description":"Use the trapezoidal rule to numerically integrate a function, _f(x)_, passed as the first argument, between upper and lower limits of integration, _x=a_ and _x=b_,passed as the second and third arguments, respectively. Use _n_ equal intervals, the optional fourth argument, for composite trapezoidal rule.","description_html":"\u003cp\u003eUse the trapezoidal rule to numerically integrate a function, \u003ci\u003ef(x)\u003c/i\u003e, passed as the first argument, between upper and lower limits of integration, \u003ci\u003ex=a\u003c/i\u003e and \u003ci\u003ex=b\u003c/i\u003e,passed as the second and third arguments, respectively. Use \u003ci\u003en\u003c/i\u003e equal intervals, the optional fourth argument, for composite trapezoidal rule.\u003c/p\u003e","function_template":"function I = trapezoidal_rule(f,a,b,n)\r\n% trap: composite trapezoidal rule quadrature\r\n%   I = trap(f,a,b,n):\r\n%       composite trapezoidal rule\r\n% input:\r\n%   f = name of vectorized function to be integrated\r\n%   a, b = integration limits\r\n%   n = number of segments (default = 100)\r\n% output:\r\n%   I = integral estimate\r\n\r\nend","test_suite":"%% Simple Trapezoidal Rule\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nassert(isequal(trapezoidal_rule(f,a,b,1),5280))\r\n\r\n%% Composite Trapezoidal Rule for 2 intervals\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nassert(isequal(trapezoidal_rule(f,a,b,2),2634))\r\n\r\n%% Composite Trapezoidal Rule for 4 intervals\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nassert(isequal(trapezoidal_rule(f,a,b,4),1516.875))\r\n\r\n%% Exact analytical comparison\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nP=polyint(p);\r\nI_correct=polyval(P,b)-polyval(P,a);\r\nI=trapezoidal_rule(f,a,b);\r\nassert(abs(I-I_correct)\u003c1)\r\n\r\n%% Exact analytical comparison--higher tolerance\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nI = trapezoidal_rule(f,a,b,1000);\r\nP=polyint(p);\r\nI_correct=polyval(P,b)-polyval(P,a);\r\nassert(abs(trapezoidal_rule(f,a,b,1000)-I_correct)\u003c1e-1)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":114,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-11-13T19:14:48.000Z","updated_at":"2026-04-04T10:48:38.000Z","published_at":"2012-11-13T20:00:02.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUse the trapezoidal rule to numerically integrate a function,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef(x)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, passed as the first argument, between upper and lower limits of integration,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex=a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex=b\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,passed as the second and third arguments, respectively. Use\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equal intervals, the optional fourth argument, for composite trapezoidal rule.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":966,"title":"Bisection method of finding a root.","description":"Test the bisection algorithm described in Chapter 5 of Steven C. Chapra's textbook, *Applied Numerical Methods with MATLAB for Engineers and Scientists*. The first test case uses the following problem on the interval [1 3].\r\n\r\n  f(x)=x^2-4=0\r\n\r\nThe first test will be a single iteration of bisection. Other tests for varying termination criteria, intervals, and other functions will be added later.","description_html":"\u003cp\u003eTest the bisection algorithm described in Chapter 5 of Steven C. Chapra's textbook, \u003cb\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/b\u003e. The first test case uses the following problem on the interval [1 3].\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ef(x)=x^2-4=0\r\n\u003c/pre\u003e\u003cp\u003eThe first test will be a single iteration of bisection. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/p\u003e","function_template":"function root = bisection(func,x_lower,x_upper,es,maxiter)\r\n% bisection: root location of zeroes of a function\r\n%   root=bisection(func,x_lower,x_uupper,es,maxit,p1,p2,...):\r\n%      uses bisection to find the root of func\r\n% input:\r\n%   func = name of function \r\n%   x_lower, x_upper = lower and upper guesses that bracket the root\r\n%   es = desired relative error (default = 0.0001%) stopping criterion\r\n%   maxiter = maximum allowable iterations (default = 50)\r\n% output:\r\n%   root = real root\r\n  root = x;\r\nend","test_suite":"%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 3;\r\nes = 0;\r\nmaxit=1;\r\nx_root_correct = 2;\r\nassert(isequal(bisection(f,x_lower,x_upper,es,maxit),x_root_correct))\r\n%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 4;\r\nes = 0;\r\nmaxit=1;\r\nx_root = 2.5;\r\nassert(isequal(bisection(f,x_lower,x_upper,es,maxit),x_root))\r\n%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 4;\r\nx_root = 2.000000476837158;\r\nassert(isequal(bisection(f,x_lower,x_upper),x_root))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":"2013-09-24T18:05:32.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-02T05:07:13.000Z","updated_at":"2025-03-03T06:51:43.000Z","published_at":"2012-10-02T05:07:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the bisection algorithm described in Chapter 5 of Steven C. Chapra's textbook,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The first test case uses the following problem on the interval [1 3].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[f(x)=x^2-4=0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first test will be a single iteration of bisection. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1015,"title":"Polynomial Interpolation","description":"Given a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial. Output is the interpolated value for a given value of x, as well as the condition number of the Vandermonde coefficient matrix.","description_html":"\u003cp\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial. Output is the interpolated value for a given value of x, as well as the condition number of the Vandermonde coefficient matrix.\u003c/p\u003e","function_template":"function [y,c] = Poly_Interp(X,Y,x)\r\n% X is a vector of independent variable values\r\n% Y is a vector of measurements of dependent variable values\r\n% x is the value of the independent variable to be interpolated\r\n% y is the interpolated value, evaluated at x\r\n% c is the condition number of the Vandermonde coefficient matrix\r\n   y = x;\r\nend","test_suite":"%% Check linear interpolation\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851]*1e-1;\r\nx = 5000;\r\ny = Poly_Interp(X,Y,x)\r\ny_correct = 0.73650;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\n%% Check Vandermonde coefficient matrix condition number\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851];\r\nx = 5000;\r\ny_correct = 7.3650;\r\nc_correct = 1.6350e+05;\r\n[y,c] = Poly_Interp(X,Y,x)\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(c-c_correct)\u003c1e2)\r\n%% Check quadratic interpolation\r\nX = [300, 400, 500];\r\nY = [0.616, 0.525, 0.457];\r\nx = 350;\r\n[y,c] = Poly_Interp(X,Y,x)\r\ny_correct = 0.567625;\r\nc_correct = [5.8932e+06];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(c-c_correct)\u003c1e2)\r\n%% Check quadratic interpolation for log\r\nX = [1, 4 6];\r\nY = log(X);\r\nx = 2;\r\n[y,c] = Poly_Interp(X,Y,x)\r\ny_correct = 0.5658;\r\nc_correct = 93.9107;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(c-c_correct)\u003c1e-2)","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2012-10-30T18:33:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-30T16:59:18.000Z","updated_at":"2025-06-01T14:44:47.000Z","published_at":"2012-10-30T17:18:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial. Output is the interpolated value for a given value of x, as well as the condition number of the Vandermonde coefficient matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":975,"title":"Gauss Eliminate 2-by-2 example","description":"Use forward elimination to make the coefficient matrix, A, an upper triangular matrix, and then solve using back substitution, for a sample 2-by-2 system.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 42px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 21px; transform-origin: 407px 21px; vertical-align: baseline; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 348.5px 8px; transform-origin: 348.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eUse forward elimination to make the coefficient matrix, A, an upper triangular matrix, and then solve using back substitution, for a sample 2-by-2 system.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [Ab,x] = GaussEliminate2eqs(A,b)\r\n% A is 2-by-2 system coefficient matrix of the linear system\r\n% b is the 2-by-1 right-hand-side column vector\r\n% Ab is the 2-by-3 Augmented matrix of [A,b] after forward elimination\r\n% x  is the 2-by-1 solution vector\r\n\r\nend","test_suite":"%%\r\nA = [3 2; -1, 2];\r\nb = [18; 2];\r\n[Ab,x]=GaussEliminate2eqs(A,b);\r\nAb_correct = [A,b];\r\nAb_correct(2,:) = [0 8/3 8];\r\nx_correct = [4; 3];\r\nassert(isequal(Ab,Ab_correct))\r\nassert(isequal(x, x_correct))\r\n\r\n%%\r\nA = [3 6; -2 -3];\r\nb = [9;12];\r\n[Ab,x]=GaussEliminate2eqs(A,b);\r\nAb_correct = [3 6 9;-1 -1 15];\r\nx_correct = [-33;18];\r\nassert(isequal(Ab,Ab_correct))\r\nassert(isequal(x, x_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":279,"edited_by":223089,"edited_at":"2022-12-04T08:25:24.000Z","deleted_by":null,"deleted_at":null,"solvers_count":126,"test_suite_updated_at":"2022-12-04T08:25:24.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-08T05:33:17.000Z","updated_at":"2026-03-11T11:45:42.000Z","published_at":"2012-10-08T05:33:17.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUse forward elimination to make the coefficient matrix, A, an upper triangular matrix, and then solve using back substitution, for a sample 2-by-2 system.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1846,"title":"Free Fall analytical solution (Chapra 2012 textbook Example 1.1)","description":"Analytical solution to bungee jumper problem.\r\n\r\nGiven time series as a vector, parameters mass and drag coefficient, and gravity coefficient, compute values of bungee jumper velocity (downward speed) at given times. Assume input values are in consistent units.\r\n\r\n*Problem Statement* (Chapra, page 7):  A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon. Use Eq. (1.9) to compute velocity for the first 12 s of free fall. Also determine the terminal velocity that will be attained for an infinitely long cord (or alternatively, the jumpmaster is having a particularly bad day!). Use a drag coefficient of 0.25 kg/m.","description_html":"\u003cp\u003eAnalytical solution to bungee jumper problem.\u003c/p\u003e\u003cp\u003eGiven time series as a vector, parameters mass and drag coefficient, and gravity coefficient, compute values of bungee jumper velocity (downward speed) at given times. Assume input values are in consistent units.\u003c/p\u003e\u003cp\u003e\u003cb\u003eProblem Statement\u003c/b\u003e (Chapra, page 7):  A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon. Use Eq. (1.9) to compute velocity for the first 12 s of free fall. Also determine the terminal velocity that will be attained for an infinitely long cord (or alternatively, the jumpmaster is having a particularly bad day!). Use a drag coefficient of 0.25 kg/m.\u003c/p\u003e","function_template":"function v = Chapra_Example_1p1_velocity(t,m,c_d,g)\r\n% Input\r\n% t:    vector of time values (seconds) at which velocity is computed\r\n% m:    mass (kg) of falling bungee jumper\r\n% c_d:  drag coefficient of falling bungee jumper\r\n% g:    gravitational instant (m/s^2)\r\n%\r\n% Output\r\n% v:    velocity vector\r\n  v = t;\r\nend","test_suite":"%% AOE 2074 Week 1 -- Cody Example\r\n%  Chapra Example 1.1\r\n%  Analytical Solution to the Bungee Jumper Problem\r\n\r\n% Initialize state variable, time (t), parameters (p), and right-side force (f)\r\n% Time, t, is a vector of values taken from the table on page 8 of Chapra's textbook.\r\nt = 0:2:12; % seconds\r\n\r\n% Parameters are the bungee jumper's mass (m) and drag coefficient (c_d)\r\nm   = 68.1; % kg\r\nc_d = 0.25; % kg/m\r\n\r\n% Right-hand-side force is the gravitational force with gravitational constant (g)\r\ng = 9.81;   % m/s^2\r\n\r\n% Compute analytical solution for velocity (downward speed) at given values of time.\r\nv = Chapra_Example_1p1_velocity( t, m, c_d, g );\r\n\r\n% Check error against textbook solution given in table on page 8.\r\nVelocity = [0\r\n\t18.7292\r\n\t33.1118\r\n\t42.0762\r\n\t46.9575\r\n\t49.4214\r\n\t50.6175];\r\nassert(norm(Velocity-v(:),inf)\u003c1e-4)\r\n\r\n%% Steady-state solution\r\nv = Chapra_Example_1p1_velocity( inf, 68.1, 0.25, 9.81 );\r\nassert(abs(v-51.6938)\u003c1e-4)\r\n\r\n%% Chapra Example 1.1 for t=30\r\nv = Chapra_Example_1p1_velocity( 30, 68.1, 0.25, 9.81 );\r\nassert(abs(v-51.6926)\u003c1e-4)\r\n\r\n%% Cheating check\r\nassert(isempty(regexp(fileread('Chapra_Example_1p1_velocity.m'),'assert.m','once')))","published":true,"deleted":false,"likes_count":1,"comments_count":6,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-25T01:43:42.000Z","updated_at":"2026-03-04T14:17:32.000Z","published_at":"2013-08-25T01:47:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnalytical solution to bungee jumper problem.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven time series as a vector, parameters mass and drag coefficient, and gravity coefficient, compute values of bungee jumper velocity (downward speed) at given times. Assume input values are in consistent units.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eProblem Statement\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (Chapra, page 7): A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon. Use Eq. (1.9) to compute velocity for the first 12 s of free fall. Also determine the terminal velocity that will be attained for an infinitely long cord (or alternatively, the jumpmaster is having a particularly bad day!). Use a drag coefficient of 0.25 kg/m.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1890,"title":"Fixed-Point Iteration","description":"Perform fixed-point iteration to estimate the root of a nonlinear equation.","description_html":"\u003cp\u003ePerform fixed-point iteration to estimate the root of a nonlinear equation.\u003c/p\u003e","function_template":"function x = fixed_point(g,x0,maxit)\r\n%% Input\r\n%  g:     function handle to root equation such that x=g(x) (handle)\r\n%  x0:    initial guess for fixed-point, x (scalar)\r\n%  maxit: maximum number of fixed-point iterations (scalar integer)\r\n%\r\n%% Output\r\n%  x:     estimate\r\n   x = x0;\r\nend","test_suite":"%%\r\nx_fixed_point = fixed_point(@(x) 2./(2*x+1),0,5)\r\nassert(abs(0.8923-x_fixed_point)\u003c1e-4)\r\n%%\r\nx_fixed_point = fixed_point(@(x) 2./(2*x+1),0,20)\r\nassert(abs(0.7807-x_fixed_point)\u003c1e-4)\r\n%%\r\nx_fixed_point = fixed_point(@(x) exp(-x),0,2)\r\nassert(abs(0.3679-x_fixed_point)\u003c1e-4)\r\n%%\r\nx_fixed_point = fixed_point(@(x) exp(-x),0,10)\r\nassert(abs(0.5649-x_fixed_point)\u003c1e-4)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-09-24T18:48:50.000Z","updated_at":"2026-03-02T14:20:41.000Z","published_at":"2013-09-24T18:48:50.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePerform fixed-point iteration to estimate the root of a nonlinear equation.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":973,"title":"Partial pivoting for Gauss Elimination","description":"Write a function to implement partial pivoting for Gauss elimination, given the pivot element.","description_html":"\u003cp\u003eWrite a function to implement partial pivoting for Gauss elimination, given the pivot element.\u003c/p\u003e","function_template":"function Ab = PartialPivot(A,b,pivot)\r\n% A = m-by-n coefficient matrix\r\n% b = m-by-1 right-hand-side vector\r\n% pivot = pivot row and column\r\n% Ab = m-by-(n+1) Augmented matrix after pivot step\r\n  Ab = \r\nend","test_suite":"%%\r\nA = [0 2; 1 3];\r\nb = [4; 2];\r\nAb = [1 3 2; 0 2 4];\r\nassert(isequal(PartialPivot(A,b,1),Ab))\r\n%%\r\nA = [0 2 3; 4 6 7; 2, -3, 6];\r\nb = [8; -3; 5];\r\nAb = [A([2 1 3],:), b([2 1 3])];\r\nassert(isequal(PartialPivot(A,b,1),Ab))\r\n%%\r\nA = [4 6 7; 0 2 3; 0, -6, 5/2];\r\nb = [-3; 8; 13/2];\r\nAb = [A([1 3 2],:), b([1 3 2])];\r\nassert(isequal(PartialPivot(A,b,2),Ab))\r\n%%\r\nA = [0 2 5; 2 1 1; 3 1 0];\r\nb = [1; 1; 2];\r\nAb = [A([3 2 1],:), b([3 2 1])];\r\nassert(isequal(PartialPivot(A,b,1),Ab))\r\n%%\r\nA = eye(4);\r\nb = ones(4,1);\r\nassert(isequal(PartialPivot(A,b,3),[A,b]))","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2012-10-10T03:30:19.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-08T00:42:34.000Z","updated_at":"2025-06-08T19:31:51.000Z","published_at":"2012-10-08T01:51:50.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWrite a function to implement partial pivoting for Gauss elimination, given the pivot element.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":965,"title":"False position (linear interpolation) method of finding a root.","description":"Test the false position algorithm described in Chapter 5 of Steven C. Chapra's textbook, Applied Numerical Methods with MATLAB for Engineers and Scientists. The first test case uses the following problem on the interval [1 3].\r\nf(x)=x^2-4=0\r\nThe first test will be a single iteration of false position. Other tests for varying termination criteria, intervals, and other functions will be added later.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 124.433px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 62.2167px; transform-origin: 407px 62.2167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 275.5px 8px; transform-origin: 275.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eTest the false position algorithm described in Chapter 5 of Steven C. Chapra's textbook,\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 98.5px 8px; transform-origin: 98.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 211px 8px; transform-origin: 211px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. The first test case uses the following problem on the interval [1 3].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 48px 8.5px; tab-size: 4; transform-origin: 48px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ef(x)=x^2-4=0\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 368px 8px; transform-origin: 368px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe first test will be a single iteration of false position. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function root = false_position(func,x_lower,x_upper,es,maxiter)\r\n% falsepos: root location of zeroes of a function\r\n%   root=false_position(func,x_lower,x_uupper,es,maxit,p1,p2,...):\r\n%      uses false position to find the root of func\r\n% input:\r\n%   func = name of function \r\n%   x_lower, x_upper = lower and upper guesses that bracket the root\r\n%   es = desired relative error (default = 0.0001%) stopping criterion\r\n%   maxiter = maximum allowable iterations (default = 50)\r\n%   p1,p2,... = additional parameters used by function\r\n% output:\r\n%   root = real root\r\n  root = x;\r\nend","test_suite":"%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 3;\r\nes = 0;\r\nmaxit=1;\r\ny_correct = 1.75;\r\nassert(isequal(false_position(f,x_lower,x_upper,es,maxit),y_correct))\r\n\r\n%%\r\nf=@(x) 2*x-5;\r\nx_lower = 1;\r\nx_upper = 5;\r\nes = 0;\r\nmaxit=5;\r\ny_correct = 2.5;\r\nassert(isequal(false_position(f,x_lower,x_upper,es,maxit),y_correct))\r\n\r\n%%\r\nf=@(x) sind(3*x);\r\nx_lower = -90;\r\nx_upper = 90;\r\nes = 0;\r\nmaxit=3;\r\ny_correct = 0;\r\nassert(isequal(false_position(f,x_lower,x_upper,es,maxit),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":7,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":"2022-01-05T16:37:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-02T04:09:49.000Z","updated_at":"2026-03-22T12:15:04.000Z","published_at":"2012-10-02T04:13:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the false position algorithm described in Chapter 5 of Steven C. Chapra's textbook,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The first test case uses the following problem on the interval [1 3].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[f(x)=x^2-4=0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first test will be a single iteration of false position. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":974,"title":"Forward Elimination for Gauss Elimination","description":"Perform forward elimination for a given pivot column in the augmented matrix, Ab=[A,b]","description_html":"\u003cp\u003ePerform forward elimination for a given pivot column in the augmented matrix, Ab=[A,b]\u003c/p\u003e","function_template":"function Ab = ForwardEliminate(Ab,pivot)\r\n% Ab = m-by-(n+1) Augmented matrix after pivot step\r\n% pivot = pivot row and column\r\n\r\nend","test_suite":"%%\r\nA = [4 6 7; 0 2 3; 2, -3, 6];\r\nb = [-3; 8; 5];\r\nAb = [A,b];\r\nAb(end,:)=[0, -6, 5/2, 13/2];\r\nassert(isequal(ForwardEliminate([A,b],1),Ab))\r\n%%\r\nA = [4 6 7; 0 2 3; 2, -3, 6];\r\nb = [-3; 8; 5];\r\nAb = [A,b];\r\nAb(end,:)=[0, -6, 5/2, 13/2];\r\nAb2 = Ab;\r\nAb2(3,:) = Ab(3,:) + 3*Ab(2,:);\r\nassert(isequal(ForwardEliminate(Ab,2),Ab2))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":29,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-08T03:02:44.000Z","updated_at":"2025-12-07T18:23:27.000Z","published_at":"2012-10-08T03:02:44.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePerform forward elimination for a given pivot column in the augmented matrix, Ab=[A,b]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1017,"title":"Lagrange Interpolation","description":"Given a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Lagrange interpolation. Output is the interpolated value for a given value of x, as well as the vector of Lagrange polynomial coefficients.","description_html":"\u003cp\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Lagrange interpolation. Output is the interpolated value for a given value of x, as well as the vector of Lagrange polynomial coefficients.\u003c/p\u003e","function_template":"function [y,L] = Lagrange_Interp(X,Y,x)\r\n% X is a vector of independent variable values\r\n% Y is a vector of measurements of dependent variable values\r\n% x is the value of the independent variable to be interpolated\r\n% y is the interpolated value, evaluated at x\r\n% L is a vector of Lagrange polynomial values at x\r\n  y = x;\r\nend","test_suite":"%% Check linear interpolation\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851]*1e-1;\r\nx = 5000;\r\ny = Lagrange_Interp(X,Y,x)\r\ny_correct = 0.73650;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\n%% Check Lagrange polynomial coefficients\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851];\r\nx = 5000;\r\ny_correct = 7.3650;\r\nL_correct = [1, 2]/3;\r\n[y,L] = Lagrange_Interp(X,Y,x)\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(L-L_correct)\u003c1e-3)\r\n%% Check quadratic interpolation\r\nX = [300, 400, 500];\r\nY = [0.616, 0.525, 0.457];\r\nx = 350;\r\n[y,L] = Lagrange_Interp(X,Y,x)\r\ny_correct = 0.567625;\r\nL_correct = [3, 6, -1]/8;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(L-L_correct)\u003c1e-3)\r\n%% Check quadratic interpolation for log\r\nX = [1, 4 6];\r\nY = log(X);\r\nx = 2;\r\n[y,L] = Lagrange_Interp(X,Y,x)\r\ny_correct = 0.5658;\r\nL_correct = [8/15, 2/3, -1/5];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(L-L_correct)\u003c1e-3)","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2012-10-30T18:40:10.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-30T17:43:01.000Z","updated_at":"2025-06-21T13:59:01.000Z","published_at":"2012-10-30T17:43:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Lagrange interpolation. Output is the interpolated value for a given value of x, as well as the vector of Lagrange polynomial coefficients.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1011,"title":"Newton Interpolation","description":"Given a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Newton interpolation. Output is the interpolated value for a given value of x, as well as the vector of divided differences, b, that are the coefficients of the Newton polynomial.","description_html":"\u003cp\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Newton interpolation. Output is the interpolated value for a given value of x, as well as the vector of divided differences, b, that are the coefficients of the Newton polynomial.\u003c/p\u003e","function_template":"function [y,b] = Newton_Interp(X,Y,x)\r\n% X is a vector of independent variable values\r\n% Y is a vector of measurements of dependent variable values\r\n% x is the value of the independent variable to be interpolated\r\n% y is the interpolated value, evaluated at x\r\n% b is a vector of divided difference coefficients in the Newton polynomial\r\n  y = x;\r\nend","test_suite":"%% Check linear interpolation\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851]*1e-1;\r\nx = 5000;\r\ny = Newton_Interp(X,Y,x)\r\ny_correct = 0.73650;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\n%% Check Newton polynomial coefficients\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851];\r\nx = 5000;\r\ny_correct = 7.3650;\r\nb_correct = [7.5247, -0.00079867];\r\n[y,b] = Newton_Interp(X,Y,x)\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(b-b_correct)\u003c1e-3)\r\n%% Check quadratic interpolation\r\nX = [300, 400, 500];\r\nY = [0.616, 0.525, 0.457];\r\nx = 350;\r\n[y,b] = Newton_Interp(X,Y,x)\r\ny_correct = 0.567625;\r\nb_correct = [0.616, -0.00091, 0.00000115];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(b-b_correct)\u003c1e-3)\r\n%% Check quadratic interpolation for log\r\nX = [1, 4 6];\r\nY = log(X);\r\nx = 2;\r\n[y,b] = Newton_Interp(X,Y,x)\r\ny_correct = 0.5658;\r\nb_correct = [0, 0.4620981, -0.0518731];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(b-b_correct)\u003c1e-3)","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":12,"test_suite_updated_at":"2012-10-30T18:36:47.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-30T03:15:39.000Z","updated_at":"2025-12-10T10:32:01.000Z","published_at":"2012-10-30T16:49:49.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial using Newton interpolation. Output is the interpolated value for a given value of x, as well as the vector of divided differences, b, that are the coefficients of the Newton polynomial.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1031,"title":"Composite Trapezoidal Rule for Numeric Integration","description":"Use the trapezoidal rule to numerically integrate a function, _f(x)_, passed as the first argument, between upper and lower limits of integration, _x=a_ and _x=b_,passed as the second and third arguments, respectively. Use _n_ equal intervals, the optional fourth argument, for composite trapezoidal rule.","description_html":"\u003cp\u003eUse the trapezoidal rule to numerically integrate a function, \u003ci\u003ef(x)\u003c/i\u003e, passed as the first argument, between upper and lower limits of integration, \u003ci\u003ex=a\u003c/i\u003e and \u003ci\u003ex=b\u003c/i\u003e,passed as the second and third arguments, respectively. Use \u003ci\u003en\u003c/i\u003e equal intervals, the optional fourth argument, for composite trapezoidal rule.\u003c/p\u003e","function_template":"function I = trapezoidal_rule(f,a,b,n)\r\n% trap: composite trapezoidal rule quadrature\r\n%   I = trap(f,a,b,n):\r\n%       composite trapezoidal rule\r\n% input:\r\n%   f = name of vectorized function to be integrated\r\n%   a, b = integration limits\r\n%   n = number of segments (default = 100)\r\n% output:\r\n%   I = integral estimate\r\n\r\nend","test_suite":"%% Simple Trapezoidal Rule\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nassert(isequal(trapezoidal_rule(f,a,b,1),5280))\r\n\r\n%% Composite Trapezoidal Rule for 2 intervals\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nassert(isequal(trapezoidal_rule(f,a,b,2),2634))\r\n\r\n%% Composite Trapezoidal Rule for 4 intervals\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nassert(isequal(trapezoidal_rule(f,a,b,4),1516.875))\r\n\r\n%% Exact analytical comparison\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nP=polyint(p);\r\nI_correct=polyval(P,b)-polyval(P,a);\r\nI=trapezoidal_rule(f,a,b);\r\nassert(abs(I-I_correct)\u003c1)\r\n\r\n%% Exact analytical comparison--higher tolerance\r\np=[2 0 -4 0 -1 1];\r\na=-2;\r\nb=4;\r\nf = @(x) polyval(p,x);\r\nI = trapezoidal_rule(f,a,b,1000);\r\nP=polyint(p);\r\nI_correct=polyval(P,b)-polyval(P,a);\r\nassert(abs(trapezoidal_rule(f,a,b,1000)-I_correct)\u003c1e-1)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":114,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-11-13T19:14:48.000Z","updated_at":"2026-04-04T10:48:38.000Z","published_at":"2012-11-13T20:00:02.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUse the trapezoidal rule to numerically integrate a function,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ef(x)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, passed as the first argument, between upper and lower limits of integration,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex=a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex=b\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e,passed as the second and third arguments, respectively. Use\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e equal intervals, the optional fourth argument, for composite trapezoidal rule.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":966,"title":"Bisection method of finding a root.","description":"Test the bisection algorithm described in Chapter 5 of Steven C. Chapra's textbook, *Applied Numerical Methods with MATLAB for Engineers and Scientists*. The first test case uses the following problem on the interval [1 3].\r\n\r\n  f(x)=x^2-4=0\r\n\r\nThe first test will be a single iteration of bisection. Other tests for varying termination criteria, intervals, and other functions will be added later.","description_html":"\u003cp\u003eTest the bisection algorithm described in Chapter 5 of Steven C. Chapra's textbook, \u003cb\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/b\u003e. The first test case uses the following problem on the interval [1 3].\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ef(x)=x^2-4=0\r\n\u003c/pre\u003e\u003cp\u003eThe first test will be a single iteration of bisection. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/p\u003e","function_template":"function root = bisection(func,x_lower,x_upper,es,maxiter)\r\n% bisection: root location of zeroes of a function\r\n%   root=bisection(func,x_lower,x_uupper,es,maxit,p1,p2,...):\r\n%      uses bisection to find the root of func\r\n% input:\r\n%   func = name of function \r\n%   x_lower, x_upper = lower and upper guesses that bracket the root\r\n%   es = desired relative error (default = 0.0001%) stopping criterion\r\n%   maxiter = maximum allowable iterations (default = 50)\r\n% output:\r\n%   root = real root\r\n  root = x;\r\nend","test_suite":"%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 3;\r\nes = 0;\r\nmaxit=1;\r\nx_root_correct = 2;\r\nassert(isequal(bisection(f,x_lower,x_upper,es,maxit),x_root_correct))\r\n%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 4;\r\nes = 0;\r\nmaxit=1;\r\nx_root = 2.5;\r\nassert(isequal(bisection(f,x_lower,x_upper,es,maxit),x_root))\r\n%%\r\nf=@(x) x.^2-4;\r\nx_lower = 1;\r\nx_upper = 4;\r\nx_root = 2.000000476837158;\r\nassert(isequal(bisection(f,x_lower,x_upper),x_root))\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":23,"test_suite_updated_at":"2013-09-24T18:05:32.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-02T05:07:13.000Z","updated_at":"2025-03-03T06:51:43.000Z","published_at":"2012-10-02T05:07:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTest the bisection algorithm described in Chapter 5 of Steven C. Chapra's textbook,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eApplied Numerical Methods with MATLAB for Engineers and Scientists\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The first test case uses the following problem on the interval [1 3].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[f(x)=x^2-4=0]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe first test will be a single iteration of bisection. Other tests for varying termination criteria, intervals, and other functions will be added later.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1015,"title":"Polynomial Interpolation","description":"Given a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial. Output is the interpolated value for a given value of x, as well as the condition number of the Vandermonde coefficient matrix.","description_html":"\u003cp\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial. Output is the interpolated value for a given value of x, as well as the condition number of the Vandermonde coefficient matrix.\u003c/p\u003e","function_template":"function [y,c] = Poly_Interp(X,Y,x)\r\n% X is a vector of independent variable values\r\n% Y is a vector of measurements of dependent variable values\r\n% x is the value of the independent variable to be interpolated\r\n% y is the interpolated value, evaluated at x\r\n% c is the condition number of the Vandermonde coefficient matrix\r\n   y = x;\r\nend","test_suite":"%% Check linear interpolation\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851]*1e-1;\r\nx = 5000;\r\ny = Poly_Interp(X,Y,x)\r\ny_correct = 0.73650;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\n%% Check Vandermonde coefficient matrix condition number\r\nX = [4800; 5100];\r\nY = [7.5247; 7.2851];\r\nx = 5000;\r\ny_correct = 7.3650;\r\nc_correct = 1.6350e+05;\r\n[y,c] = Poly_Interp(X,Y,x)\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(c-c_correct)\u003c1e2)\r\n%% Check quadratic interpolation\r\nX = [300, 400, 500];\r\nY = [0.616, 0.525, 0.457];\r\nx = 350;\r\n[y,c] = Poly_Interp(X,Y,x)\r\ny_correct = 0.567625;\r\nc_correct = [5.8932e+06];\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(c-c_correct)\u003c1e2)\r\n%% Check quadratic interpolation for log\r\nX = [1, 4 6];\r\nY = log(X);\r\nx = 2;\r\n[y,c] = Poly_Interp(X,Y,x)\r\ny_correct = 0.5658;\r\nc_correct = 93.9107;\r\nassert(abs(y-y_correct)\u003c1e-4)\r\nassert(norm(c-c_correct)\u003c1e-2)","published":true,"deleted":false,"likes_count":2,"comments_count":4,"created_by":279,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":"2012-10-30T18:33:18.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-10-30T16:59:18.000Z","updated_at":"2025-06-01T14:44:47.000Z","published_at":"2012-10-30T17:18:56.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a set of measurements of dependent variables in a vector, Y, that vary with one independent variable in a vector, X, calculate the interpolating polynomial. Output is the interpolated value for a given value of x, as well as the condition number of the Vandermonde coefficient matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"aoe2074\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"aoe2074\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"aoe2074\"","","\"","aoe2074","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f4a01d55dc0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f4a01d55d20\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f4a01d55460\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f4a01d56040\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f4a01d55fa0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f4a01d55f00\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f4a01d55e60\u003e":"tag:\"aoe2074\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f4a01d55e60\u003e":"tag:\"aoe2074\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"aoe2074\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"aoe2074\"","","\"","aoe2074","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f4a01d55dc0\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f4a01d55d20\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f4a01d55460\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f4a01d56040\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f4a01d55fa0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f4a01d55f00\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f4a01d55e60\u003e":"tag:\"aoe2074\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f4a01d55e60\u003e":"tag:\"aoe2074\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":975,"difficulty_rating":"easy"},{"id":1846,"difficulty_rating":"easy"},{"id":1890,"difficulty_rating":"easy"},{"id":973,"difficulty_rating":"easy"},{"id":965,"difficulty_rating":"easy"},{"id":974,"difficulty_rating":"easy-medium"},{"id":1017,"difficulty_rating":"easy-medium"},{"id":1011,"difficulty_rating":"easy-medium"},{"id":1031,"difficulty_rating":"easy-medium"},{"id":966,"difficulty_rating":"easy-medium"},{"id":1015,"difficulty_rating":"medium"}]}}