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

Contact us at files@mathworks.com