MATLAB Answers


non-linear fitting with min(sse) of x

Asked by Pakorn
on 23 Nov 2012

Hi there, I have X1, X2 and Y1 data set and a function of x=f(y,B), but not y=g(x,B), where B is a vector of parameters. Unfortunately, the inverse function of f can't be solved analytically. So I am stuck with x=f(y,B).

The problem is I want to estimate the parameter values of the function, based on X1 and Y1, so that I can use it to estimate Y2 from X2, numerically.

Is it possible at all to estimate parameter values based on SSE regarding Y1, and not X1? and nlinfit do not seem to offer the option.

Cheers, PA


Why in your reckoning is it less appropriate to minimize


than it is to minimize


I am terribly sorry. I want to estimate B based on min(SSE regarding Y1). That is I have x=f(y,B), but I want to calculate SSE on the horizontal axis (axis of Y1). Normal functions doesn't seem to offer this.

There is a good reason for this. I want to predict Y2 (response variable) from X2 (explanatory variable), but I only have x=f(x,B). Function with B estimated based on min(SSE regarding Y1) will predict Y2 more correctly, with respect to X1-Y1 relationship, since it minimises the error of the (soon-to-be-predicted) Y values.

Then see my Answer below.

Log in to comment.


No products are associated with this question.

1 Answer

Answer by Matt J
on 23 Nov 2012
Edited by Matt J
on 24 Nov 2012
 Accepted Answer

If you have the Optimization Toolbox, maybe you can express g(x,B) in the following way and pass it to your favorite solver,

 g=@(x,B) fsolve(@(y) f(y,B)-x  ,  y0);

You could also generalize this by making the initial guess y0 a more general function of (x,B), if you know a good custom initialization scheme.


Show 1 older comment

Is this what you meant?



f=@(y,B) ...

g=@(x,B) fsolve(@(y) f(y,B)-x,Y1);

SSE_Y=@(B) sum(power(g(X1,B)-Y1,2))



No, nothing I've given here has anything to do with solving for Y2 or assumes anything is given. It's just a way of computing the inverse g(x,B) for any pair (x,B) without knowing its explicit analytical form. I illustrate below with a simple function f(y,B)= y.^2 +B and compare it with its known analytical inverse gtrue(x,B)=sqrt(x-B). Instead of FSOLVE though, I use FMINSEARCH because I don't have the Optimization Toolbox.

 f=@(y,B) y.^2+B;
 y0=@(x,B) max(B,sqrt(abs(x))); %A heuristic initializer
 g=@(x,B) fminsearch(@(y) (f(y,B)-x).^2, y0(x,B));
 gtrue=@(x,B) sqrt(x-B);

We can now check whether g(x,B) and gtrue(x,B) give the same approximate values for different pairs of inputs x and B:

    >> gtrue(1,1), g(1,1)
    ans =
    ans =
    >> gtrue(2,1), g(2,1)
    ans =
    ans =
    >> gtrue(5,3), g(5,3)
    ans =
    ans =
    >> gtrue(15,5), g(15,5)
    ans =
    ans =

Right,thank you very much. You are very much appreciated. Ps. Btw, the code I put above should work, right?

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!