How to use lsqlin while translating IDL code?

IDL function code for multiple linear regression without interception
if true
% code
Function Multi_regression, ind_v,dep_v,k,low,high
common V_PUB, matrix
common V_PUB2, y
nb=n_elements(dep_v)
x=reform(dep_v)
varend=fltarr(k)
yend=fltarr(k,nb)
for ii=0,k-1 do begin
varend[ii]=sqrt(total((ind_v[ii,*]-mean(ind_v[ii,*]))^2))
yend[ii,*]=ind_v[ii,*]
endfor
var=sqrt(total((dep_v-mean(dep_v))^2))
y=dep_v
matrix=yend
y=transpose(double(y))
glow=fltarr(k)+low
ghigh=fltarr(k)+high
gintial=fltarr(k)+1.0/float(k)
gbnd = [glow, ghigh]
Lbnd =[0,100]
nobj = 1
g = gintial
Lcomp = 'HMBL11'
nobj=0
CONSTRAINED_MIN, g, gbnd, Lbnd, nobj, Lcomp, inform
L =total((matrix ## g- y)^2)
return,g
END
end
if true
% code
FUNCTION HMBL11, g
common V_PUB
common V_PUB2
L=total((matrix ## g-y)^2)
RETURN, L
END
end ------------------------------------------
While translate IDL code to MATLAB code, 'lsqlin' is most difficult for me. Even I check the syntax of 'lsqlin', I don't know where I should check.
if true
% code
function [result] = Multi_regression(x_matrix, y_matrix, k, min_allow,max_allow)
global matrix
global y
nb= numel(y_matrix);
x=y_matrix;
varend=zeros(k);
yend=zeros(k, nb);
for ii=1:1:num_class
varend(ii)=sqrt(sum(reshape(x_matrix(ii,:),1,[]))-(mean(reshape(x_matrix(ii,:),1,[]))));
yend(ii,:)=x_matrix(ii,:);
end
var=sqrt(sum(y_matrix-mean(y_matrix))^2);
y=y_matrix;
matrix=yend;
x=matrix.';
y= y.';
glow = double(k)+min_allow;
ghigh = double(k)+max_allow;
gintial = double(k)+1.0/double(k);
g=gintial;
result=lsqlin(x,y,[],[],[],[],glow,ghigh,g);
END
end

Answers (0)

Asked:

on 22 Feb 2017

Edited:

on 22 Feb 2017

Community Treasure Hunt

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

Start Hunting!