Prev: need help for usage of simple filter
Next: Problem when i create a digital sin wave in Matlab simulink!
From: Nic Roberts on 21 Jun 2010 11:00 Hi i am trying to obtain to constants using 'lsqcurvefit' here's the code, xdata=stretch_r(:,2).'; ydata=stress_r.'; x0=[100; 1]; [x,resnorm]=lsqcurvefit(@MooneyRivlin,x0,xdata,ydata) function F=MooneyRivlin(x,xdata) F=(2*x(1)+2*x(2)/xdata)*(xdata-1/xdata^2); Both 'stretch' and 'stress' are of length 14 but I keep getting the error, ??? Error using ==> optim\private\lsqncommon at 98 LSQCURVEFIT cannot continue because user supplied objective function failed with the following error: Error using ==> mrdivide Matrix dimensions must agree. Error in ==> lsqcurvefit at 182 [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ... Error in ==> MonneyLSQ at 4 [x,resnorm]=lsqcurvefit(@MooneyRivlin,x0,xdata,ydata) Any suggestions for this rather annoying error would be much appriciated thankyou. Nic
From: Alan Weiss on 21 Jun 2010 14:12
I believe you forgot several . in your objective function: F=(2*x(1)+2*x(2)/xdata)*(xdata-1/xdata^2); should be F=(2*x(1)+2*x(2)./xdata).*(xdata-1./(xdata.^2)) At least, I think my edited F captures what you mean. Try F outside of lsqcurvefit to make sure it is returning what you want. Alan Weiss MATLAB mathematical toolbox documentation On 6/21/2010 11:00 AM, Nic Roberts wrote: > Hi > > i am trying to obtain to constants using 'lsqcurvefit' here's the code, > > xdata=stretch_r(:,2).'; > ydata=stress_r.'; > x0=[100; 1]; > [x,resnorm]=lsqcurvefit(@MooneyRivlin,x0,xdata,ydata) > > function F=MooneyRivlin(x,xdata) > F=(2*x(1)+2*x(2)/xdata)*(xdata-1/xdata^2); > > > Both 'stretch' and 'stress' are of length 14 but I keep getting the error, > > ??? Error using ==> optim\private\lsqncommon at 98 > LSQCURVEFIT cannot continue because user supplied objective function > failed with the following error: > Error using ==> mrdivide > Matrix dimensions must agree. > > Error in ==> lsqcurvefit at 182 > [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ... > Error in ==> MonneyLSQ at 4 > [x,resnorm]=lsqcurvefit(@MooneyRivlin,x0,xdata,ydata) > > Any suggestions for this rather annoying error would be much appriciated > thankyou. > > Nic |