Stuck at Gauss-Newton Method code
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti

I am trying to make a code with a formula (𝑦 = 𝑎0 (1 − 𝑒 ^(−𝑎1𝑥 ))).
Help
x=[0.25,0.75,1.25,1.75,2.25];
y=[0.23,0.58,0.70,0.76,0.79];
disp('iterations a0 a1 da0 da1')
tol= 10^-8;
a=[0.5 1];
error=1;
n=length(x);
itermax=100;
for iter=1:itermax
a0=a(1);
a1=a(2);
for i=1:n
f(i)=a0*(1-exp(-a1.*x(i)));
j(i,1)=1-exp(-a1.*x(i));
j(i,2)=a0*a1*exp(-a1.*x(i));
d(i)=y(i)-f(i);
end
da=(j'*j)\(j'*d');
a=a+da';
out= [iter a da']
disp(out);
if (abs(da(1))<tol && abs(da(2))<tol)
break
end
end
x1=min(x);
x2=max(x);
xx=linspace(x1,x2,100);
yy=(a0*xx).*(1-exp(-a1*xx));
p=plot(xx,yy,x,y,'o');
2 Commenti
Risposte (2)
Walter Roberson
il 5 Mag 2022
your j 2 is the derivative with respect to x, but you need it to be the derivative with respect to a1 which is a0*x*exp(-a1*x)
2 Commenti
Walter Roberson
il 5 Mag 2022
da=(j'*j)\(j'*d');
I am clear why you do not factor out the j' giving you
da = j\d';
?
Vedere anche
Categorie
Scopri di più su Animation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
