Write 2 function files in matlab one for fixedpoint iterati
Write 2 function files in matlab : one for fixed-point iteration for a system of equations and one for Newton’s method for a system of equations. Determine what your inputs and outputs should be. Test the code on the following system. the code must also take convergence into consideration.
x2- y
x- y2
Solution
Matlab codes;
Main function;
%clearing window, variables and figures
 clear all;
 close all;
 clf;
 clc;
 fixed()
 newton()
 %fixed approach function
function fixed()
 fprintf(\'\ Fixed point approach\ \');
 syms x;
 f1=x; %first function
 f2=sqrt(x); %second function
 %for function 1;
 %equation is in terms of x,x=0;
 x=sym(0);
 fprintf(\'\ Value of function is 0 as x is already at zero\ \');
 %Checking convergence;
 f1dash=1 %Finding derivative f1 w.r.t x
 x=sym(0);
 fprintf(\'\ The first function converge as f1dash is constant\ \');
 fprintf(\'\ Value of function is 0 as x is already at zero\');
 %for function 2;
 %equation is in terms of x,x=0;
 x=sym(0);
 %Checking convergence;
 f2dash=(1/2)*(1/sqrt(x)); %Finding derivative w.r.t x
 fprintf(\'\ The second function converges as for negative infinity, absolute of f2dash is =0 or <1\ \');
 fprintf(\'\ Value of function is 0 as x is already at zero\');
%Newton raphson method approach
function newton()
 fprintf(\'\ Newton raphson approach\ \');
 syms x;
 f1=x; %first function
 f2=sqrt(x); %second function
 %for function 1;
 xo=sym(1);
 error=5;
 while(error>.01)
 f1dash=diff(f1,x);
 x=sym(xo);
 dx=-eval(f1)/f1dash;
 x1=xo+dx;
 x=sym(x1);
 fc=eval(f1);
 x=sym(xo);
 fe=eval(f1);
 error=fc-fe;
 xo=x1;
 end
 xo
 f2=sqrt(x); %second function
 %for function 1;
 xo=sym(1);
 error=5;
 while(error>.01)
 f2dash=diff(f2,x);
 x=sym(xo);
 dx=-eval(f2)/f2dash;
 x1=xo+dx;
 x=sym(x1);
 fc=eval(f2);
 x=sym(xo);
 fe=eval(f2);
 error=fc-fe;
 x0=x1;
 end
 xo
 fprintf(\'\ Both the functions converges for any value of x\ \');
Result;
Value of function is 0 as x is already at zero
f1dash =
1
 The first function converge as f1dash is constant
Value of function is 0 as x is already at zero
 The second function converges as for negative infinity, absolute of f2dash is =0 or <1
Value of function is 0 as x is already at zero
 Newton raphson approach
 
 xo =
 
 0
 
 
 xo =
 
 1
Both the functions converges for any value of x


