lsqnonlin question

8 visualizzazioni (ultimi 30 giorni)
Shalini
Shalini il 18 Apr 2012
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?

Risposte (2)

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

Accedi per commentare.


Shalini
Shalini il 18 Apr 2012
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 Commenti
Sean de Wolski
Sean de Wolski il 18 Apr 2012
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 il 18 Apr 2012
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

Accedi per commentare.

Categorie

Scopri di più su Optimization in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by