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 - The Fusion of Science and Community**

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.

Loading...

Similar Threads - Matlab loop troubles | Date |
---|---|

Matlab Arduino-MATLAB communication using SerialEvent() for PID Loop | Oct 28, 2016 |

Matlab -- how can i use a FOR loop if I have 2 variables changing | Oct 12, 2016 |

Matlab What is wrong with this WHILE loop? | Aug 26, 2016 |

MATLAB sum loop issue | Feb 18, 2016 |

Simple MATLAB loop | Oct 30, 2015 |

**Physics Forums - The Fusion of Science and Community**