作业帮 > 综合 > 作业

请Matlab高手看看我的程序问题出在哪

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/10 00:27:55
请Matlab高手看看我的程序问题出在哪
用Levenberg-Marquardt法进行非线性拟合,运行发现前后维数不匹配,方程是D=a*t^b,其中D和b的数据在开头引用了,
syms a b y x real;
f=a*(x^b);
Jsym=jacobian(f,[a b])
A=textread('data.txt');
data_1=A(1:100,1:1);
obs_1=A(1:100,2:2);
a0=10; b0=0.5;
Ndata=length(obs_1); %the number of data
Nparams=2; %dimension of parameters
n_iters=50;
lamda=0.01; %fudge factor
updateJ=1; %variable assignment
a_est=a0;
b_est=b0;
for it=1:n_iters
if updateJ==1
J=zeros(Ndata,Nparams);
for i=1:length(data_1)
J(i,:)=[(data_1(i)^b_est)+a_est*data_1(i)*(data_1(i)^b_est)]; %compute Jacobian Matrix
end
y_est = a_est*(data_1^b_est);
d=obs_1-y_est; %compute the error
H=J'*J; %compute Hessian Matrix
if it==1 % if it is the first iteration,calculate the error
e=dot(d,d);
end
end
H_lm=H+(lamda*eye(Nparams,Nparams));
dp=inv(H)*(J'*d(:)); %compute the step
g = J'*d(:);
a_lm=a_est+dp(1);
b_lm=b_est+dp(2);
y_est_lm = a_lm*(data_1^b_lm); %compute the new y and error corresponding to the estimate value
d_lm=obs_1-y_est_lm;
e_lm=dot(d_lm,d_lm);
if e_lm
请Matlab高手看看我的程序问题出在哪
你没有正确使用点乘,y_est = a_est*(data_1^b_est)应改为y_est = a_est*(data_1.^b_est);y_est_lm = a_lm*(data_1^b_lm)改为y_est_lm = a_lm*(data_1.^b_lm)就OK了.中间一定要加“.”.