optimization problem using fminunc
이전 댓글 표시
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
Graham
2013년 8월 14일
DURGA PRAJAPATI
2021년 9월 5일
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
채택된 답변
추가 답변 (1개)
Alan Weiss
2013년 8월 14일
0 개 추천
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
카테고리
도움말 센터 및 File Exchange에서 Solver-Based Nonlinear Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!