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

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 Commento

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.

Accedi per commentare.

Risposte (1)

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.

Richiesto:

il 2 Mar 2017

Risposto:

Jan
il 3 Mar 2017

Community Treasure Hunt

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

Start Hunting!

Translated by