View Single Post
May22-09, 07:22 PM
P: 109
Here is my code for part 1. Can someone help me check this? I am not sure if it's correct

clc, clear;
format compact;
format long
x = 2;
for count = 1:100 %Number of Iterations
a = log(2+x); %left hand side of equation
b = x; %right hand side of equation
if (a==b)
disp(count) %Number of iterations needed to get to answer
answer = x;
x = a; %Answer

f = 2; %x(k=0) = 2
for k = 1:count
d = log(2+f);
e = f;
c = d-answer; %x(k)-a, where a is my answer (for convergence)
axisy(k) = c; %put answers in an array
f = d;

g = log(-answer);
for k = 1:count
h = log(2+g);
i = g;
j = h-answer; x(k-1)-a, where a is the convergent answer
axisx(k) = j;
g = h;


2)For Newton-Raphson, is my f(x) = ln(2+x)-x?

then i use g(x)=x(k) - f(x)/f('x)

=x(k)-[ ln(2+x)-x] / (1/(2+x)+1) ???

Im not sure how to write a code for this. Ive searched online and have found a few codes, but nothing that I need
Should I do this by hand instead?