Mathematica Asked on February 7, 2021
I think I figured out what was wrong. Since I was adding in Print[m]
after I ran the loop, I had to clear my variables if I wanted to run the loop again. I guess my new question is: why did I have to clear m
and x
? I tried to reevaluate F[x]
to reset the function, and I tried to rerun m = 3
after, but it just gave me strange results which I will attach below.
What happens when I rerun F[x_] = x^2 Cos[x] + x + 3
after running the loop.
Original issue starts here.
I’m running a For-loop (and it needs to be a For-loop) thats supposed to do Newton’s method on a function.
I’ll post the parts of the code that I think are needed to get the error
F[x_] = x^2 Cos[x] + x + 3
m = 3
For[i = 0, i < 5, i++,
F'[m];
y = F[m] + F'[m] (x - m);
x = (0 - F[m])/(F'[m]) + m;
Print[N[F[x]]];
m = x
All of this code here works fine. The moment I add Print[m]
or Print[x]
to the loop, it completely breaks and I do not know why. The picture below is the code working before I add in Print[m] anywhere in the loop.
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP