Stuck at Gauss-Newton Method code

์กฐํšŒ ์ˆ˜: 45 (์ตœ๊ทผ 30์ผ)
seoung gi Sin
seoung gi Sin 2022๋…„ 5์›” 5์ผ
ํŽธ์ง‘: Torsten 2022๋…„ 5์›” 5์ผ
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
KSSV
KSSV 2022๋…„ 5์›” 5์ผ
What is the question? Where are you stuck?
seoung gi Sin
seoung gi Sin 2022๋…„ 5์›” 5์ผ
the plot does not correctly reflect the data.

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (2๊ฐœ)

Walter Roberson
Walter Roberson 2022๋…„ 5์›” 5์ผ
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
seoung gi Sin
seoung gi Sin 2022๋…„ 5์›” 5์ผ
Your advice is a bit helpful to me, but the graph still don't reflect the data at all.
Walter Roberson
Walter Roberson 2022๋…„ 5์›” 5์ผ
da=(j'*j)\(j'*d');
I am clear why you do not factor out the j' giving you
da = j\d';
?

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.


Torsten
Torsten 2022๋…„ 5์›” 5์ผ
ํŽธ์ง‘: Torsten 2022๋…„ 5์›” 5์ผ
Change
j(i,2)=a0*a1*exp(-a1.*x(i));
to
j(i,2)=a0*x(i)*exp(-a1.*x(i));
and
xx=linspace(x1,x2,100);
yy=(a0*xx).*(1-exp(-a1*xx));
to
xx=linspace(x1,x2,100);
yy=(a0).*(1-exp(-a1*xx));

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Programming์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

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

Start Hunting!

Translated by