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

13 vues (au cours des 30 derniers jours)
mark
mark le 13 Mar 2012
Réponse apportée : Hafsa le 18 Août 2024
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 commentaires
mark
mark le 13 Mar 2012
trying .. i just need the first steps as in the direction i need to get starting .. im new to matlap
mark
mark le 19 Mar 2012
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

Connectez-vous pour commenter.

Réponses (2)

Sean de Wolski
Sean de Wolski le 13 Mar 2012
doc fsolve
If you have the Optimization Toolbox.

Hafsa
Hafsa le 18 Août 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

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by