Thread Subject: leastsqr problem

Subject: leastsqr problem

From: Godzilla

Date: 26 Oct, 2009 20:19:06

Message: 1 of 1

Anybody have experience with non-linear fitting, specifically using leasqr.m

Here is my function:
%%% START
function y = leasqrfunc(x,px)
a = px(1);
b = px(2);
c = px(3);
p = px(4);

u = (x-c);

y = a + b./(u.^p);
%%% END

and here is the partial derivative function (4 parameters);
%%% START
function y = leasqrdfdp(x,f,px,dp,func)
% function is y = a + b/(x-c)^p
a = px(1);
b = px(2);
c = px(3);
p = px(4);

u = x-c;

y = [1.0 u.^(-p) b.*(-p).*(-1).*u.^(-p-1) b.*u.^(-p).*log(u).*(-1)];
% the above equation is all on one time
%%%% END


The program complains about ;

??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> leasqrdfdp
y = [1.0 u.^(-p) b.*(-p).*(-1).*u.^(-p-1) b.*u.^(-p).*log(u).*(-1)];

I've used leasqr before without a hitch but now I can't seem to figure out what I'm doing wrong in the partial function. I double checked the spaces between each partial and there are three spaces separating 4 partials, i.e. one for each parameter.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com