How can i find a fit for a data set with an user defined function?
Show older comments
I have a stress-strain data set from excel:
[x1 x2 x3 ...];
[y1 y2 y3 ...];
I want to fit the ramberg osgood model to the data set.
The equation is : x=y/210000+k*y^n
The constants are k and n. i need to find these constants. what would be the easiest way to solve this? The purpose of this is to get a fitting model for plastic deformation of steel.
I just started using Matlab btw, so i'm not very familiar with all the functions.
Answers (2)
Jos (10584)
on 30 Oct 2017
Take a look at fit. Also make sure you have your dependent and independent variables setup correctly. Usually y is expressed as a function of x, rather than the other way around.
FT = fittype('x./210000 + k.*x.^n') % y = f(x)
f0 = fit(x,y,FT)
1 Comment
Furkan Koc
on 30 Oct 2017
Star Strider
on 30 Oct 2017
One approach (using only MATLAB, no Toolboxes):
x = [ ... ];
y = [ ... ];
ro_fcn = @(b,y) y/210000 + b(1).*y.^b(2); % Model Function (k=b(1), n=b(2))
RNCF = @(b) norm(x - ro(fcn(b,y)); % Residual Norm Cost Function
B0 = [ ... ]; % Initial Parameter Estimates (2x1) Vector
[B, ResNorm] = fminsearch(RNCF, B0); % Estimate Parameters
NOTE — This is UNTESTED CODE. It should work.
Nonlinear parater estimation is very sensitive to the initial choice of parameter estimates (here ‘B0’), so choose a set that are reasonably close to the ones you expect to be the solution.
6 Comments
Furkan Koc
on 30 Oct 2017
Star Strider
on 30 Oct 2017
You have to use an initial parameter set, because the algorithm has to know where to start. All nonlinear parameter estimation algorithms require them. If you know what the parameter magnitudes and signs should be, any random set with the appropriate magnitudes and signs will work. One option is simply to use:
B0 = [1; 1];
If you have problems fitting your data, choose different initial parameters. You can also use a genetic algorithm (the Global Optimization Toolbox ga function) since it searches the entire parameter space to find a suitable parameter set. It also requires an initial parameter set, although it has the ability to choose those programmatically.
Furkan Koc
on 31 Oct 2017
Walter Roberson
on 31 Oct 2017
Change
RNCF = @(b) norm(x - ro(fcn(b,y));
to
RNCF = @(b) norm(x - ro_fcn(b,y));
Furkan Koc
on 31 Oct 2017
Star Strider
on 31 Oct 2017
@Furkan Koc — First, plot the fit using the returned value of ‘B’ to see how good the fit is. Then, either choose another set of initial parameter estimates (the best option) or use the optimset function to create an options structure with an increased value of 'MaxFunEvals'. (The ‘Current funciton value’ is the residual norm. Compare that with the mean of your dependent variable to see if the fit departed from the mean.)
Alternatively, use one of the Global Optimization Toolbox functions (my favourite is ga) to see if it will find an optimal set of parameters.
@Walter — Thank you!
Categories
Find more on Polymers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!