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? NonLinearModel.fit and nlinfit do not seem to offer the option.

Cheers, PA

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.

Pakorn
on 24 Nov 2012

Is this what you meant?

X1=[..;..;...]

Y1=[..;..;...]

f=@(y,B) ...

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

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

B=fminsearch(SSE_Y,B0)

Cheers

Matt J
on 24 Nov 2012

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 =

0

ans =

-8.8818e-16

>> gtrue(2,1), g(2,1)

ans =

1

ans =

1.0000

>> gtrue(5,3), g(5,3)

ans =

1.4142

ans =

1.4142

>> gtrue(15,5), g(15,5)

ans =

3.1623

ans =

3.1623

Pakorn
on 24 Nov 2012

Log in to comment.

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

Learn moreOpportunities for recent engineering grads.

Apply Today
## 3 Comments

## Matt J (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/54623-non-linear-fitting-with-min-sse-of-x#comment_112989

Why in your reckoning is it less appropriate to minimize

than it is to minimize

## Pakorn (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/54623-non-linear-fitting-with-min-sse-of-x#comment_113061

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.

## Matt J (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/54623-non-linear-fitting-with-min-sse-of-x#comment_113062

Then see my Answer below.

Log in to comment.