creating a function to solve non linear equations using simple iteration method

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

You need to try and make a start, and when you get utterly stuck then post your code along with the problem you are having. If you want to learn to write code, you need to make an effort first.
trying .. i just need the first steps as in the direction i need to get starting .. im new to matlap
function [x,err] = solveit(g,x0,to,max)
syms x
x1=x0(1);
while subs(diff(g),x,x0)<=1
n=n+1;
if x1-subs(g,x,x1)<= to && n<= max
x1=subs(g,x,x1);
x=x1;
break
else
x=err;
end
end
end

댓글을 달려면 로그인하십시오.

답변 (2개)

Hafsa
Hafsa 2024년 8월 18일
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

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

질문:

2012년 3월 13일

답변:

2024년 8월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by