{"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":1485,"title":"Method of Common Differences part-1","description":"\r\nUse the method of common differences to output a vector containing the initial values and the nth order difference.\r\n\r\nex \r\n  [ 1 4 9 16 25 36 ] has 1st differences [ 3 5 7 9 11 ] and second differences [2 2 2 2] . Therefore output [1 3 2]  which is the 1st element of the above three vectors. \r\n\r\nThe use of this is that the sequence can be continued by using these differences. \r\n\r\nProblem 9) \r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1484 1484\u003e\r\nNext: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1486 1486\u003e\r\n\r\n","description_html":"\u003cp\u003eUse the method of common differences to output a vector containing the initial values and the nth order difference.\u003c/p\u003e\u003cp\u003eex \r\n  [ 1 4 9 16 25 36 ] has 1st differences [ 3 5 7 9 11 ] and second differences [2 2 2 2] . Therefore output [1 3 2]  which is the 1st element of the above three vectors.\u003c/p\u003e\u003cp\u003eThe use of this is that the sequence can be continued by using these differences.\u003c/p\u003e\u003cp\u003eProblem 9) \r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1484\"\u003e1484\u003c/a\u003e\r\nNext: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1486\"\u003e1486\u003c/a\u003e\u003c/p\u003e","function_template":"function y = seq2commondiff(x)\r\nt=[1];\r\nend","test_suite":"%%\r\nx = [1 4 9 16 25];\r\ny_correct = [1 3 2];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [1 9 29 67 129 221];\r\ny_correct = [1 8 12 6];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [3     4     9    23    51    98   169   269   403   576];\r\ny_correct = [3 1 4 5];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [1 8 27 64 125 216];\r\ny_correct = [1 7 12 6];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [2     0     2     9    22    42];\r\ny_correct = [2 -2 4 1];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx=[1     8    28    67   131   226]\r\ny_correct = [1 7 13 6];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2013-05-01T18:21:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-01T17:52:16.000Z","updated_at":"2025-07-04T10:38:00.000Z","published_at":"2013-05-01T18:21:43.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 method of common differences to output a vector containing the initial values and the nth order difference.\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\u003eex [ 1 4 9 16 25 36 ] has 1st differences [ 3 5 7 9 11 ] and second differences [2 2 2 2] . Therefore output [1 3 2] which is the 1st element of the above three vectors.\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 use of this is that the sequence can be continued by using these differences.\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\u003eProblem 9) Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1484\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1484\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Next:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1486\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1486\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":1486,"title":"Method of Common Differences part-2","description":"\r\nThis is the inverse problem to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1485 Problem 1485\u003e. Problem 1485 illustrates the method of differences takes a sequence and takes successive differences till it hits a constant.  The output was the initial values and the final common difference. This output can be used to regenerate the original sequence. Thus this problem.\r\n\r\nUse the initial value and difference vector in the form output in 1485 and generate first n values of the sequence. \r\n\r\nEx: Consider the vector [1 3 2]. The last value '2' is the second order difference and the previous values are the initial values. This generates the sequence [1 4 9 16 25 36 ... ]\r\n\r\nProblem 10)\r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1485 1485\u003e \r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1496 1496\u003e ","description_html":"\u003cp\u003eThis is the inverse problem to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1485\"\u003eProblem 1485\u003c/a\u003e. Problem 1485 illustrates the method of differences takes a sequence and takes successive differences till it hits a constant.  The output was the initial values and the final common difference. This output can be used to regenerate the original sequence. Thus this problem.\u003c/p\u003e\u003cp\u003eUse the initial value and difference vector in the form output in 1485 and generate first n values of the sequence.\u003c/p\u003e\u003cp\u003eEx: Consider the vector [1 3 2]. The last value '2' is the second order difference and the previous values are the initial values. This generates the sequence [1 4 9 16 25 36 ... ]\u003c/p\u003e\u003cp\u003eProblem 10)\r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1485\"\u003e1485\u003c/a\u003e \r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1496\"\u003e1496\u003c/a\u003e\u003c/p\u003e","function_template":"function y = commondiff2seq(x,n)\r\n  y = [1 2 3];\r\nend","test_suite":"%%\r\nx = [1 3 2];\r\nn=5;\r\ny_correct = [1     4     9    16    25];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6];\r\nn=6;\r\ny_correct = [1     5    15    31    53    81];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [10 -4 4];\r\nn=7;\r\ny_correct = [10 6 6 10 18 30 46];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [100 10 -5];\r\nn=5;\r\ny_correct = [100 110 115 115 110];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [0 -10 4 -2 6];\r\nn=10;\r\ny_correct = [ 0   -10   -16   -20   -18     0    50   154   340   642];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [3 0];\r\nn=4;\r\ny_correct = [3 3 3 3 ];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [6 1];\r\nn=4;\r\ny_correct = [6 7 8 9];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [-10 1 -5 2];\r\nn=10;\r\ny_correct = [-10    -9   -13   -20   -28   -35   -39   -38   -30   -13];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [ 1     3    -1    -2     2     1];\r\nn=10;\r\ny_correct = [ 1     4     6     5     1    -3     0    22    81   202];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [0 0 0];\r\nn=5;\r\ny_correct = [0 0 0 0 0];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-01T18:40:08.000Z","updated_at":"2026-01-02T17:21:44.000Z","published_at":"2013-05-01T18:40:14.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\u003eThis is the inverse problem to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1485\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 1485\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Problem 1485 illustrates the method of differences takes a sequence and takes successive differences till it hits a constant. The output was the initial values and the final common difference. This output can be used to regenerate the original sequence. Thus this 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\u003eUse the initial value and difference vector in the form output in 1485 and generate first n values of the sequence.\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\u003eEx: Consider the vector [1 3 2]. The last value '2' is the second order difference and the previous values are the initial values. This generates the sequence [1 4 9 16 25 36 ... ]\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\u003eProblem 10) Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1485\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1485\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1496\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1496\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":561,"title":"Find the jerk","description":"No, it's not the author of this problem...\r\n\r\nJerk is the rate of change in acceleration over time of an object.  So, if given the position of an object over time in the form of a 1-by-N vector, return the indices i where there is nonzero jerk.  \r\n\r\nSuper rad bonus hint: The signal you need to find the jerk of will be given by the variable sig, created with the commands \r\n\r\n  h = 0.065; % stepsize\r\n  t = -10:h:10;\r\n  sigCoefs = 2*rand(1,3)-1;\r\n  sig = polyval(sigCoefs,t);\r\n  breakPoint = randi(length(sig)-2)+1;\r\n  sig(breakPoint) = (1.01)*sig(breakPoint); % this creates a nonzero jerk\r\n \r\nCheck the signal visually with\r\n\r\n  plot(t,sig,'k.-')\r\n\r\nNow, using just sig, determine breakPoint.\r\n ","description_html":"\u003cp\u003eNo, it's not the author of this problem...\u003c/p\u003e\u003cp\u003eJerk is the rate of change in acceleration over time of an object.  So, if given the position of an object over time in the form of a 1-by-N vector, return the indices i where there is nonzero jerk.\u003c/p\u003e\u003cp\u003eSuper rad bonus hint: The signal you need to find the jerk of will be given by the variable sig, created with the commands\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eh = 0.065; % stepsize\r\nt = -10:h:10;\r\nsigCoefs = 2*rand(1,3)-1;\r\nsig = polyval(sigCoefs,t);\r\nbreakPoint = randi(length(sig)-2)+1;\r\nsig(breakPoint) = (1.01)*sig(breakPoint); % this creates a nonzero jerk\r\n\u003c/pre\u003e\u003cp\u003eCheck the signal visually with\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eplot(t,sig,'k.-')\r\n\u003c/pre\u003e\u003cp\u003eNow, using just sig, determine breakPoint.\u003c/p\u003e","function_template":"function idx = findAJerk(sig)\r\n  idx = find(sig\u003e0);\r\nend","test_suite":"%% \r\n\r\n  h = 0.065; % stepsize\r\n  t = -10:h:10;\r\n\r\nfor tr = 1:1000\r\n  sigCoefs = 2*rand(1,3)-1;\r\n  sig = polyval(sigCoefs,t);\r\n  breakPoint = randi(length(sig)-2)+1;\r\n  sig(breakPoint) = (1.01)*sig(breakPoint);\r\n  assert(any(abs(findAJerk(sig) - breakPoint)\u003c=6)) % extra wide window out of kindness\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":2688,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":"2012-04-07T16:14:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-07T03:32:53.000Z","updated_at":"2026-01-31T12:36:27.000Z","published_at":"2012-04-07T03:37:20.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\u003eNo, it's not the author of this 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\u003eJerk is the rate of change in acceleration over time of an object. So, if given the position of an object over time in the form of a 1-by-N vector, return the indices i where there is nonzero jerk.\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\u003eSuper rad bonus hint: The signal you need to find the jerk of will be given by the variable sig, created with the commands\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[h = 0.065; % stepsize\\nt = -10:h:10;\\nsigCoefs = 2*rand(1,3)-1;\\nsig = polyval(sigCoefs,t);\\nbreakPoint = randi(length(sig)-2)+1;\\nsig(breakPoint) = (1.01)*sig(breakPoint); % this creates a nonzero jerk]]\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\u003eCheck the signal visually with\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[plot(t,sig,'k.-')]]\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\u003eNow, using just sig, determine breakPoint.\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":46053,"title":"Construct finite difference approximations of derivatives","description":"In solving a differential equation with a finite-difference method, one computes derivatives with various combinations of the function's values at chosen grid points. For example, the forward difference formula for the first derivative is\r\n\r\n f' = (f_{j+1} - f_j)/h\r\n\r\nwhere j is the grid index and h is the spacing between points. The systematic approach for deriving such formulas is to \u003chttp://www2.math.umd.edu/~dlevy/classes/amsc466/lecture-notes/differentiation-chap.pdf use Taylor series\u003e. In the example above, one can write\r\n\r\n f_{j+1} = f_j + h f' + h^2 f''/2 + h^3 f'''/6 + ...\r\n\r\nThen solving for f' and neglecting terms of order h^2 and higher gives\r\n\r\n f' = (f_{j+1} - f_j)/h - h f''/2\r\n\r\nBecause the exponent on h in the last term is 1, the method is called a first order method.\r\n\r\nWrite a function that takes the order |n| of the derivative and a vector |terms| indicating the terms to use (based on the number of grid cells away from the point in question) and produces a vector of coefficients, the order of the error term, and the numerical coefficient of the error term. In the above example, |n = 1| and |terms = [1 0]|, and \r\n\r\n coeffs   = [1 -1]\r\n errOrder = 1\r\n errCoeff = -0.5; \r\n","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: 435.55px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 217.775px; transform-origin: 407px 217.775px; 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: 380.183px 7.91667px; transform-origin: 380.183px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn solving a differential equation with a finite-difference method, one computes derivatives with various combinations of the function's values at chosen grid points. For example, the forward difference formula for the first derivative is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 37.5833px; 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 18.7917px; text-align: left; transform-origin: 384px 18.7917px; 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: 13.5917px 7.91667px; transform-origin: 13.5917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-15px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKkAAABLCAYAAAALWaemAAAEa0lEQVR4nO2d3ZHiMBCEOwdnQAJOYCNwBGRABtQl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tc52nOq1Q1p57OE3CNusS8ZqFU31ZcMKtU0cpz2eR0wWlegqU9mEbMqwaOyKzwr+bmYqKCmbMZsyLBZO7bxbGe8HqVrJstncJmFc7nHGBs7KlcDsi2Y8USwcRbvLibl0R7elEVmxm9Yy4K3wnJa6YYNpKVEOvBp4fzzmEo1vPBuwCtVFNpgfPcMbKEdNG/WrMEhkwS7p4a0SbUmijfp1tVBkwVannfFzSm/x7AoIkRy7xPxV+skasBBZ4BLzV0UldtmN/FGRBRsUvRopcy2cFOI/n24yS390Cdu/i5VibzL7iu5Uf4IWI4rEvCvNs/7oDs5QV1/CJ8ri024y1h/lrYuESAp3V+7zN2s4w2yhSjYhhBBCCCGEEEIIIYQQQsTkHzIr3fuGMmo5AAAAAElFTkSuQmCC\" alt=\"f' = (f_{j+1} - f_j})/h\" style=\"width: 84.5px; height: 37.5px;\" width=\"84.5\" height=\"37.5\"\u003e\u003c/span\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: 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: 365.642px 7.91667px; transform-origin: 365.642px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ewhere j is the grid index and h is the spacing between points. The systematic approach for deriving such formulas is to\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www2.math.umd.edu/~dlevy/classes/amsc466/lecture-notes/differentiation-chap.pdf\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003euse Taylor series\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 116.3px 7.91667px; transform-origin: 116.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. In the example above, one can write\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 36.0833px; 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 18.0417px; text-align: left; transform-origin: 384px 18.0417px; 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: 13.5917px 7.91667px; transform-origin: 13.5917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-15px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcUAAABICAYAAACHmO42AAALhklEQVR4nO2dvZHryA6Fj/tsec9UAkpAESgCZTDm85SB/LXkr6faCJSDU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Rs1+3iWfa8rqckw7vCZnRlzbfS2l55xl0MWa+KJ/r6j9B5Ssy0l8zhshu4D+Q3WCWm6VSwUhWrykOotiPpghGNI2drQqry76bALkhzN98XGuaBdWfE1ISIMhlT49vo1Zp1unRPGDd3Y67ZEGZj0UmueglgY9jVONe7xLYE9mhXqHY0Ml76XKOKwRlGLommw3X5shyb2cJY+E1HEvl9QtHC/VJvv24VRAiVhTIdt9fVCsyC1e7v8uTx3IYSYGIbxFCmYDvsKNGYGn9AsULtZwQqtCiHERDDZQ17itLCEpW8fd9c5R0mEQggxAczc1l7itPg0TTiZ85RIKIQQhWF9r+rXpscaRd/z5MkLIUQhWMqk/ap5sPWJQ9h3hCqpUAghCsD9KhnE+aCxG/MAZRSFEKIgMoh1YLsIDRk7X+MphBAiAh+DqEzH8nA/d2xP176EQAghREZuGM9iPKO/ebjIC0su+gye7XqjZCghhMgIC/SvaMowXAfPUXnGNNj2ei6jx3IZlWMIIURGbOPpsUNhumk5o81EPaPdN2QbuDu0lyiEENk4ofE0fA+F6aZnh8YI3tGOwwXy2IUQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCHi+Rc2DzR72nvjXAAAAABJRU5ErkJggg==\" alt=\"f_{j+1} = f_j + hf' + h^2 f''/2 + h^3 f'''/6 + ...\" style=\"width: 226.5px; height: 36px;\" width=\"226.5\" height=\"36\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; 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 10.5px; text-align: left; transform-origin: 384px 10.5px; 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: 51.7333px 7.91667px; transform-origin: 51.7333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThen solving for \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAkCAYAAAAD3IPhAAABNklEQVRYhe2XXbGEMAxGj4c6wAAGVsEqwEEdrINrAQ1IwAMWqgEL3IcmU3Zm2W2ZBnjgPPET2kyS5gtwc3MDQAM8Mu0aKydaIAAj0AMz4L/YLsBk4chDFh/k3sv9DLgP9n/yvq/tiJNNZ1LYn7LZuPFNkPdtbWdevEflF5qiXPsiZlm8y7TXFFaPSicLL+SfjAmjqAziSMi0d2L/qah34Yl18iKlKKye+S+bdcSTVA3dtCelaFg9/1U7Jo1OT9FCXsc1Retlq7EditbLVmM7jIaUoqoFuQdt94tcn4oKXdWesZcRwxGgFI1K9RGgFFXdEnE0Q1W3RBzNUBnIFUdTJi7SX3QEMBmOStFh6vAj7Yj1sf7dUHE8XKXXI4IjHelTektLVOZATE84yxGlIabJc4GecnMp/gGjCl04ApTc8QAAAABJRU5ErkJggg==\" alt=\"f'\" style=\"width: 17.5px; height: 18px;\" width=\"17.5\" height=\"18\"\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: 94.9083px 7.91667px; transform-origin: 94.9083px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and neglecting terms of order \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAnCAYAAAD3h5P5AAABYklEQVRYhe2WYc2DMBCGHw84wAAGUICCOagDHGABDZ8EPMzCNGCB/ehdOFgZa8uWfEmfpFlGcz16974tUChcQwv0MtpfJa2AO/CQ30XGn8x9lQlw5n8DzPIC/TcT1/jd7nGSPDQXtXh9Mt8EnrcpyVU0E3ml0+RDbGCFF4sKJ0W5vcSGqnLKKMEP0hT7IGHXNljtEouT+CQa1pLfEmLvZPhbbbLwXul79LDJOt1UbDE7qPAOCSWOqp5azAqmZT06Z7Yq1h3bU05xRFhV/bkAnTwb8ALqzYtNJsbaMjQ+bp36c8bvaJShC6gLNHnDepOFRlTJJ7O4Y3szWRcke/iIyiw+4ndpS2Zd0L1EZ9Kx7dVeudpbbcmlDLwva0hsl6FimnlVqO13yFJZ1Gz7vSf11PuIG8e9hrXf1mKXVeDsCtV+O5nfOyELXTx0hdp+Txyf4UmcXaE125PtZ9/khUKh8L94Ap3giAaNUZJzAAAAAElFTkSuQmCC\" alt=\"h^2\" style=\"width: 15.5px; height: 19.5px;\" width=\"15.5\" height=\"19.5\"\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: 53.3px 7.91667px; transform-origin: 53.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and higher gives\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 38.5833px; 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 19.2917px; text-align: left; transform-origin: 384px 19.2917px; 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: 13.5917px 7.91667px; transform-origin: 13.5917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-15px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQQAAABNCAYAAABAKBoaAAAHIklEQVR4nO2dzXHjOBCFXw687VEJKAFHoAiUgY97U20Cus9JMag2AuWgDUExKAXvAX5Gi+YfKIL44fuqUFMzI1tgE2g0uhsNQAghhBBCCCGEEEIIIcQqNAA+vv8U05HcRFU0AG4AHgBOAL4AXJL2qAwkN1EdDYAn3KBuAOzhBvYX3KonupHcRJXc4Abx4fvvO/iBvkvVqQKQ3ER1fMAN6mfqjhSG5Caq5Arte+cguYnq2MHveY+J+1ISkpuokk/4ga0973QkN1ENB7jw2AnAHX5gn0zTIP/NluSmCMmGOMIPYA7qO14HtvhNzXI7wflCqOieUILV5qCXnKucmEatcrPPdUvcF5EAuw+WiTidWuVmHaWfifsiEsCwWenm4WmBFkItcmtzhFcI+8R9EQl4wO+DU9PA72FD+XqzhSYW5SS3JaGiu6MuRScm0MBPiPPEnznATZ6pn5/aj094Z9acSfaudRBiHucitxg8oUSrzXKAH9iHkc+2f+Y68rmQY8AN3N6VDq3cV92YckuJPZSlRKsNYkNnS5uHnNxTJ4z9mdwVQky5pcQ6SvlcDZxVI8thA/CU3iPC765ZIcSUW0r4XJT/Hu4ZL/C+hdqiKsIQovU/4BNXbhhfGWtWCDHllhKbV0FlwPdnow9SCBUyZ79IZxoLgQxRq0KILbdU2ISkA1xf7cS3FkKuz7AKNhR2hxNMn4bcwQkyZ8cRsRp/au49B82U56tVIcSWWyrO8Errht95GbSKYrybw/d3co6d0K906L8ZypFgKbvFFRcnOH85B0Pfl9EpU0LKJwdAyAvmy2iH6KyTbUrrC72VoBCWlFtO2INaV7yOb2s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3Bw+4B4x2qYNYlFovWM0BOvwu8JOe1aKsxTB10bTbgxKKxPyUPLtCq00ptC8iFctxR/82jBZ0iDOXN0az0liOh6xE4XBAtkug0wGmQTcPXuo6ZHXZ7UTWK73YBjQ7bVi4wWso8gmFIudwwPgktzkEUggiOXaFAnyZsjNelYWK2sTBKgTl6Yjk0El1hVcGtAZs9EGrVxzGLjkWYjVsDvwJTjnY8JWNPmj1igPzdJa++VmIYOwp1Ct+bwts7UGxPIwyyDoQWWDL4neFHK2yEMtDC0zWl8gCmxjTjiLI+x0X+meUqyOywDoMuyyAVEVxtwDvSlTkRmSDrcHXZbLSf1DEkdqC4M3XUgYiK5h41Hfcub1duCDTAzQFIWUgsmXouLP1H+zglIKORb/PFGUgpStWZ6yGv/Uf3KEowxJcML79OkKKVyTgCH/fRBd7OCVwg7zgS8Dw7hlO2XY1fkYhSCEqxuZ6jDUdPxeiYg4Iux1M1pgQQgghhBBCCCGEEEIIIYQQQgghhBBCWP4HvMwy/Pk8LhMAAAAASUVORK5CYII=\" alt=\"f' = (f_{j+1} - f_j)/h - hf''/2\" style=\"width: 130px; height: 38.5px;\" width=\"130\" height=\"38.5\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; 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 10.5px; text-align: left; transform-origin: 384px 10.5px; 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: 81.3px 7.91667px; transform-origin: 81.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBecause the exponent on \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003eh\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: 191.35px 7.91667px; transform-origin: 191.35px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in the last term is 1, the method is called a first order method.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.5px; 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: 110.717px 7.91667px; transform-origin: 110.717px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the order\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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: 91.7917px 7.91667px; transform-origin: 91.7917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of the derivative and a vector\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; 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: 19.25px 7.91667px; transform-origin: 19.25px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eterms\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: 130.3px 7.91667px; transform-origin: 130.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e indicating the terms to use (based on the number of grid cells away from the point in question) and produces a vector of coefficients, the order of the error term, and the numerical coefficient of the error term. In the above example,\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; 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: 19.25px 7.91667px; transform-origin: 19.25px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003en = 1\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: 13.6167px 7.91667px; transform-origin: 13.6167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; 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: 50.05px 7.91667px; transform-origin: 50.05px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eterms = [1 0]\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: 15.5583px 7.91667px; transform-origin: 15.5583px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; 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 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 69.3px 7.91667px; transform-origin: 69.3px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e coeffs   = [1 -1]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 50.05px 7.91667px; transform-origin: 50.05px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e errOrder = 1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 65.45px 7.91667px; transform-origin: 65.45px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e errCoeff = -0.5;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [coeff,errOrder,errCoeff] = FDderiv(n,terms)\r\n%  n        = order of the derivative sought\r\n%  terms    = grid indices of terms to include\r\n%  coeff    = coefficients of the terms in the formula \r\n%  errOrder = exponent of h in the first non-zero higher-order term\r\n%  errCoeff = coefficient of the first non-zero higher-order term\r\n\r\n  coeff    = ...\r\n  errOrder = ...\r\n  errCoeff = ...\r\nend","test_suite":"%%\r\n%  First-order forward difference for the first derivative\r\nn = 1;\r\nterms = [1 0];\r\ncoeff_correct = [1 -1];\r\nerrOrder_correct = 1;\r\nerrCoeff_correct = -1/2;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  First-order backward difference for the first derivative\r\nn = 1;\r\nterms = [0 -1];\r\ncoeff_correct = [1 -1];\r\nerrOrder_correct = 1;\r\nerrCoeff_correct = 1/2;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the first derivative\r\nn = 1;\r\nterms = [1 -1];\r\ncoeff_correct = [1/2 -1/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/6;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order forward difference for the first derivative\r\nn = 1;\r\nterms = [2 1 0];\r\ncoeff_correct = [-1/2 2 -3/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = 1/3;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order backward difference for the first derivative\r\nn = 1;\r\nterms = [0 -1 -2];\r\ncoeff_correct = [3/2 -2 1/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = 1/3;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Fourth-order centered difference for the first derivative\r\nn = 1;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [-1 8 0 -8 1]/12\r\nerrOrder_correct = 4;\r\nerrCoeff_correct = 1/30;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the second derivative\r\nn = 2;\r\nterms = [1 0 -1];\r\ncoeff_correct = [1 -2 1];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/12;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Fourth-order centered difference for the second derivative\r\nn = 2;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [-1 16 -30 16 -1]/12;\r\nerrOrder_correct = 4;\r\nerrCoeff_correct = 1/90;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the third derivative\r\nn = 3;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [1/2 -1 0 1 -1/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/4;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the fourth derivative\r\nn = 4;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [1 -4 6 -4 1];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/6;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-07-22T03:37:57.000Z","updated_at":"2020-11-15T13:41:30.000Z","published_at":"2020-07-22T05:20:57.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\u003eIn solving a differential equation with a finite-difference method, one computes derivatives with various combinations of the function's values at chosen grid points. For example, the forward difference formula for the first derivative is\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\u003e       \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f' = (f_{j+1} - f_j})/h\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ef\\\\prime=\\\\frac{f_{j+1}-f_j}{h}\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003ewhere j is the grid index and h is the spacing between points. The systematic approach for deriving such formulas is to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www2.math.umd.edu/~dlevy/classes/amsc466/lecture-notes/differentiation-chap.pdf\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euse Taylor series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. In the example above, one can write\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\u003e       \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f_{j+1} = f_j + hf' + h^2 f''/2 + h^3 f'''/6 + ...\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e f_{j+1} = f_j + h f\\\\prime +  \\\\frac{h^2}{2}f\\\\prime\\\\prime +  \\\\frac{h^3}{6}f\\\\prime\\\\prime\\\\prime + \\\\ldots\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003eThen solving for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f'\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e$f\\\\prime$\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e and neglecting terms of order \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"h^2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e$h^2$\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e and higher gives\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\u003e       \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f' = (f_{j+1} - f_j)/h - hf''/2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ef\\\\prime = \\\\frac{f_{j+1} - f_j}{h} - \\\\frac{h}{2}f\\\\prime\\\\prime\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003eBecause the exponent on \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"h\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eh\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e in the last term is 1, the method is called a first order method.\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\u003eWrite a function that takes the order\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e of the derivative and a vector\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eterms\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e indicating the terms to use (based on the number of grid cells away from the point in question) and produces a vector of coefficients, the order of the error term, and the numerical coefficient of the error term. In the above example,\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 1\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eterms = [1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\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[ coeffs   = [1 -1]\\n errOrder = 1\\n errCoeff = -0.5;]]\u003e\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":1485,"title":"Method of Common Differences part-1","description":"\r\nUse the method of common differences to output a vector containing the initial values and the nth order difference.\r\n\r\nex \r\n  [ 1 4 9 16 25 36 ] has 1st differences [ 3 5 7 9 11 ] and second differences [2 2 2 2] . Therefore output [1 3 2]  which is the 1st element of the above three vectors. \r\n\r\nThe use of this is that the sequence can be continued by using these differences. \r\n\r\nProblem 9) \r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1484 1484\u003e\r\nNext: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1486 1486\u003e\r\n\r\n","description_html":"\u003cp\u003eUse the method of common differences to output a vector containing the initial values and the nth order difference.\u003c/p\u003e\u003cp\u003eex \r\n  [ 1 4 9 16 25 36 ] has 1st differences [ 3 5 7 9 11 ] and second differences [2 2 2 2] . Therefore output [1 3 2]  which is the 1st element of the above three vectors.\u003c/p\u003e\u003cp\u003eThe use of this is that the sequence can be continued by using these differences.\u003c/p\u003e\u003cp\u003eProblem 9) \r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1484\"\u003e1484\u003c/a\u003e\r\nNext: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1486\"\u003e1486\u003c/a\u003e\u003c/p\u003e","function_template":"function y = seq2commondiff(x)\r\nt=[1];\r\nend","test_suite":"%%\r\nx = [1 4 9 16 25];\r\ny_correct = [1 3 2];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [1 9 29 67 129 221];\r\ny_correct = [1 8 12 6];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [3     4     9    23    51    98   169   269   403   576];\r\ny_correct = [3 1 4 5];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [1 8 27 64 125 216];\r\ny_correct = [1 7 12 6];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx = [2     0     2     9    22    42];\r\ny_correct = [2 -2 4 1];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n%%\r\nx=[1     8    28    67   131   226]\r\ny_correct = [1 7 13 6];\r\nassert(isequal(seq2commondiff(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2013-05-01T18:21:43.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-01T17:52:16.000Z","updated_at":"2025-07-04T10:38:00.000Z","published_at":"2013-05-01T18:21:43.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 method of common differences to output a vector containing the initial values and the nth order difference.\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\u003eex [ 1 4 9 16 25 36 ] has 1st differences [ 3 5 7 9 11 ] and second differences [2 2 2 2] . Therefore output [1 3 2] which is the 1st element of the above three vectors.\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 use of this is that the sequence can be continued by using these differences.\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\u003eProblem 9) Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1484\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1484\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Next:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1486\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1486\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":1486,"title":"Method of Common Differences part-2","description":"\r\nThis is the inverse problem to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1485 Problem 1485\u003e. Problem 1485 illustrates the method of differences takes a sequence and takes successive differences till it hits a constant.  The output was the initial values and the final common difference. This output can be used to regenerate the original sequence. Thus this problem.\r\n\r\nUse the initial value and difference vector in the form output in 1485 and generate first n values of the sequence. \r\n\r\nEx: Consider the vector [1 3 2]. The last value '2' is the second order difference and the previous values are the initial values. This generates the sequence [1 4 9 16 25 36 ... ]\r\n\r\nProblem 10)\r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1485 1485\u003e \r\nPrev: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1496 1496\u003e ","description_html":"\u003cp\u003eThis is the inverse problem to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1485\"\u003eProblem 1485\u003c/a\u003e. Problem 1485 illustrates the method of differences takes a sequence and takes successive differences till it hits a constant.  The output was the initial values and the final common difference. This output can be used to regenerate the original sequence. Thus this problem.\u003c/p\u003e\u003cp\u003eUse the initial value and difference vector in the form output in 1485 and generate first n values of the sequence.\u003c/p\u003e\u003cp\u003eEx: Consider the vector [1 3 2]. The last value '2' is the second order difference and the previous values are the initial values. This generates the sequence [1 4 9 16 25 36 ... ]\u003c/p\u003e\u003cp\u003eProblem 10)\r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1485\"\u003e1485\u003c/a\u003e \r\nPrev: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1496\"\u003e1496\u003c/a\u003e\u003c/p\u003e","function_template":"function y = commondiff2seq(x,n)\r\n  y = [1 2 3];\r\nend","test_suite":"%%\r\nx = [1 3 2];\r\nn=5;\r\ny_correct = [1     4     9    16    25];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6];\r\nn=6;\r\ny_correct = [1     5    15    31    53    81];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [10 -4 4];\r\nn=7;\r\ny_correct = [10 6 6 10 18 30 46];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [100 10 -5];\r\nn=5;\r\ny_correct = [100 110 115 115 110];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [0 -10 4 -2 6];\r\nn=10;\r\ny_correct = [ 0   -10   -16   -20   -18     0    50   154   340   642];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [3 0];\r\nn=4;\r\ny_correct = [3 3 3 3 ];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [6 1];\r\nn=4;\r\ny_correct = [6 7 8 9];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [-10 1 -5 2];\r\nn=10;\r\ny_correct = [-10    -9   -13   -20   -28   -35   -39   -38   -30   -13];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [ 1     3    -1    -2     2     1];\r\nn=10;\r\ny_correct = [ 1     4     6     5     1    -3     0    22    81   202];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n\r\n%%\r\nx = [0 0 0];\r\nn=5;\r\ny_correct = [0 0 0 0 0];\r\nassert(isequal(commondiff2seq(x,n),y_correct))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":25,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-05-01T18:40:08.000Z","updated_at":"2026-01-02T17:21:44.000Z","published_at":"2013-05-01T18:40:14.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\u003eThis is the inverse problem to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1485\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 1485\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Problem 1485 illustrates the method of differences takes a sequence and takes successive differences till it hits a constant. The output was the initial values and the final common difference. This output can be used to regenerate the original sequence. Thus this 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\u003eUse the initial value and difference vector in the form output in 1485 and generate first n values of the sequence.\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\u003eEx: Consider the vector [1 3 2]. The last value '2' is the second order difference and the previous values are the initial values. This generates the sequence [1 4 9 16 25 36 ... ]\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\u003eProblem 10) Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1485\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1485\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Prev:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/1496\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1496\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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":561,"title":"Find the jerk","description":"No, it's not the author of this problem...\r\n\r\nJerk is the rate of change in acceleration over time of an object.  So, if given the position of an object over time in the form of a 1-by-N vector, return the indices i where there is nonzero jerk.  \r\n\r\nSuper rad bonus hint: The signal you need to find the jerk of will be given by the variable sig, created with the commands \r\n\r\n  h = 0.065; % stepsize\r\n  t = -10:h:10;\r\n  sigCoefs = 2*rand(1,3)-1;\r\n  sig = polyval(sigCoefs,t);\r\n  breakPoint = randi(length(sig)-2)+1;\r\n  sig(breakPoint) = (1.01)*sig(breakPoint); % this creates a nonzero jerk\r\n \r\nCheck the signal visually with\r\n\r\n  plot(t,sig,'k.-')\r\n\r\nNow, using just sig, determine breakPoint.\r\n ","description_html":"\u003cp\u003eNo, it's not the author of this problem...\u003c/p\u003e\u003cp\u003eJerk is the rate of change in acceleration over time of an object.  So, if given the position of an object over time in the form of a 1-by-N vector, return the indices i where there is nonzero jerk.\u003c/p\u003e\u003cp\u003eSuper rad bonus hint: The signal you need to find the jerk of will be given by the variable sig, created with the commands\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eh = 0.065; % stepsize\r\nt = -10:h:10;\r\nsigCoefs = 2*rand(1,3)-1;\r\nsig = polyval(sigCoefs,t);\r\nbreakPoint = randi(length(sig)-2)+1;\r\nsig(breakPoint) = (1.01)*sig(breakPoint); % this creates a nonzero jerk\r\n\u003c/pre\u003e\u003cp\u003eCheck the signal visually with\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eplot(t,sig,'k.-')\r\n\u003c/pre\u003e\u003cp\u003eNow, using just sig, determine breakPoint.\u003c/p\u003e","function_template":"function idx = findAJerk(sig)\r\n  idx = find(sig\u003e0);\r\nend","test_suite":"%% \r\n\r\n  h = 0.065; % stepsize\r\n  t = -10:h:10;\r\n\r\nfor tr = 1:1000\r\n  sigCoefs = 2*rand(1,3)-1;\r\n  sig = polyval(sigCoefs,t);\r\n  breakPoint = randi(length(sig)-2)+1;\r\n  sig(breakPoint) = (1.01)*sig(breakPoint);\r\n  assert(any(abs(findAJerk(sig) - breakPoint)\u003c=6)) % extra wide window out of kindness\r\nend\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":2688,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":73,"test_suite_updated_at":"2012-04-07T16:14:29.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-04-07T03:32:53.000Z","updated_at":"2026-01-31T12:36:27.000Z","published_at":"2012-04-07T03:37:20.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\u003eNo, it's not the author of this 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\u003eJerk is the rate of change in acceleration over time of an object. So, if given the position of an object over time in the form of a 1-by-N vector, return the indices i where there is nonzero jerk.\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\u003eSuper rad bonus hint: The signal you need to find the jerk of will be given by the variable sig, created with the commands\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[h = 0.065; % stepsize\\nt = -10:h:10;\\nsigCoefs = 2*rand(1,3)-1;\\nsig = polyval(sigCoefs,t);\\nbreakPoint = randi(length(sig)-2)+1;\\nsig(breakPoint) = (1.01)*sig(breakPoint); % this creates a nonzero jerk]]\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\u003eCheck the signal visually with\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[plot(t,sig,'k.-')]]\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\u003eNow, using just sig, determine breakPoint.\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":46053,"title":"Construct finite difference approximations of derivatives","description":"In solving a differential equation with a finite-difference method, one computes derivatives with various combinations of the function's values at chosen grid points. For example, the forward difference formula for the first derivative is\r\n\r\n f' = (f_{j+1} - f_j)/h\r\n\r\nwhere j is the grid index and h is the spacing between points. The systematic approach for deriving such formulas is to \u003chttp://www2.math.umd.edu/~dlevy/classes/amsc466/lecture-notes/differentiation-chap.pdf use Taylor series\u003e. In the example above, one can write\r\n\r\n f_{j+1} = f_j + h f' + h^2 f''/2 + h^3 f'''/6 + ...\r\n\r\nThen solving for f' and neglecting terms of order h^2 and higher gives\r\n\r\n f' = (f_{j+1} - f_j)/h - h f''/2\r\n\r\nBecause the exponent on h in the last term is 1, the method is called a first order method.\r\n\r\nWrite a function that takes the order |n| of the derivative and a vector |terms| indicating the terms to use (based on the number of grid cells away from the point in question) and produces a vector of coefficients, the order of the error term, and the numerical coefficient of the error term. In the above example, |n = 1| and |terms = [1 0]|, and \r\n\r\n coeffs   = [1 -1]\r\n errOrder = 1\r\n errCoeff = -0.5; \r\n","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: 435.55px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 217.775px; transform-origin: 407px 217.775px; 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: 380.183px 7.91667px; transform-origin: 380.183px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIn solving a differential equation with a finite-difference method, one computes derivatives with various combinations of the function's values at chosen grid points. For example, the forward difference formula for the first derivative is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 37.5833px; 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 18.7917px; text-align: left; transform-origin: 384px 18.7917px; 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: 13.5917px 7.91667px; transform-origin: 13.5917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-15px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKkAAABLCAYAAAALWaemAAAEa0lEQVR4nO2d3ZHiMBCEOwdnQAJOYCNwBGRABtQlsO/3RAzUReAcuBCIgRS4B9GnwYvBsq0f2/1VqbZg+RHtsTQzHsmAEEIIIYQQQggRiQrA1+OvGI50S0AFoAVwBXAEcAdwytqjZSDdElEBuMEJXQGo4cS+w40O4jXSLSEtnLDN4/EOXvxdrk4tAOmWiC84oW+5O7IwpFtCzpAfNQbplogdvA+1z9yXJSHdEnKAF1s+1HCkW2QauFTJEcAFXuyjaRL+J9ItIXt4USn0Bc9ii59ItwwwOuVoIIYh3RJi/Solnocj3RLCFMoNy77efJyhhbAW3RbBFd6vyk0Fl28c05f7xBaajC9Jt1VTwR+k74HvaeAO6NDXD+3HAT5aHnPgp46ih8D+lqDbJmjgxW4+vLb7nvOH14WUrFVwaRsGI6WPTjF1Ex1sGmVuv4oGN/Qg2veUbqQxdRMdWL1zjfDZazbSmLqJDjcML474ghtBTnAH6dMIsmYjjambMNjC3KHFEQwYWNz7jrUaaWzdRmHTIhc4x7cvebt7dGQJzvEe4cURNKIhv2+tRhpbt2BodDwD2MG+M4JXIdoYnZmZb4QbBAOGbrrGBhJDWl8aZglGOqdus8C8Xf14TCPsS/zy9SGjRy7Y1xDhGDDUneeZPrKNWh1e/K/7frIEI51Tt8lw1OyOin25PxbAliwwYV9vCCsrC/Gr1jjdp9AtCF72GnrG0KhLHEWPcNMUReIoF3K9OtSvWoOR5tAt+INDhugzyhHXYn9LAyc4/ewQQv2qMUbKqzIl6JhLt8GcEF50EMXnmIEK3o/aw7kvF4RPPaF+VYiRMijtVrrn1DOXbm+p4R17W+FiHf6+DjYoO+1EIxh74JnnCxnhdhO+rxRy6PaWFv5s4dl8Nc+/q15hdDsWFmNMbbHW1nAajpJCWTHRdLMV16mCIOv/TGlzikEdGoyf6rZIEt3oj6ascKnhR+wpbc6TqobzyVs4TZY8backiW6quBZFM6biWoikWN9Q26aIIrGFEil3oUgd3f8C8EctW5u0BDpXxXXq6P7vTN+nNq79/nyI+mHFderEfInRvSgQu42fktaiSGzFtXKCokhYca1tpUWxMGgquVBE+Kr/Tc52nOq1Q1p57OE3CNusS8ZqFU31ZcMKtU0cpz2eR0wWlegqU9mEbMqwaOyKzwr+bmYqKCmbMZsyLBZO7bxbGe8HqVrJstncJmFc7nHGBs7KlcDsi2Y8USwcRbvLibl0R7elEVmxm9Yy4K3wnJa6YYNpKVEOvBp4fzzmEo1vPBuwCtVFNpgfPcMbKEdNG/WrMEhkwS7p4a0SbUmijfp1tVBkwVannfFzSm/x7AoIkRy7xPxV+skasBBZ4BLzV0UldtmN/FGRBRsUvRopcy2cFOI/n24yS390Cdu/i5VibzL7iu5Uf4IWI4rEvCvNs/7oDs5QV1/CJ8ri024y1h/lrYuESAp3V+7zN2s4w2yhSjYhhBBCCCGEEEIIIYQQQsTkHzIr3fuGMmo5AAAAAElFTkSuQmCC\" alt=\"f' = (f_{j+1} - f_j})/h\" style=\"width: 84.5px; height: 37.5px;\" width=\"84.5\" height=\"37.5\"\u003e\u003c/span\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: 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: 365.642px 7.91667px; transform-origin: 365.642px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ewhere j is the grid index and h is the spacing between points. The systematic approach for deriving such formulas is to\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"http://www2.math.umd.edu/~dlevy/classes/amsc466/lecture-notes/differentiation-chap.pdf\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003euse Taylor series\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 116.3px 7.91667px; transform-origin: 116.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. In the example above, one can write\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 36.0833px; 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 18.0417px; text-align: left; transform-origin: 384px 18.0417px; 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: 13.5917px 7.91667px; transform-origin: 13.5917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-15px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcUAAABICAYAAACHmO42AAALhklEQVR4nO2dvZHryA6Fj/tsec9UAkpAESgCZTDm85SB/LXkr6faCJSDUlAMYz73rkGdIkQ1yf4lm+T5qlh174iaIdFNoIEGQEAIIYQQQgghhBBCCCGEEEIIIYQQtbMHcAZwAfADYDfv5Yg3BzRjcgFwmvlahBBiE5wB/AHwAPD7/vcvpITn5oZmHOy43Ge9IiGEWDlHAC98eoY3tIZRHuM8nNEYQMp/h2ac/qDxHoUQQhTgBrdHSM9E3uI83Bw/u0BjIoQQSRxHPu9TsA9IAZdi/z5CuaJZrAghhPDkgsbLeCItBEqjqPBpOkc042L3Bi+Bv4Ph07FFjhBCiA5HNIqXyTMxKKkjLzs08uS4hBg37vu+0Ow1CiGECGCPVvn+RHz/jMajiQnxiX6YwNRNbBrihMarZJJNqEEVQojNwxKLmExFhunkkeSHhi3WA6dRdSXhCCGE6IFhuifC9wRviPMuxTAHtAuVlAXHC824CiGE8ITJHKEexQ+0j1iKH7RGMSUs/UD8PrEQQmyOWI+ExeKu36di8XRSvHfLE+GZq0IIsVmsR2K7obDGzeVBnuFO/tij8UpUlpEOZX81Pzvis3TGLj7O+E6oOUIJUEIIEQTrC7nvdEBj8G5wlwRYz9J1KKkjHVsiw2YIVzTjckFrMG1YlOff3985vz+X1y6EEAFQmV7QGkQqYpuVSqP4g/YtDK5DXkk6bM/GRgq390HZMivVGsU92jH4gYyhEEIE0/VIuh1QrKeokOh00Ht/oE1movytp351fluIHrjCer6PO1TEGsMJzc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\"226.5\" height=\"36\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; 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 10.5px; text-align: left; transform-origin: 384px 10.5px; 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: 51.7333px 7.91667px; transform-origin: 51.7333px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThen solving for \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAkCAYAAAAD3IPhAAABNklEQVRYhe2XXbGEMAxGj4c6wAAGVsEqwEEdrINrAQ1IwAMWqgEL3IcmU3Zm2W2ZBnjgPPET2kyS5gtwc3MDQAM8Mu0aKydaIAAj0AMz4L/YLsBk4chDFh/k3sv9DLgP9n/yvq/tiJNNZ1LYn7LZuPFNkPdtbWdevEflF5qiXPsiZlm8y7TXFFaPSicLL+SfjAmjqAziSMi0d2L/qah34Yl18iKlKKye+S+bdcSTVA3dtCelaFg9/1U7Jo1OT9FCXsc1Retlq7EditbLVmM7jIaUoqoFuQdt94tcn4oKXdWesZcRwxGgFI1K9RGgFFXdEnE0Q1W3RBzNUBnIFUdTJi7SX3QEMBmOStFh6vAj7Yj1sf7dUHE8XKXXI4IjHelTektLVOZATE84yxGlIabJc4GecnMp/gGjCl04ApTc8QAAAABJRU5ErkJggg==\" alt=\"f'\" style=\"width: 17.5px; height: 18px;\" width=\"17.5\" height=\"18\"\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: 94.9083px 7.91667px; transform-origin: 94.9083px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and neglecting terms of order \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-5px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAnCAYAAAD3h5P5AAABYklEQVRYhe2WYc2DMBCGHw84wAAGUICCOagDHGABDZ8EPMzCNGCB/ehdOFgZa8uWfEmfpFlGcz16974tUChcQwv0MtpfJa2AO/CQ30XGn8x9lQlw5n8DzPIC/TcT1/jd7nGSPDQXtXh9Mt8EnrcpyVU0E3ml0+RDbGCFF4sKJ0W5vcSGqnLKKMEP0hT7IGHXNljtEouT+CQa1pLfEmLvZPhbbbLwXul79LDJOt1UbDE7qPAOCSWOqp5azAqmZT06Z7Yq1h3bU05xRFhV/bkAnTwb8ALqzYtNJsbaMjQ+bp36c8bvaJShC6gLNHnDepOFRlTJJ7O4Y3szWRcke/iIyiw+4ndpS2Zd0L1EZ9Kx7dVeudpbbcmlDLwva0hsl6FimnlVqO13yFJZ1Gz7vSf11PuIG8e9hrXf1mKXVeDsCtV+O5nfOyELXTx0hdp+Txyf4UmcXaE125PtZ9/khUKh8L94Ap3giAaNUZJzAAAAAElFTkSuQmCC\" alt=\"h^2\" style=\"width: 15.5px; height: 19.5px;\" width=\"15.5\" height=\"19.5\"\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: 53.3px 7.91667px; transform-origin: 53.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and higher gives\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 38.5833px; 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 19.2917px; text-align: left; transform-origin: 384px 19.2917px; 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: 13.5917px 7.91667px; transform-origin: 13.5917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e       \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"vertical-align:-15px\"\u003e\u003cimg src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQQAAABNCAYAAABAKBoaAAAHIklEQVR4nO2dzXHjOBCFXw687VEJKAFHoAiUgY97U20Cus9JMag2AuWgDUExKAXvAX5Gi+YfKIL44fuqUFMzI1tgE2g0uhsNQAghhBBCCCGEEEIIIcQqNAA+vv8U05HcRFU0AG4AHgBOAL4AXJL2qAwkN1EdDYAn3KBuAOzhBvYX3KonupHcRJXc4Abx4fvvO/iBvkvVqQKQ3ER1fMAN6mfqjhSG5Caq5Arte+cguYnq2MHveY+J+1ISkpuokk/4ga0973QkN1ENB7jw2AnAHX5gn0zTIP/NluSmCMmGOMIPYA7qO14HtvhNzXI7wflCqOieUILV5qCXnKucmEatcrPPdUvcF5EAuw+WiTidWuVmHaWfifsiEsCwWenm4WmBFkItcmtzhFcI+8R9EQl4wO+DU9PA72FD+XqzhSYW5SS3JaGiu6MuRScm0MBPiPPEnznATZ6pn5/aj094Z9acSfaudRBiHucitxg8oUSrzXKAH9iHkc+2f+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jRErOeH8LmeOFMUXVkrDhkDWFuXaU4R8A/6ola1uuJ8D5VUTlpVTaa+0ow38LfZ/avPZn/BVVSXEWOMMhaycZ5RhlEPXzgflWzl8zvm8sCSordGON2Bp/MN/K+XvG9805EpAM3VgjRFwY0s85zf8HhkOK0F5CFIYN6RdhgYcexxRpYDUmWXFlMaekQFLY2S2HhHLliNdTd8UMKvEDQ/ol1Bv9OZWm7ULe8CSq3lNcbI3MpbIJ59SiXI0jXi0Bej+LiI1uGF0nFpcDvOPPttCsxx3cXNqZv38h0+xEWzm5+W5P6DBT7ugi0rjYMwZdLaQ0GRU3a09yu5Blngy3Bw+4B4x2qYNYlFovWM0BOvwu8JOe1aKsxTB10bTbgxKKxPyUPLtCq00ptC8iFctxR/82jBZ0iDOXN0az0liOh6xE4XBAtkug0wGmQTcPXuo6ZHXZ7UTWK73YBjQ7bVi4wWso8gmFIudwwPgktzkEUggiOXaFAnyZsjNelYWK2sTBKgTl6Yjk0El1hVcGtAZs9EGrVxzGLjkWYjVsDvwJTjnY8JWNPmj1igPzdJa++VmIYOwp1Ct+bwts7UGxPIwyyDoQWWDL4neFHK2yEMtDC0zWl8gCmxjTjiLI+x0X+meUqyOywDoMuyyAVEVxtwDvSlTkRmSDrcHXZbLSf1DEkdqC4M3XUgYiK5h41Hfcub1duCDTAzQFIWUgsmXouLP1H+zglIKORb/PFGUgpStWZ6yGv/Uf3KEowxJcML79OkKKVyTgCH/fRBd7OCVwg7zgS8Dw7hlO2XY1fkYhSCEqxuZ6jDUdPxeiYg4Iux1M1pgQQgghhBBCCCGEEEIIIYQQQgghhBBCWP4HvMwy/Pk8LhMAAAAASUVORK5CYII=\" alt=\"f' = (f_{j+1} - f_j)/h - hf''/2\" style=\"width: 130px; height: 38.5px;\" width=\"130\" height=\"38.5\"\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; 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 10.5px; text-align: left; transform-origin: 384px 10.5px; 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: 81.3px 7.91667px; transform-origin: 81.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eBecause the exponent on \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003eh\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: 191.35px 7.91667px; transform-origin: 191.35px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in the last term is 1, the method is called a first order method.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.5px; 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: 110.717px 7.91667px; transform-origin: 110.717px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the order\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"font-family: \u0026quot;STIXGeneral\u0026quot;, \u0026quot;STIXGeneral-webfont\u0026quot;, serif; font-style: italic; font-weight: 400; color: rgb(0, 0, 0);\"\u003en\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: 91.7917px 7.91667px; transform-origin: 91.7917px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of the derivative and a vector\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; 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: 19.25px 7.91667px; transform-origin: 19.25px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eterms\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: 130.3px 7.91667px; transform-origin: 130.3px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e indicating the terms to use (based on the number of grid cells away from the point in question) and produces a vector of coefficients, the order of the error term, and the numerical coefficient of the error term. In the above example,\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; 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: 19.25px 7.91667px; transform-origin: 19.25px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003en = 1\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: 13.6167px 7.91667px; transform-origin: 13.6167px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and\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: 1.94167px 7.91667px; transform-origin: 1.94167px 7.91667px; 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: 50.05px 7.91667px; transform-origin: 50.05px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eterms = [1 0]\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: 15.5583px 7.91667px; transform-origin: 15.5583px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, and\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; 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 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 69.3px 7.91667px; transform-origin: 69.3px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e coeffs   = [1 -1]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 50.05px 7.91667px; transform-origin: 50.05px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e errOrder = 1\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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: 0.833333px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.833333px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.833333px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.833333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 65.45px 7.91667px; transform-origin: 65.45px 7.91667px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e errCoeff = -0.5;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [coeff,errOrder,errCoeff] = FDderiv(n,terms)\r\n%  n        = order of the derivative sought\r\n%  terms    = grid indices of terms to include\r\n%  coeff    = coefficients of the terms in the formula \r\n%  errOrder = exponent of h in the first non-zero higher-order term\r\n%  errCoeff = coefficient of the first non-zero higher-order term\r\n\r\n  coeff    = ...\r\n  errOrder = ...\r\n  errCoeff = ...\r\nend","test_suite":"%%\r\n%  First-order forward difference for the first derivative\r\nn = 1;\r\nterms = [1 0];\r\ncoeff_correct = [1 -1];\r\nerrOrder_correct = 1;\r\nerrCoeff_correct = -1/2;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  First-order backward difference for the first derivative\r\nn = 1;\r\nterms = [0 -1];\r\ncoeff_correct = [1 -1];\r\nerrOrder_correct = 1;\r\nerrCoeff_correct = 1/2;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the first derivative\r\nn = 1;\r\nterms = [1 -1];\r\ncoeff_correct = [1/2 -1/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/6;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order forward difference for the first derivative\r\nn = 1;\r\nterms = [2 1 0];\r\ncoeff_correct = [-1/2 2 -3/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = 1/3;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order backward difference for the first derivative\r\nn = 1;\r\nterms = [0 -1 -2];\r\ncoeff_correct = [3/2 -2 1/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = 1/3;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Fourth-order centered difference for the first derivative\r\nn = 1;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [-1 8 0 -8 1]/12\r\nerrOrder_correct = 4;\r\nerrCoeff_correct = 1/30;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the second derivative\r\nn = 2;\r\nterms = [1 0 -1];\r\ncoeff_correct = [1 -2 1];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/12;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Fourth-order centered difference for the second derivative\r\nn = 2;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [-1 16 -30 16 -1]/12;\r\nerrOrder_correct = 4;\r\nerrCoeff_correct = 1/90;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the third derivative\r\nn = 3;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [1/2 -1 0 1 -1/2];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/4;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)\r\n\r\n%%\r\n%  Second-order centered difference for the fourth derivative\r\nn = 4;\r\nterms = [2 1 0 -1 -2];\r\ncoeff_correct = [1 -4 6 -4 1];\r\nerrOrder_correct = 2;\r\nerrCoeff_correct = -1/6;\r\n[coeff,errOrder,errCoeff] = FDderiv(n,terms);\r\nassert(all(abs(coeff-coeff_correct) \u003c 1e-6))\r\nassert(isequal(errOrder,errOrder_correct))\r\nassert(abs((errCoeff-errCoeff_correct)/errCoeff_correct) \u003c 1e-4)","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":46909,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-07-22T03:37:57.000Z","updated_at":"2020-11-15T13:41:30.000Z","published_at":"2020-07-22T05:20:57.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\u003eIn solving a differential equation with a finite-difference method, one computes derivatives with various combinations of the function's values at chosen grid points. For example, the forward difference formula for the first derivative is\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\u003e       \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f' = (f_{j+1} - f_j})/h\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ef\\\\prime=\\\\frac{f_{j+1}-f_j}{h}\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003ewhere j is the grid index and h is the spacing between points. The systematic approach for deriving such formulas is to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www2.math.umd.edu/~dlevy/classes/amsc466/lecture-notes/differentiation-chap.pdf\\\"\u003e\u003cw:r\u003e\u003cw:t\u003euse Taylor series\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. In the example above, one can write\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\u003e       \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f_{j+1} = f_j + hf' + h^2 f''/2 + h^3 f'''/6 + ...\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e f_{j+1} = f_j + h f\\\\prime +  \\\\frac{h^2}{2}f\\\\prime\\\\prime +  \\\\frac{h^3}{6}f\\\\prime\\\\prime\\\\prime + \\\\ldots\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003eThen solving for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f'\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e$f\\\\prime$\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e and neglecting terms of order \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"h^2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003e$h^2$\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e and higher gives\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\u003e       \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"true\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"f' = (f_{j+1} - f_j)/h - hf''/2\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003ef\\\\prime = \\\\frac{f_{j+1} - f_j}{h} - \\\\frac{h}{2}f\\\\prime\\\\prime\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\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\u003eBecause the exponent on \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"h\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003eh\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e in the last term is 1, the method is called a first order method.\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\u003eWrite a function that takes the order\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"equation\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"displayStyle\\\" w:val=\\\"false\\\"/\u003e\u003cw:attr w:name=\\\"altTextString\\\" w:val=\\\"n\\\"/\u003e\u003c/w:customXmlPr\u003e\u003cw:r\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:customXml\u003e\u003cw:r\u003e\u003cw:t\u003e of the derivative and a vector\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eterms\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e indicating the terms to use (based on the number of grid cells away from the point in question) and produces a vector of coefficients, the order of the error term, and the numerical coefficient of the error term. In the above example,\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 1\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eterms = [1 0]\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and\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[ coeffs   = [1 -1]\\n errOrder = 1\\n errCoeff = -0.5;]]\u003e\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\"}]}"}],"term":"tag:\"finite difference\"","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:\"finite difference\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"finite difference\"","","\"","finite difference","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe6c38\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f76f7fe6b98\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe62d8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe6eb8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f76f7fe6e18\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f76f7fe6d78\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f76f7fe6cd8\u003e":"tag:\"finite difference\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe6cd8\u003e":"tag:\"finite difference\""},"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:\"finite difference\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"finite difference\"","","\"","finite difference","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe6c38\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f76f7fe6b98\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe62d8\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe6eb8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f76f7fe6e18\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f76f7fe6d78\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f76f7fe6cd8\u003e":"tag:\"finite difference\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f76f7fe6cd8\u003e":"tag:\"finite difference\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1485,"difficulty_rating":"easy"},{"id":1486,"difficulty_rating":"easy"},{"id":561,"difficulty_rating":"easy"},{"id":46053,"difficulty_rating":"unrated"}]}}