secant method help matlab
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
hi i have been asked to make a function file for secant menthod
fxi=f(xi);
fxi_1=f(xi_1);
% Initialize iteration count iter = 1;
%iteration for the secant starts while abs(fxi)>precsion
    xi=xi-(fxi/fxi_1);
    xi_1=(xi-f(xi).(xi_1-xi))/(f(xi_1)-f(xi))
    % Increment the iteration count by 1
    iter = iter + 1;
end %the final xr value is the root root=xi; % The total iteration number iter = iter - 1; this what i have done
when i run the values its gives this error(Attempted to access f(2); index out of bounds because numel(f)=1.) can anyone help ?
1 Kommentar
  Alberto
      
 am 22 Sep. 2014
				I think your code interpret f, not as a function, but as an array with values. So, when you are trying to evaluate f(x), where x=2, your code looks for the second values in an array f.
Advice: 1) save your bound points in variables a and b (for example). Also create a proper function f (inline function or m-file function), so you can evaluate f in a and b. You will need a while or for+if to make your iterations.
Antworten (0)
Siehe auch
Kategorien
				Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

