Asked by aymos
on 26 Jun 2018

Hi,

I have a semilog graph which must be fitted (in its linear region) using this equation: y = 6e17*B*log[(x+B)/B]

Can you please tell how can I obtain the value of constant B, using fun(@x) ?

Thank you so much in advance for your help !

Answer by Ameer Hamza
on 26 Jun 2018

Edited by Ameer Hamza
on 26 Jun 2018

If you have a vector of x and y values then you can use several functions to estimate B. The correct method to use depending on your definition of the error function. For example, if you want to estimate B by minimizing the MSE (mean square error) then use lsqcurvefit(). For example,

xdata = ...; % vector of x values

ydata = ...; % vector of y values

y = @(B, x) 6e17*B.*log((x+B)./B);

B_estmated = lsqcurvefit(y, 1, xdata, ydata);

^ initial point for the numerical optimization algorithm.

Similarly, if you have some other error function, then you can use fmincon().

Ameer Hamza
on 27 Jun 2018

I am defining an error metric. For example, if you have a vector of predictedOutput and actualOutput, then you want your predictedOutput to match the actualOutput. Therefore you define an error metric like this

error = predictedOutput - actualOutput;

Sum(error.^2)

the square of error is the most commonly used error metric. Unless there is some additional information given about the error metric, this error metric is used by default. So now if we are able to minimize the value of this error metric, it will mean that difference between predictedOutput and actualOutput is very small.

aymos
on 27 Jun 2018

Thanks Ameer.. and by what variable are you defining the predicted output ? (you are using y for both predicted and actual output?)

[~, y] = ode45(@(t,y) odefun(A, B, C, y), t, y0);

Ameer Hamza
on 27 Jun 2018

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Rik (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/407540-fun-x#comment_582846

## aymos (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/407540-fun-x#comment_582847

Sign in to comment.