lsqnonlin question

6 次查看(过去 30 天)
Shalini
Shalini 2012-4-18
Consider the following code:
X(1:10304)=xlsread('qs_comp_2.xls',2,'G3822:G14125');
Y(1:10304)=xlsread('qs_comp_2.xls',2,'H3822:H14125');
X(10305:12631)=xlsread('comp.xls',3,'T4259:T6585');
Y(10305:12631)=xlsread('comp.xls',3,'U4259:U6585');
X0=[1012 1400 0.17 -0.0001];
lb = [1012;900;0.17;-0.0001];
ub=[1300;1600;0.3119;10];
StartAt = [1012;900;0.17;-0.0001];
options = optimset('MaxFunEvals',10000);
x=lsqnonlin(@(X0)fit_simp(X0,X,Y),StartAt,lb,ub,options);
[total_readings,epsilon_dot_QS,epsilon_dot_MR] = GetMRDetails;
for i=1:total_readings
Y_new(i)=(X0(1)+X0(2)*(X(i)^X0(3))+X0(4)*log(epsilon_dot_QS/epsilon_dot_MR));
end
Please can anyone help me here:
1) Is the final optimised vector X0 or is it x? That is: which id the final answer X0 or X 2)Is there anything I'm missing in this code?

回答(2 个)

Sean de Wolski
Sean de Wolski 2012-4-18
It is x, the output from lsqnonlin. It doesn't look like the above code ever uses the actual optimized value.
  1 个评论
Shalini
Shalini 2012-4-18
Please can you correct it-I shall be grateful.I'm new to matlab

请先登录,再进行评论。


Shalini
Shalini 2012-4-18
Why you think so?
My fit_simp function (see properly above) is as below
function diff = fit_simp(x,X,Y)
% This function is called by lsqnonlin.
% x is a vector which contains the coefficients of the
% equation. X and Y are the option data sets that were
% passed to lsqnonlin.
A=x(1);
B=x(2);
n=x(3);
C=x(4);
[total_readings,epsilon_dot_QS,epsilon_dot_MR] = GetMRDetails;
for i=1:total_readings
diff(i)=(A+B*(X(i)^n)+C*log(epsilon_dot_QS/epsilon_dot_MR));
diff(i)=diff(i)-Y(i);
end
  2 个评论
Sean de Wolski
Sean de Wolski 2012-4-18
That looks fine, it's that your call to LSQNONLIN generates a vector called 'x'. This vector is not used in the remainder of the code you showed us.
Shalini
Shalini 2012-4-18
ok, i will correct that- 2 questions:
1)IS optimisation code correct?
2) I want to outtput the adjusted R square, how to do that?
Shalini

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by