Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

g=@(x) exp(-x); x=-1:0.01:1; y=g(x); plot(x,y,x,x); [c,n,err]=fixed_point_iteration(g,0.5,1e-10,100) [c1,n1,err1]=fixed_point_iteration(g,0.5,1e-10,100) function [c,n,err]=fixed_point_iteration(g,x0,tol,N) x1=x0; x0=x0-1; n=0; c=0; c1=0; err=[]; while(abs(x1-x0)>tol) x0=x1; x1=g(x0); n=n+1; if(n==N) err=[]; c=[]; c1=[]; break; end

image text in transcribed

image text in transcribed

g=@(x) exp(-x);

x=-1:0.01:1;

y=g(x);

plot(x,y,x,x);

[c,n,err]=fixed_point_iteration(g,0.5,1e-10,100)

[c1,n1,err1]=fixed_point_iteration(g,0.5,1e-10,100)

function [c,n,err]=fixed_point_iteration(g,x0,tol,N)

x1=x0;

x0=x0-1;

n=0;

c=0;

c1=0;

err=[];

while(abs(x1-x0)>tol)

x0=x1;

x1=g(x0);

n=n+1;

if(n==N)

err=[];

c=[];

c1=[];

break;

end

end

c=x0;

c1=x0;

err=abs(x1-x0);

end

Can someone fix this code and make it run correctly?

X Fixed point method 7 solutions submitted (max: Unlimited) View my solutions Problem Summary Write a MATLAB function, called fixed_point_iteration that inputs a function, 8, an initial guess x_@, an error tolerance, tol, and a maximum number of iterations, N, and outputs the fixed point of g, obtained using the fixed point iteration, starting with x 0. Your function should have an error defined by E = |x_n-x_{n-1} ], and stop when the error is less than the tolerance, or if the number of iterations exceeds N - whichever happens first. Your function header should look something like: function [C, n, err] = fixed_point_iteration(g,xo, tol,N) Use the code you just developed to find the solution to the equations x= e* and x= 1, with an accuracy of 10-10 for x in [-1, 1]. State your initial guess, and how many iterations it took. 1+x Plot on the same graph, y = g(x) and y = x. Here c is the fixed-point solution and n the number of iterations the method takes. To avoid function/variable override, let g = e^{-x} and g1 = 1/(1+x). Furthermore, when you call the fixed_point_iteration function, do the following: [C, n, err] = fixed_point_iteration(g,x0, tol,N) [c1, n1, err1] = fixed_point_iteration(g1,xe1, tol,N1) The MATLAB function for e* is exp(-x). Fix This Solution Assessment: 2 of 3 Tests Passed (67%) Respect guidelines 34% (34%) Test first solution 33% (33%) * Test second solution Variable c1 has an incorrect value. 0% (33%) Total: 67%

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

Step: 3

blur-text-image

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Summarize the impact of a termination on the employee.

Answered: 1 week ago