- #1
danbone87
- 28
- 0
Hi, I have this for loop where i want it to iterate for a variable ap = ap-1 -f(x)
and i want ap-1 to replace ap in each iteration.
It's pretty simple but i just can't get it to work out. any help would be appreciated and here's my code btw.
clc
a=1
fa=exp(a)*((-a^2)+(2*a)-2)+2.723684615938410;
fprimea=exp(a)*(a^2);
ap=a+(fa/fprimea);
tol=1*(10^-6);
f=abs(ap-a);
n=15;
for k=1:10
ap=a-(fa/fprimea);
f=abs(ap-a)
a=ap
end
and i want ap-1 to replace ap in each iteration.
It's pretty simple but i just can't get it to work out. any help would be appreciated and here's my code btw.
clc
a=1
fa=exp(a)*((-a^2)+(2*a)-2)+2.723684615938410;
fprimea=exp(a)*(a^2);
ap=a+(fa/fprimea);
tol=1*(10^-6);
f=abs(ap-a);
n=15;
for k=1:10
ap=a-(fa/fprimea);
f=abs(ap-a)
a=ap
end