早教吧作业答案频道 -->其他-->
请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('dat
题目详情
请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
用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
▼优质解答
答案和解析
你没有正确使用点乘,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了.中间一定要加“.”.
看了 请Matlab高手看看我的程...的网友还看了以下:
某人乘车从A市到B市,原计划上午多行100千米到C城吃饭,下午行完全程某人乘车从A市到B市,原计划上 2020-03-31 …
如图是绿色植物叶肉细胞中光合作用与需氧呼吸过程及其关系的图解,其中A-D表示相关过程,a-e表示有 2020-05-14 …
如图是绿色植物叶肉细胞中光合作用与有氧呼吸过程及其关系的图解,其中A-D表示相关过程,a-e表示有 2020-05-14 …
如图是植物某细胞中光合作用与有氧呼吸过程及其关系的图解,其中A-D表示相关过程,a-e表示有关物质 2020-05-14 …
请Matlab高手看看我的程序问题出在哪用Levenberg-Marquardt法进行非线性拟合, 2020-05-16 …
关于热力学定律的一个问题PV=RT(n就不写了)d(RT)=d(PV)=VdP+PdVdU=A+Q 2020-07-07 …
一位同学用电压表测电路两端的电压,试触时发现指针不动,在分析原因时,他作了如下判断,其中可能的是( 2020-07-07 …
某同学使用电流表测电路的电流,试触时发现电流表的指针不动,则故障可能是()A.电流表量程选小了B. 2020-07-13 …
某同学在做“用电压表测量电压”的实验时,发现指针偏转情况如图所示,出现该现象的原因是()A.量程选小 2020-11-26 …
e的导数是e还是0谢谢,那由方程e^y(e的y次方)+xy-e=o所确定的隐函数y的导数,这个例题对 2021-02-16 …