Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve the following nonlinear system using Newtons method in Matlab (use newton.m ): 0 = x2 y sin(z) + 1, 0 = x + 1

Solve the following nonlinear system using Newtons method in Matlab (use newton.m ): 0 = x2 y sin(z) + 1, 0 = x + 1 + sin(10y) y, 0 = (1 x)z y. Include a command to check that your solution is a root (or close to) by plugging the answer back into your function. Hint: You need to find a suitable starting value for x, y, and z so that the method converges. Bonus: Can you find more than one root? Submit hw06q3.m and make sure the definitions of your functions f and f are also included

newton.m

function [root,numits] = newton(fun,gradfun,x0,tol) % Solve fun(x)=0 using Newton's method given the function and its gradient % gradfun starting from the initial guess x0. x0 = x0(:); % this will force x0 to be a column vector xold = x0+1; % this needs to be ~= x0 so that we enter the while loop xnew = x0; numits = 0; n = length(x0); %data_x=[xnew(1)]; %data_y=[xnew(2)]; while norm(xnew-xold)>tol gradfxk = gradfun(xnew); fxk = fun(xnew); fxk = fxk(:); % this will force fxk to be a column vector [a,b]=size(fxk); if a~=n || b~=1 error('function has wrong dimension, expecting %d x 1, but got %d x %d',n , a, b) end [a,b]=size(gradfxk); if a~=n || b~=n error('gradient has wrong dimension, expecting %d x %d, but got %d x %d', n, n, a, b) end xold = xnew; #xnew = xold - (gradfxk)^{-1} * fxk, but implement as a linear solve xnew = xold - gradfxk \ fxk; numits = numits+1; plot(xnew(1), xnew(2),'-o','MarkerEdgeColor','black'); %xlim([-5 5]) %ylim([-80 10]) pause(0.1) if (numits>=100) root = xnew; fprintf('current step: ') disp(xnew) error('no convergence after %d iterations', numits); end end root = xnew; end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions