Cody

# Problem 486. Surface Fit z(x,y)

Solution 60041

Submitted on 12 Mar 2012 by Venu Lolla
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% x= [0 0 1 1 2 2 3 3]; y= [0 1 0 1 0 1 0 1]; z=[-4 -1 -3 -2 0 -1 5 2]; c=[1 -2 3 -4]; assert(isequal(c,round(sufit(x,y,z))))

{Warning: Trust-region-reflective algorithm requires at least as many equations as variables; using Levenberg-Marquardt algorithm instead.} {> In lsqncommon at 77 In lsqnonlin at 235 In sufit at 5 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'lsq_init_pt_min','CSHelpWindow');">Initial point is a local minimum</a>. Optimization completed because the <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'lsq_grad_size','CSHelpWindow');">size of the gradient</a> at the initial point is less than the default value of the <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'function_tolerance_lsq','CSHelpWindow');">function tolerance</a>. <<a href = "matlab: createExitMsg('levenbergMarquardt',1.000000e+02,true,true,'lsqnonlin',0.000000e+00,'default',1.000000e-10,0.000000e+00,'',0.000000e+00,0.000000e+00,'',0.000000e+00);">stopping criteria details</a>>

2   Pass
%% x= rand(1,100); y= rand(1,100); z=7*x.^2-9*x.*y+11*y.^2-17; c=[7 -9 11 -17]; assert(isequal(c,round(sufit(x,y,z))))

{Warning: Trust-region-reflective algorithm requires at least as many equations as variables; using Levenberg-Marquardt algorithm instead.} {> In lsqncommon at 77 In lsqnonlin at 235 In sufit at 5 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'lsq_init_pt_min','CSHelpWindow');">Initial point is a local minimum</a>. Optimization completed because the <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'lsq_grad_size','CSHelpWindow');">size of the gradient</a> at the initial point is less than the default value of the <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'function_tolerance_lsq','CSHelpWindow');">function tolerance</a>. <<a href = "matlab: createExitMsg('levenbergMarquardt',1.000000e+02,true,true,'lsqnonlin',3.591368e-23,'default',1.000000e-10,0.000000e+00,'',0.000000e+00,0.000000e+00,'',0.000000e+00);">stopping criteria details</a>>

3   Pass
%% x= rand(1,10000); y= rand(1,10000); z=17*x.^2-19*x.*y+11*y.^2-13; c=[17 -19 11 -13]; assert(isequal(c,round(sufit(x,y,z))))

{Warning: Trust-region-reflective algorithm requires at least as many equations as variables; using Levenberg-Marquardt algorithm instead.} {> In lsqncommon at 77 In lsqnonlin at 235 In sufit at 5 In verifyCode>evaluateCode at 189 In verifyCode at 37 In fevalJSON at 14} <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'lsq_init_pt_min','CSHelpWindow');">Initial point is a local minimum</a>. Optimization completed because the <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'lsq_grad_size','CSHelpWindow');">size of the gradient</a> at the initial point is less than the default value of the <a href = "matlab: helpview([docroot '/toolbox/optim/msg_csh/optim_msg_csh.map'],'function_tolerance_lsq','CSHelpWindow');">function tolerance</a>. <<a href = "matlab: createExitMsg('levenbergMarquardt',1.000000e+02,true,true,'lsqnonlin',1.438712e-19,'default',1.000000e-10,0.000000e+00,'',0.000000e+00,0.000000e+00,'',0.000000e+00);">stopping criteria details</a>>