0% found this document useful (0 votes)
8 views1 page

Fixed Position

The document describes a MATLAB script for solving the equation e^(-x) - x = 0 using fixed-point iteration. It initializes parameters such as the true solution, initial guess, tolerance, and maximum iterations, and iteratively computes the next approximation while calculating relative and true errors. The script outputs the results of each iteration and indicates whether convergence is achieved within the specified limits.

Uploaded by

wonwoong5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Fixed Position

The document describes a MATLAB script for solving the equation e^(-x) - x = 0 using fixed-point iteration. It initializes parameters such as the true solution, initial guess, tolerance, and maximum iterations, and iteratively computes the next approximation while calculating relative and true errors. The script outputs the results of each iteration and indicates whether convergence is achieved within the specified limits.

Uploaded by

wonwoong5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

[Fixed-point]

% Fixed-point iteration to solve e^(-x) - x = 0


clear all;

% True solution for error calculation (approximately)


true_solution = 0.56714329; % Solution of f(x) = e^(-x) - x = 0

% Initial guess
x0 = 0; % Starting value
tol = 1e-6; % Tolerance for convergence
max_iter = 100; % Maximum number of iterations

% Header for output


fprintf('Iter\t x_n\t\t Rel. Error (%%)\t True Error (%%)\n');

for iter = 1:max_iter


% Fixed-point iteration formula: y_2 = exp(-x)
x1 = exp(-x0);

% Percent relative error calculation


if iter == 1
rel_error = NaN; % No relative error for the first iteration
else
rel_error = abs((x1 - x0) / x1) * 100;
end

% Percent true error calculation (if true solution is known)


true_error = abs((true_solution - x1) / true_solution) * 100;

% Print current iteration results


fprintf('%d\t %.6f\t %.6f\t %.6f\n', iter, x1, rel_error, true_error);

% Check for convergence


if abs(x1 - x0) < tol
fprintf('Converged to solution: x = %.6f after %d iterations.\n', x1, iter);
break;
end

% Update for next iteration


x0 = x1;
end

% If maximum iterations are reached without convergence


if iter == max_iter
fprintf('Did not converge within %d iterations.\n', max_iter);
end

You might also like