Determine the roots of the following simultaneous nonlinear equations using
(a) fixed-point iteration and (b) the newton-Raphson method.
y = -x^2 + x + 0.75
y + 5xy =x^2
Employ initial guesses of x = y = 1.2 and discuss the results.
x = -1:-.25;
y = -1:5;
fx = @(x,y) y + x .^2 - .75; %solved for y
fy = @(x,y) (-5 .* x .* y) + x .^2 ;%solved for y
%fy = @(x,y) (-5 .* y + 1) .* x ;%solved for y
%fy = @(x,y) -x .^2 + x + .75; %solved for y
%fx = @(x,y) sqrt((5 .* x .* y) + y) ;%solved for y
%fx = @(x,y) sqrt(-y + x - .75); %solved for y
%fy = @(x,y) (x .^2)/ (1 + 5*x) ;%solved for y
hold on
plot (fy(x,y))
plot (fx(x,y))
% newton-raphson for systems of non-linear equations
u = @(x,y) - x .^2 + x + .75 - y; % u derivitation by parts
v = @(x,y) y + 5 .* x .* y - x .^2;%v derivitation by parts
dudx =@(x,y) -2 * x + 1;
dudy = @(x,y) -1;
dvdx = @(x,y) 5*y - 2*x;
dvdy = @(x,y) 1+ 5*x;
%y1 = fy(x,y); first iteration of y
%x1 = fx(x,y);first iteration of x
%y2 = fy(x1,y1); second iteration of y
%x2 = fx(x1,y1);second iteration of x
x = 1.2;
y = .2;
for ii = 1:3
ny = fy(x,y);
nx = fx(x,y);
y = ny;
x = nx;
plot(x,y,'*r')
end
%guess
x = 4; y = 0;
denom = ((dudx(x,y) * dvdy(x,y)) - (dudy(x,y) * dvdx(x,y)));
for ii = 0:15
denominator = denom + ( denom == 0) ;
x_1 = x - (((u(x,y) * dvdy(x,y)) - (v(x,y) * dudy(x,y))) / denominator);
y_1 = y - (((v(x,y) * dudx(x,y)) - (u(x,y) * dvdx(x,y))) / denominator);
x = x_1;
y = y_1;
plot( x_1 , y_1, '*g')
end
hold off
When running the fixed point at the initial guesses specified, it diverges very quickly, so we chose to start the y at .2 instead because it is closer. Nevertheless, even after bringing the initial guess closer, it diverges after 4 iterations. The newton Raphson method was also rather inaccurate at first, but x=4, y=0 seemed to get quite close, though still not quite there.
No comments:
Post a Comment