How can i find a fit for a data set with an user defined function?

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)

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

i cannot install the curve fit toolbox, because i'm using Matlab from my school server(the product is not installed on my pc).

Sign in to comment.

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

my problem is that i don't have any initial parameters. however the data set itself is pretty close to the solution. is there a way around without using the initial parameters?
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.
when i enter the last line i get this error:
Undefined function or variable 'fcn'.
Error in @(b)norm(x-ro(fcn(b,y)))
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Change
RNCF = @(b) norm(x - ro(fcn(b,y));
to
RNCF = @(b) norm(x - ro_fcn(b,y));
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: 14.121855
@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!

Sign in to comment.

Categories

Products

Asked:

on 30 Oct 2017

Commented:

on 31 Oct 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!