I have been having an issue with my code, I am writting a direct method for finding a root from a user input. However, I spent an hour to debug my code with no improvement. A help from the community would be very apperciated.
The error message output is as follow:
Array indices must be positive integers or logical values.
Error in sym/subsref (line 870)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in direct_method (line 21)
fx_value(ii)=fx_given(x(ii))
thank you in advance, my code is as follow:
function Root_Found=direct_methodsyms xfx_given=input('Input the desired function:');x1=input('Input the lower limit guess value of the root:');x2=input('Input the upper limit guess value of the root:');fprintf("The chosen roots values: [x1,x2]=[%.1f,%.1f] \n",x1,x2);N=input('Input the number of iterations desired:');x=linspace(x1,x2,N)';fx_value=zeros(N);for ii=1:Nfx_value(ii)=fx_given(x(ii))endfigureplot(x,fx_value)title('Direct Method')xlabel('x')ylabel('y')grid onRoot_Found=fx_value;end
Best Answer