MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NonlinearRegression


David Pires <l45337 at alfa.ist.utl.pt> wrote in message
news:8p9kit$1rm at smc.vnet.net...
> I want to fit my data with a function such as:
> f(x)=Sqrt(a-b*x), where a and b are the parameters I want to adjust and x
> is the variable. The problem is that there is only a given range of x for
> that f(x) has real values. When I use the NonlinearRegression (or
> NonlinearFit) command, Mathematica gives error messages and aborts the
> fitting process.
>
> I'd like to know if someone knows how to set the range of x when using
> that command.


Hi,

Here is a method I have used in the past.
Instead of fitting to f(x) = Sqrt[a-b*x], define the fitting function as

   f[a_,b_,x_] := If[a-b*x > 0, Evaluate[Sqrt[a-b*x]], 0]

as in the following example,


<< Statistics`NonlinearFit`

data = Table[{x, Sqrt[1 - 0.2x]}, {x, 0, 4, 0.3}]

func[a_, b_, x_] := If[a - b x > 0,  Evaluate[Sqrt[a - b x]],  0];
NonlinearRegress[data, func[a, b, x], {x}, {a, b}]

This seems to work fine.

Cheers,

     Bill





  • Prev by Date: Re: Displaying Mixed Numbers
  • Next by Date: Re: Displaying Mixed Numbers
  • Previous by thread: Re: NonlinearRegression
  • Next by thread: Mathematica 3.0/4.0