{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.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":"2026-04-06T00: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":44507,"title":"Curve fitting (linear functions) \u0026 function handles","description":"In this problem you are provided some raw data.  You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed.  You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.  \r\n\r\nConsider a linear function _y = m x + c_.  Let's say |x| is a vector of uniformly spaced numbers, such as |1:100|.  The function operates on the data to produce, say, |y = 2:2:200|.  You are provided with both the vector |x| and the vector |y|.  The parameters |m| and |c| are scalars;  in this example |m| is 2 and |c| is zero.  \r\n\r\nSo here you should output two things:\r\n\r\n* the handle to a _generic_ function that implements a linear function (i.e. of the form _y = m x + c_) taking two inputs, namely *1* a set of parameters and *2* the vector |x|, and outputting the corresponding vector |y|;  and\r\n* a set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).  \r\n\r\nAs the parameters will be used in your own function, the data type will be set by you.  \r\n\r\nSo, for the above example, you _could_ return a \u003chttps://au.mathworks.com/help/matlab/function-handles.html function handle\u003e |@myFunc| that you have defined, along with the variable |param| that has two \u003chttps://au.mathworks.com/help/matlab/structures.html fields\u003e such that |param.amplification| = 2 and |param.verticalShift| = NaN.  \r\n\r\nOr, if you have defined your function differently, then you _could_ return the \u003chttps://au.mathworks.com/help/matlab/function-handles.html function handle\u003e |@myFn| along with a \u003chttps://au.mathworks.com/help/matlab/cell-arrays.html cell array\u003e variable |prms| that has four elements such that |prms{1}='no'|, |prms{2}=NaN|, |prms{3} = 'yes'| and |prms{4} = 2|.  \r\n\r\nAnd so on.  \r\n\r\n_Note:  *all* of the relevant numbers ( |m|, |c| and the elements of |x| and |y|) are *integers* (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type \u003chttps://au.mathworks.com/help/matlab/ref/double.html double\u003e._  \r\n\r\n* See also \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44508 Problem 44508. Curve fitting (non-linear functions) \u0026 function handles\u003e — more difficult.","description_html":"\u003cp\u003eIn this problem you are provided some raw data.  You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed.  You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.\u003c/p\u003e\u003cp\u003eConsider a linear function \u003ci\u003ey = m x + c\u003c/i\u003e.  Let's say \u003ctt\u003ex\u003c/tt\u003e is a vector of uniformly spaced numbers, such as \u003ctt\u003e1:100\u003c/tt\u003e.  The function operates on the data to produce, say, \u003ctt\u003ey = 2:2:200\u003c/tt\u003e.  You are provided with both the vector \u003ctt\u003ex\u003c/tt\u003e and the vector \u003ctt\u003ey\u003c/tt\u003e.  The parameters \u003ctt\u003em\u003c/tt\u003e and \u003ctt\u003ec\u003c/tt\u003e are scalars;  in this example \u003ctt\u003em\u003c/tt\u003e is 2 and \u003ctt\u003ec\u003c/tt\u003e is zero.\u003c/p\u003e\u003cp\u003eSo here you should output two things:\u003c/p\u003e\u003cul\u003e\u003cli\u003ethe handle to a \u003ci\u003egeneric\u003c/i\u003e function that implements a linear function (i.e. of the form \u003ci\u003ey = m x + c\u003c/i\u003e) taking two inputs, namely \u003cb\u003e1\u003c/b\u003e a set of parameters and \u003cb\u003e2\u003c/b\u003e the vector \u003ctt\u003ex\u003c/tt\u003e, and outputting the corresponding vector \u003ctt\u003ey\u003c/tt\u003e;  and\u003c/li\u003e\u003cli\u003ea set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs the parameters will be used in your own function, the data type will be set by you.\u003c/p\u003e\u003cp\u003eSo, for the above example, you \u003ci\u003ecould\u003c/i\u003e return a \u003ca href = \"https://au.mathworks.com/help/matlab/function-handles.html\"\u003efunction handle\u003c/a\u003e \u003ctt\u003e@myFunc\u003c/tt\u003e that you have defined, along with the variable \u003ctt\u003eparam\u003c/tt\u003e that has two \u003ca href = \"https://au.mathworks.com/help/matlab/structures.html\"\u003efields\u003c/a\u003e such that \u003ctt\u003eparam.amplification\u003c/tt\u003e = 2 and \u003ctt\u003eparam.verticalShift\u003c/tt\u003e = NaN.\u003c/p\u003e\u003cp\u003eOr, if you have defined your function differently, then you \u003ci\u003ecould\u003c/i\u003e return the \u003ca href = \"https://au.mathworks.com/help/matlab/function-handles.html\"\u003efunction handle\u003c/a\u003e \u003ctt\u003e@myFn\u003c/tt\u003e along with a \u003ca href = \"https://au.mathworks.com/help/matlab/cell-arrays.html\"\u003ecell array\u003c/a\u003e variable \u003ctt\u003eprms\u003c/tt\u003e that has four elements such that \u003ctt\u003eprms{1}='no'\u003c/tt\u003e, \u003ctt\u003eprms{2}=NaN\u003c/tt\u003e, \u003ctt\u003eprms{3} = 'yes'\u003c/tt\u003e and \u003ctt\u003eprms{4} = 2\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eAnd so on.\u003c/p\u003e\u003cp\u003e\u003ci\u003eNote:  \u003cb\u003eall\u003c/b\u003e of the relevant numbers ( \u003ctt\u003em\u003c/tt\u003e, \u003ctt\u003ec\u003c/tt\u003e and the elements of \u003ctt\u003ex\u003c/tt\u003e and \u003ctt\u003ey\u003c/tt\u003e) are \u003cb\u003eintegers\u003c/b\u003e (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type \u003ca href = \"https://au.mathworks.com/help/matlab/ref/double.html\"\u003edouble\u003c/a\u003e.\u003c/i\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003eSee also \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44508\"\u003eProblem 44508. Curve fitting (non-linear functions) \u0026 function handles\u003c/a\u003e — more difficult.\u003c/li\u003e\u003c/ul\u003e","function_template":"%{\r\n    Some comments about this code....\r\n%}\r\nfunction [afunctionhandle asetofparameters] = generateFit(x, y)    % \u003c---This function is called first by the Test Suite\r\n    % Here you are going to figure out the values of the parameters\r\n    \r\n    afunctionhandle\r\n    asetofparameters\r\n    \r\nfunction nameofyouroutputvectorvariable = nameofyourgenericlinearfunction(nameofyourparametersetvariable, nameofyourxvectorvariable)\r\n    % Here you are providing code representing y = m x + c.  ","test_suite":"%% Gradient only\r\nx = 1:100;\r\ny_correct = 2:2:200;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Intercept only\r\nx = 1:100;\r\ny_correct = 101:200;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Gradient and intercept — same input\r\nx = 1:100;\r\ny_correct = 102:2:300;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Gradient and intercept — different inputs\r\nx = 1:100;\r\ny_correct = 102:2:300;\r\n[fh, pars] = generateFit(x, y_correct);\r\nels = 10+randi(30) : 60+randi(30);\r\ny = fh(pars, x(els));\r\nassert( isequal(y,y_correct(els)) )\r\ny = fh(pars, x+100);\r\nassert( isequal(y,302:2:500) )\r\n\r\n%% Another gradient and intercept\r\nx = 1000:-1:500;\r\ny_correct = 0:500;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Yet another gradient and intercept\r\nx = 1000:-1:500;\r\ny_correct = -500:2:500;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Even more gradient and intercept combinations, randomly generated\r\nfor i = 1 : 20\r\n    x = -randi(1000) : randi(10) : randi(1000);\r\n    m = randi(20)-10;\r\n    c = randi(20)-10;\r\n    y_correct = round(exp(log(c) + log(x)))  -  m^1 * (x(1))^0;\r\n    [fh, pars] = generateFit(x, y_correct);\r\n    y = fh(pars, x);\r\n    assert( isequal(y,y_correct) )\r\nend;\r\n\r\n%% Now check whether the function handle refers to a truly generic function.\r\n% \"Gradient and intercept\"\r\nx1 = 1:100;\r\ny1_correct = 102:2:300;\r\n[fh1, pars1] = generateFit(x1, y1_correct);\r\n\r\n% \"Another gradient and intercept\"\r\nx2 = 1000:-1:500;\r\ny2_correct = 0:500;\r\n[fh2, pars2] = generateFit(x2, y2_correct);\r\n\r\n% According to the Problem Statament, fh1 and fh2 should be interchangeable.  \r\ny1 = fh2(pars1, x1);\r\nassert( isequal(y1,y1_correct) )\r\n\r\ny2 = fh1(pars2, x2);\r\nassert( isequal(y2,y2_correct) )\r\n\r\n\r\n%% Check parameter variable\r\n% Finally, check that the user is sending a small number of parameters to their\r\n% custom function (to be called via the function handle), and not simply sending\r\n% the entire vector y.  \r\nx = 1:1000;\r\ny_correct = flip(1:1000);\r\n[fh, pars] = generateFit(x, y_correct);\r\npw = whos('pars')\r\nassert( pw.bytes \u003c 100 , 'Parameter variable is too big.')\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-27T13:32:51.000Z","updated_at":"2018-01-30T13:02:58.000Z","published_at":"2018-01-29T12:37:35.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\u003eIn this problem you are provided some raw data. You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed. You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.\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\u003eConsider a linear function\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey = m x + c\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Let's say\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a vector of uniformly spaced numbers, such as\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\u003e1:100\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The function operates on the data to produce, say,\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\u003ey = 2:2:200\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. You are provided with both the 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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and the 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\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The parameters\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\u003em\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are scalars; in this 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\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is 2 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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is zero.\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\u003eSo here you should output two things:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe handle to a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egeneric\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function that implements a linear function (i.e. of the form\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey = m x + c\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e) taking two inputs, namely\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e a set of parameters 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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the 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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and outputting the corresponding 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\u003ey\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ea set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).\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\u003eAs the parameters will be used in your own function, the data type will be set by you.\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\u003eSo, for the above example, you\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecould\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e return a\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=\\\"https://au.mathworks.com/help/matlab/function-handles.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efunction handle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\u003e@myFunc\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that you have defined, along with the variable\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\u003eparam\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that has two\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=\\\"https://au.mathworks.com/help/matlab/structures.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e such that\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\u003eparam.amplification\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 2 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\u003eparam.verticalShift\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = NaN.\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\u003eOr, if you have defined your function differently, then you\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecould\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e return the\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=\\\"https://au.mathworks.com/help/matlab/function-handles.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efunction handle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\u003e@myFn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e along with a\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=\\\"https://au.mathworks.com/help/matlab/cell-arrays.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecell array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e variable\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\u003eprms\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that has four elements such that\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\u003eprms{1}='no'\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: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\u003eprms{2}=NaN\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: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\u003eprms{3} = 'yes'\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\u003eprms{4} = 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eAnd so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e of the relevant numbers (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and the elements of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e) are\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eintegers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/double.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edouble\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44508\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44508. Curve fitting (non-linear functions) \u0026amp; function handles\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e — more difficult.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44507,"title":"Curve fitting (linear functions) \u0026 function handles","description":"In this problem you are provided some raw data.  You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed.  You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.  \r\n\r\nConsider a linear function _y = m x + c_.  Let's say |x| is a vector of uniformly spaced numbers, such as |1:100|.  The function operates on the data to produce, say, |y = 2:2:200|.  You are provided with both the vector |x| and the vector |y|.  The parameters |m| and |c| are scalars;  in this example |m| is 2 and |c| is zero.  \r\n\r\nSo here you should output two things:\r\n\r\n* the handle to a _generic_ function that implements a linear function (i.e. of the form _y = m x + c_) taking two inputs, namely *1* a set of parameters and *2* the vector |x|, and outputting the corresponding vector |y|;  and\r\n* a set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).  \r\n\r\nAs the parameters will be used in your own function, the data type will be set by you.  \r\n\r\nSo, for the above example, you _could_ return a \u003chttps://au.mathworks.com/help/matlab/function-handles.html function handle\u003e |@myFunc| that you have defined, along with the variable |param| that has two \u003chttps://au.mathworks.com/help/matlab/structures.html fields\u003e such that |param.amplification| = 2 and |param.verticalShift| = NaN.  \r\n\r\nOr, if you have defined your function differently, then you _could_ return the \u003chttps://au.mathworks.com/help/matlab/function-handles.html function handle\u003e |@myFn| along with a \u003chttps://au.mathworks.com/help/matlab/cell-arrays.html cell array\u003e variable |prms| that has four elements such that |prms{1}='no'|, |prms{2}=NaN|, |prms{3} = 'yes'| and |prms{4} = 2|.  \r\n\r\nAnd so on.  \r\n\r\n_Note:  *all* of the relevant numbers ( |m|, |c| and the elements of |x| and |y|) are *integers* (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type \u003chttps://au.mathworks.com/help/matlab/ref/double.html double\u003e._  \r\n\r\n* See also \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44508 Problem 44508. Curve fitting (non-linear functions) \u0026 function handles\u003e — more difficult.","description_html":"\u003cp\u003eIn this problem you are provided some raw data.  You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed.  You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.\u003c/p\u003e\u003cp\u003eConsider a linear function \u003ci\u003ey = m x + c\u003c/i\u003e.  Let's say \u003ctt\u003ex\u003c/tt\u003e is a vector of uniformly spaced numbers, such as \u003ctt\u003e1:100\u003c/tt\u003e.  The function operates on the data to produce, say, \u003ctt\u003ey = 2:2:200\u003c/tt\u003e.  You are provided with both the vector \u003ctt\u003ex\u003c/tt\u003e and the vector \u003ctt\u003ey\u003c/tt\u003e.  The parameters \u003ctt\u003em\u003c/tt\u003e and \u003ctt\u003ec\u003c/tt\u003e are scalars;  in this example \u003ctt\u003em\u003c/tt\u003e is 2 and \u003ctt\u003ec\u003c/tt\u003e is zero.\u003c/p\u003e\u003cp\u003eSo here you should output two things:\u003c/p\u003e\u003cul\u003e\u003cli\u003ethe handle to a \u003ci\u003egeneric\u003c/i\u003e function that implements a linear function (i.e. of the form \u003ci\u003ey = m x + c\u003c/i\u003e) taking two inputs, namely \u003cb\u003e1\u003c/b\u003e a set of parameters and \u003cb\u003e2\u003c/b\u003e the vector \u003ctt\u003ex\u003c/tt\u003e, and outputting the corresponding vector \u003ctt\u003ey\u003c/tt\u003e;  and\u003c/li\u003e\u003cli\u003ea set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eAs the parameters will be used in your own function, the data type will be set by you.\u003c/p\u003e\u003cp\u003eSo, for the above example, you \u003ci\u003ecould\u003c/i\u003e return a \u003ca href = \"https://au.mathworks.com/help/matlab/function-handles.html\"\u003efunction handle\u003c/a\u003e \u003ctt\u003e@myFunc\u003c/tt\u003e that you have defined, along with the variable \u003ctt\u003eparam\u003c/tt\u003e that has two \u003ca href = \"https://au.mathworks.com/help/matlab/structures.html\"\u003efields\u003c/a\u003e such that \u003ctt\u003eparam.amplification\u003c/tt\u003e = 2 and \u003ctt\u003eparam.verticalShift\u003c/tt\u003e = NaN.\u003c/p\u003e\u003cp\u003eOr, if you have defined your function differently, then you \u003ci\u003ecould\u003c/i\u003e return the \u003ca href = \"https://au.mathworks.com/help/matlab/function-handles.html\"\u003efunction handle\u003c/a\u003e \u003ctt\u003e@myFn\u003c/tt\u003e along with a \u003ca href = \"https://au.mathworks.com/help/matlab/cell-arrays.html\"\u003ecell array\u003c/a\u003e variable \u003ctt\u003eprms\u003c/tt\u003e that has four elements such that \u003ctt\u003eprms{1}='no'\u003c/tt\u003e, \u003ctt\u003eprms{2}=NaN\u003c/tt\u003e, \u003ctt\u003eprms{3} = 'yes'\u003c/tt\u003e and \u003ctt\u003eprms{4} = 2\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eAnd so on.\u003c/p\u003e\u003cp\u003e\u003ci\u003eNote:  \u003cb\u003eall\u003c/b\u003e of the relevant numbers ( \u003ctt\u003em\u003c/tt\u003e, \u003ctt\u003ec\u003c/tt\u003e and the elements of \u003ctt\u003ex\u003c/tt\u003e and \u003ctt\u003ey\u003c/tt\u003e) are \u003cb\u003eintegers\u003c/b\u003e (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type \u003ca href = \"https://au.mathworks.com/help/matlab/ref/double.html\"\u003edouble\u003c/a\u003e.\u003c/i\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003eSee also \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44508\"\u003eProblem 44508. Curve fitting (non-linear functions) \u0026 function handles\u003c/a\u003e — more difficult.\u003c/li\u003e\u003c/ul\u003e","function_template":"%{\r\n    Some comments about this code....\r\n%}\r\nfunction [afunctionhandle asetofparameters] = generateFit(x, y)    % \u003c---This function is called first by the Test Suite\r\n    % Here you are going to figure out the values of the parameters\r\n    \r\n    afunctionhandle\r\n    asetofparameters\r\n    \r\nfunction nameofyouroutputvectorvariable = nameofyourgenericlinearfunction(nameofyourparametersetvariable, nameofyourxvectorvariable)\r\n    % Here you are providing code representing y = m x + c.  ","test_suite":"%% Gradient only\r\nx = 1:100;\r\ny_correct = 2:2:200;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Intercept only\r\nx = 1:100;\r\ny_correct = 101:200;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Gradient and intercept — same input\r\nx = 1:100;\r\ny_correct = 102:2:300;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Gradient and intercept — different inputs\r\nx = 1:100;\r\ny_correct = 102:2:300;\r\n[fh, pars] = generateFit(x, y_correct);\r\nels = 10+randi(30) : 60+randi(30);\r\ny = fh(pars, x(els));\r\nassert( isequal(y,y_correct(els)) )\r\ny = fh(pars, x+100);\r\nassert( isequal(y,302:2:500) )\r\n\r\n%% Another gradient and intercept\r\nx = 1000:-1:500;\r\ny_correct = 0:500;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Yet another gradient and intercept\r\nx = 1000:-1:500;\r\ny_correct = -500:2:500;\r\n[fh, pars] = generateFit(x, y_correct);\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n\r\n%% Even more gradient and intercept combinations, randomly generated\r\nfor i = 1 : 20\r\n    x = -randi(1000) : randi(10) : randi(1000);\r\n    m = randi(20)-10;\r\n    c = randi(20)-10;\r\n    y_correct = round(exp(log(c) + log(x)))  -  m^1 * (x(1))^0;\r\n    [fh, pars] = generateFit(x, y_correct);\r\n    y = fh(pars, x);\r\n    assert( isequal(y,y_correct) )\r\nend;\r\n\r\n%% Now check whether the function handle refers to a truly generic function.\r\n% \"Gradient and intercept\"\r\nx1 = 1:100;\r\ny1_correct = 102:2:300;\r\n[fh1, pars1] = generateFit(x1, y1_correct);\r\n\r\n% \"Another gradient and intercept\"\r\nx2 = 1000:-1:500;\r\ny2_correct = 0:500;\r\n[fh2, pars2] = generateFit(x2, y2_correct);\r\n\r\n% According to the Problem Statament, fh1 and fh2 should be interchangeable.  \r\ny1 = fh2(pars1, x1);\r\nassert( isequal(y1,y1_correct) )\r\n\r\ny2 = fh1(pars2, x2);\r\nassert( isequal(y2,y2_correct) )\r\n\r\n\r\n%% Check parameter variable\r\n% Finally, check that the user is sending a small number of parameters to their\r\n% custom function (to be called via the function handle), and not simply sending\r\n% the entire vector y.  \r\nx = 1:1000;\r\ny_correct = flip(1:1000);\r\n[fh, pars] = generateFit(x, y_correct);\r\npw = whos('pars')\r\nassert( pw.bytes \u003c 100 , 'Parameter variable is too big.')\r\ny = fh(pars, x);\r\nassert( isequal(y,y_correct) )\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":64439,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":9,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-27T13:32:51.000Z","updated_at":"2018-01-30T13:02:58.000Z","published_at":"2018-01-29T12:37:35.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\u003eIn this problem you are provided some raw data. You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed. You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.\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\u003eConsider a linear function\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey = m x + c\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. Let's say\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is a vector of uniformly spaced numbers, such as\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\u003e1:100\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The function operates on the data to produce, say,\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\u003ey = 2:2:200\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. You are provided with both the 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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and the 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\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. The parameters\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\u003em\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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e are scalars; in this 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\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is 2 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\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e is zero.\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\u003eSo here you should output two things:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe handle to a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003egeneric\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e function that implements a linear function (i.e. of the form\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey = m x + c\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e) taking two inputs, namely\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e a set of parameters 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:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the 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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, and outputting the corresponding 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\u003ey\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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ea set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).\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\u003eAs the parameters will be used in your own function, the data type will be set by you.\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\u003eSo, for the above example, you\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecould\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e return a\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=\\\"https://au.mathworks.com/help/matlab/function-handles.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efunction handle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\u003e@myFunc\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that you have defined, along with the variable\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\u003eparam\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that has two\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=\\\"https://au.mathworks.com/help/matlab/structures.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efields\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e such that\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\u003eparam.amplification\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = 2 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\u003eparam.verticalShift\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e = NaN.\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\u003eOr, if you have defined your function differently, then you\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecould\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e return the\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=\\\"https://au.mathworks.com/help/matlab/function-handles.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efunction handle\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\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\u003e@myFn\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e along with a\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=\\\"https://au.mathworks.com/help/matlab/cell-arrays.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ecell array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e variable\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\u003eprms\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that has four elements such that\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\u003eprms{1}='no'\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: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\u003eprms{2}=NaN\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: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\u003eprms{3} = 'yes'\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\u003eprms{4} = 2\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\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\u003eAnd so on.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNote: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eall\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e of the relevant numbers (\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003em\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ec\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and the elements of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e) are\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eintegers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://au.mathworks.com/help/matlab/ref/double.html\\\"\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edouble\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also\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=\\\"https://www.mathworks.com/matlabcentral/cody/problems/44508\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44508. Curve fitting (non-linear functions) \u0026amp; function handles\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e — more difficult.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"linear functions\"","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:\"linear functions\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"linear functions\"","","\"","linear functions","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007effc4cc4ed8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007effc4cc4e38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007effc4cc4578\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007effc4cc5158\u003e":1,"#\u003cMathWorks::Search::Field:0x00007effc4cc50b8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007effc4cc5018\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007effc4cc4f78\u003e":"tag:\"linear functions\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007effc4cc4f78\u003e":"tag:\"linear functions\""},"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":"cody-search","password":"78X075ddcV44","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:\"linear functions\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"linear functions\"","","\"","linear functions","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007effc4cc4ed8\u003e":null,"#\u003cMathWorks::Search::Field:0x00007effc4cc4e38\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007effc4cc4578\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007effc4cc5158\u003e":1,"#\u003cMathWorks::Search::Field:0x00007effc4cc50b8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007effc4cc5018\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007effc4cc4f78\u003e":"tag:\"linear functions\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007effc4cc4f78\u003e":"tag:\"linear functions\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44507,"difficulty_rating":"easy-medium"}]}}