creating a function to solve non linear equations using simple iteration method
10 views (last 30 days)
Show older comments
Create a Matlab function named (solveIteration) for solving a non-linear equation using (Simple iteration method) and takes the following inputs: g: function, x0 initial guess TolX as Termination tolerance on the function value, a positive scalar (when to stop iteration) and Maxiter as the max number of iterations if reached means the function has no solution The function returns the following outputs : x as a root(s) of the equation ,error as error message if the equation has no solutions Function seems like below one: function [x,error] = solveIteration(g,x0,TolX,MaxIter) ...
any hints ??
3 Comments
Answers (2)
Hafsa
on 18 Aug 2024
n = 3;
a = rand(n, n);
b = rand(n, 1);
% solve a * x + exp(x) = b for x
x = zeros(n, 1);
for itr = 1: 10
x = x - (a + diag(exp(x))) \ (a * x + exp(x) - b);
end
0 Comments
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!