Numerical Methods: (Bisect, Secant, False position, Newton Raphson) Error

5 visualizaciones (últimos 30 días)
Fahad Alismail
Fahad Alismail el 2 de Mzo. de 2017
Respondida: Jan el 3 de Mzo. de 2017
I'm trying to find the root of a function using Bisect, False position, Secant, and Newton/Raphson methods
But I keep getting this error: Any idea how to fix the problem?
False Position
i xl xu xr ea
Undefined function or variable "ea".
Error in falsepos (line 28)
b=[iter;xl;xu;xr;ea];
Error in Test_1 (line 21)
falsepos(y,0,20,0.005,100)
>>
My code is:
A=4002.24; %Average Entery Level
n=35; %Age of retirement
F=1500000; %Future Worth
i=0.3125; %Annual Interest
g=[0:.001:20]; %Geometric Gradient
y=A.*((1-(1+g).^n).*(1+i).^-n./(i-g)).*((1+i).^n)-F; %Future Worth Formula
plot(g,y),grid,title('Figure.1 Annual Raise'),xlabel('g'),ylabel('Future Worth')
format long
y=@ (g)A.*((1-(1+g).^n).*(1+i).^-n./(i-g)).*((1+i).^n)-F;
disp('Bisection')
bisect(y,0,20,0.005,100)
check_fp=y(ans)
disp('False Position')
falsepos(y,0,20,0.005,100)
check_fp=y(ans)
% disp('Newton Raphson Method')
% dy=@(x) A*((1-(1+x).^n.*(1+i).^-n)./(i-x).*(1+i).^n)-F; %derivative of y
% newtraph(y,dy,0.3,1,100)
% check_fp=y(ans)
disp('Secant')
secant(y,.5,.4,1,100)
check_fp=y(ans)
  1 comentario
Rik
Rik el 2 de Mzo. de 2017
What is the code inside falsepos doing? From this I can only see that you are calling it with 5 inputs. Is it expecting 6 inputs? When I get these kinds of errors it is usually that.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 3 de Mzo. de 2017
The error message tells you, that the variable "ea" is not defined. You did not post the code of the corresponding function "falsepos", so we do not have a chance to guess the reasons.
You can use the debugger to find out, what's going on: Set a breakpoint in the concerned function and step through the code line by line. Then you can see, why the creation of "ea" is not reached - or perhaps it is a typo only.

Community Treasure Hunt

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

Start Hunting!

Translated by