Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solving system of equations using Matlab: Question 4 (5 points) Find a solution

ID: 2303980 • Letter: S

Question

Solving system of equations using Matlab:

Question 4 (5 points) Find a solution for the following nonlinear system of equations using Newton method: 3r-cos(y2)-1=0, a2- 81(y +0 e-+20z + 10T - 3 0.1) +sin(z) +1.06 0, As an initial guess, use 2.1 = [0.1 0.1-0.1]. Make your program to display the kth guess = [zk yk 2kjin each iteration of Newton method. Choose the number of iterations such that l2-norm of the difference between the new guess and the old guess, i.e., IPr-rh-1112, is of the order 10-5. (Computer)

Explanation / Answer

This is the code for Newton method to solve a system of three non-linear equations. This is from my assignment, where I had to input the functions and other limits. The code prompts the user to enter the equations.

disp(' ')
f1name = input('The first function is (between single quotes): f1(x,y,z) = ');
f2name = input('The second function is (between single quotes): f2(x,y,z) = ');
f3name = input('The third function is (between single quotes): f3(x,y,z) = ');
gradf1 = [diff(f1name,'x') diff(f1name,'y') diff(f1name,'z')] ;
gradf2 = [diff(f2name,'x') diff(f2name,'y') diff(f2name,'z')];
gradf3 = [diff(f3name,'x') diff(f3name,'y') diff(f3name,'z')] ;
wa = input('Initial values [xo yo zo] = ');wa= wa';
tol = input('Tolerance: ');
nitermax = input('Number of iterations k = ');
disp('')
disp('--------------------------------------------------')
disp('')
disp('Roots of Functions by Method of Newton')
disp('--------------------------------------------------')
t1 = 'The first function is: f1(x,y,z) = ';
t2 = 'The second function is: f2(x,y,z) = ';
t3 = 'The third function is: f3(x,y,z) = ';
disp([t1 f1name]);
disp([t2 f2name]);
disp([t3 f3name]);
disp(sprintf('The initial values are xo = %- 4.2f, yo = %- 4.2f and zo = %- 4.2f',wa(1),wa(2),wa(3)))
disp(sprintf('The maximun number of iteration is k = %3.0f and the tolerance is: %4.2e', nitermax,tol))
disp('-----------------------------')
disp('')
disp(' k x(k) y(k) z(k) f1(x(k),y(k),z(k)) f2(x(k),y(k),z(k)) f3(x(k),y(k),z(k))')
disp('---------------------------------------------------------------------------------------------------------------------------------')
x = wa(1);
y = wa(2);
z=wa(3);
fw1 = eval(f1name);
fw2 = eval(f2name);
fw3 = eval(f3name);
fxo = [fw1;fw2;fw3];
f1pw = eval(gradf1);
f2pw = eval(gradf2);
f3pw = eval(gradf3);
fpxo =[f1pw;f2pw;f3pw];
if det(fpxo)==0
disp('Error: determinant of Jacobian is zero, try another initial point ')
else
iter = 0;
s1 = sprintf('%3.0f %- 10.4f %- 10.4f %- 10.4f',iter,wa(1),wa(2),wa(3));
s2 = sprintf(' %- 10.4f %- 10.4f %- 10.4f',fw1,fw2,fw3);
disp([s1 s2])
while (norm(fxo)>tol) & (det(fpxo)~=0) & (iter<nitermax)
iter = iter + 1;
wan = wa - inv(fpxo)*fxo;
wa = wan;
x = wa(1);
y = wa(2);
z = wa(3);
fw1 = eval(f1name);
fw2 = eval(f2name);
fw3 = eval(f3name);
fxo = [fw1;fw2;fw3];
f1pw = eval(gradf1);
f2pw = eval(gradf2);
f3pw = eval(gradf3);
fpxo =[f1pw;f2pw;f3pw];
if det(fpxo)==0
disp('Error: determinant of Jacobian is zero, try another initial point ')
end
s1 = sprintf('%3.0f %- 10.4f %- 10.4f %- 10.4f',iter,wa(1),wa(2),wa(3));
s2 = sprintf(' %- 10.4f %- 10.4f %- 10.4f',fw1,fw2,fw3);
disp([s1 s2])
end
root = wa;
disp(sprintf(' The Root are: x = %- 6.4f, y = %- 6.4f, z = %- 6.4f',wa(1),wa(2),wa(3)))
end   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote