```Path: news.mathworks.com!not-for-mail
From: "Tom Lane" <tlane@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: multiple variable exponential regression
Date: Wed, 6 Nov 2013 12:30:21 -0500
Organization: MathWorks
Lines: 17
Message-ID: <l5dubd\$a97\$1@newscl01ah.mathworks.com>
References: <l58snn\$ikv\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: ah-tlane.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
format=flowed;
charset="UTF-8";
Content-Transfer-Encoding: 7bit
X-Trace: newscl01ah.mathworks.com 1383759021 10535 172.28.17.232 (6 Nov 2013 17:30:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 6 Nov 2013 17:30:21 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:804898

> I was using other nonlinear regression methods but was getting an
> imaginary solution (a+ib) form
...
> modelfun = @(b, x)((100 - 15*(x(2, :).^b(1)))) - (40*((x(3, :).^b(2)))) -
> (15*((x(4, :).^b(3)))) x = TestData;
> y = x(1, :);
>
> [beta, R, J, CovB, MSE] = nlinfit(x, y, modelfun, beta0, opts);

One thing I see here is that you have not removed the y column from x, so
x(1,:) will refer to the same thing as y. In general, if you have any
negative x values this could yield imaginary results as the nlinfit function
manipulates the b values. You could use abs() in your modelfun to avoid
that, but I don't know if that makes sense in your application.

-- Tom

```