필터 지우기
필터 지우기

Lsqcurvefit - multiple parameters - two variables

조회 수: 33 (최근 30일)
Cyril GADAL
Cyril GADAL 2017년 5월 15일
댓글: Cyril GADAL 2017년 5월 16일
Hello,
I'm currently working on a function of two variables of the type z=f(x,y), controlled by 4 parameters, and I would like to fit data I obtained to my theoretical function. I read detailed post about how to dit with lsqcurvefit, but a problem remains. This is how I did :
function Sigma = Sigma_funct(p,Var)
Sigma = f(p(1),p(2),p(3),p(4), x,y)
end
with lets say Var(1) = x and Var(2) = y. Then, I'm supposed to use the following syntax :
p0 = [3,1,2,10] ;
x = lsqcurvefit(@Sigma_funct,p0,[x y],Sigma_data) ;
However, my problem is that x and y have different size, meaning that Sigma_data isn't a squared matrix : I can't concatenate x and y. How am I supposed to do ?
Thanks for your answers !
P.S : Just to say it, f is linear neither in parameters nor in variables.
  댓글 수: 2
Torsten
Torsten 2017년 5월 16일
It's not clear what the size of the matrix "Sigma_data" is and what it contains.
Best wishes
Torsten.
Cyril GADAL
Cyril GADAL 2017년 5월 16일
편집: Cyril GADAL 2017년 5월 16일
You're right. So I have a vector x of size N and y of size M such that Sigma_data is of size N*M : I would then have for the theoretical values Sigma(i,j) = f(xi, xj) and then would like to fit this to Sigma_data using lsqcurvefit.

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2017년 5월 16일
p0 = [3,1,2,10] ;
xdata = zeros(numel(x)*numel(y),1);
ydata = reshape(Sigma_data,[numel(x)*numel(y),1]);
p_sol = lsqcurvefit(@(p,xdata)Sigma_funct(p,xdata,x,y),p0,xdata,ydata);
function Sigma = Sigma_funct(p,xdata,x,y)
Sigma_mat = f(p(1),p(2),p(3),p(4),x,y)
Sigma = reshape(Sigma_mat,[numel(x)*numel(y),1]);
end
Best wishes
Torsten.
  댓글 수: 5
Torsten
Torsten 2017년 5월 16일
편집: Torsten 2017년 5월 16일
The only thing that matters for "lsqcurvefit" is how the ydata-vector depends on the parameter vector.
The xdata-vector is only introduced to make things easier for you if the relationship between parameter vector and ydata-vector can be established easily by an equation of the form
ydata(i) = func(p,xdata(i)) (i=1,...,N*M)
e.g. for linear regression ydata(i) = p(1)+p(2)*xdata(i).
But this is not the case for your problem - so don't worry about the "xdata"-vector.
Best wishes
Torsten.
Cyril GADAL
Cyril GADAL 2017년 5월 16일
Understood.
Thank you very much for your time !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by