optimization problem using fminunc
Show older comments
Hi,
I am trying to do a parameter estimation on an experimental data set using matlab for the 1st time. I am confused how to do this exactly. I have a model built in one mfile which outputs a result for a random set of parameters [k, l, b, g] and my objective function to be minimized in another file.
I have been calling fminunc at the bottom of my model file and sending the output of the model and the experimental data to the objective function. A part of my code is below. I left out the body of it,"", below.
Model file:
global kg gp bp kb ;
k = 1; l=5; b=4; g=10; % Assign parameter values
x0 = [k,l,b,g];
"
"
"
"
nm=nl_mat';
[x,fval] = fminunc(@globalfun,nm)
_
My objective function is the following:
function f=globalfun(nm)
ydata=xlsread('graham.xlsx','Sheet12','a3:d102');
r1=(ydata-nm).^2;
r11=sum(sum(r1));
f=r11;
return
So when I execute my model file it seems the solver is trying to get to a solution. in the end it says that the initial point is a local minimum. Im not sure whether I have it laid out correctly or if the solver just wont work. I want it to back out new values for [k, l, b, g] that can enable my model data to fit my experimental data. any help would be appreciated.
Thanks
2 Comments
Graham
on 14 Aug 2013
DURGA PRAJAPATI
on 5 Sep 2021
function obj = objFunction(q)
data=readtable('solu6_deleted few rows VALUE-Mat1');
A=table2array(data);
yex=A(:,33);
x1=A(:,1);
x2=A(:,2);
f1=A(:,4);
f2=A(:,5);
T=A(:,3);
size(T)
yp=@prediction;
obj=norm(yex(':') - yp(':')).^2 ;
-----------------------
function yp = prediction(q,f1,f2,x1,x2,T)
% Unknown parameter
Q1=q(1);
Q2=q(2);
Q3=q(3);
yp=f1.*log(x1)+f2.*log(x2)+(Q1+Q2.*(f1-f2)+Q3.*(f1-f2).^2).*f1.*f2.*T./298;
can anyone please help me ...i am not able to run this code ...basically i want the minimize the obj value by optimizing the Q1,Q2,Q3 .
if any additional data required i will share.
I am new to this software ..so please help me
Accepted Answer
More Answers (1)
Alan Weiss
on 14 Aug 2013
0 votes
Also, it is bad practice to read in data during an objective function evaluation. Read the data in once, and pass it to your objective function via an anonymous function or nested function. And generally speaking, don't use global variables.
Alan Weiss
MATLAB mathematical toolbox documentation
Categories
Find more on Solver-Based Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!