# Thread: Matlab Newton's method help

1. ## Matlab Newton's method help

i have two nonlinear equations
y=x.^3+x;
y=((5-x.^2)/2).^(1/3);

im trying to make a program where u input an (x,y) and it gives you in iterations i.e. (x1,y1) (x2,y2).. and it solves for the intersection. im confused on how to do this with 2 equations im only familiar with doing it with 1

edit:
basically have to do this
Use the Newton’s method to obtain the first (x1, y1), second (x2,y2) , third (x3,y3) , …, up to tenth (x10,y10) improvements of the solution. Is this a convergent sequence? Otherwise change the initial guess (x,y) until you get a convergent sequence.

i did this to solve for the point
>> x=linspace(0,2);
>> y1=x.^3+x;
>> y2=((5-x.^2)/2).^(1/3);
>> plot(x,y1,x,y2)
>> f1 = @(x) ((5-x.^2)/2).^(1/3);
>> f2 = @(x) (x.^3+x);
>> pt = fzero(@(x) f1(x)-f2(x),.8)

pt =

0.7950

>> coord = [pt,f1(pt)]

coord =

0.7950 1.2974

2. Use a for loop with a simple implementation of the Newton-Raphson method.

Code:
clear;clc;
x = 2;%initial guess
iters = 10;%num of iterations
h = 1e-6;%step size
f = @(x) ((5-x.^2)/2).^(1/3)-(x.^3+x);
i = 0;
while i <= iters;
fprintf('Iteration %g :  x = %0.3f\n',i,x)
df = (f(x+h)-f(x))/h;
x = x-f(x)/df;
i = i + 1;
end
Results in:
Code:
Iteration 0 : x = 2.000
Iteration 1 : x = 1.345
Iteration 2 : x = 0.959
Iteration 3 : x = 0.814
Iteration 4 : x = 0.795
Iteration 5 : x = 0.795
Iteration 6 : x = 0.795
Iteration 7 : x = 0.795
Iteration 8 : x = 0.795
Iteration 9 : x = 0.795
Iteration 10 : x = 0.795
Elbarto