Hi, I have this for loop where i want it to iterate for a variable ap = ap-1 -f(x)(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab, for loop troubles.

**Physics Forums | Science Articles, Homework Help, Discussion**