??? Error using ==> inline.subsref at 14 Not enough inputs to inline function.

6 views (last 30 days)
Hi everyone,
I'm trying to make a program that finds the roots of a function using the Secant method for a class project. In class we only use very simple Matlab commands so most of the stuff I found online was way over-complicated for me to understand and use.
So what's happening is I'm getting an error:
??? Error using ==> inline.subsref at 14
Not enough inputs to inline function.
Error in ==> secante at 9 z=b-((fx(b)*(b-a))/(fx(b)-fx(a)));
when running secante(0,2,0.000001) for the function (e^(-0.5*x))*(cos(3*x))-e^(-x)
If anyone can help me understand why this is happening and check if I'm making any other mistakes it would be deeply appreciated. Here's my code:
function R = secante(a,b,erro)
f=input('Inserir f(x)= ','s');
fx = inline(f);
e=(abs(b-a))/(abs(b));
n=3;
R(1)=a;
R(2)=b;
while (erro<e)
z=b-((fx(b)*(b-a))/(fx(b)-fx(a)));
a=b;
b=z;
e=((abs(b-a))/(abs(b)));
R(n)=z;
n=n+1;
end

Accepted Answer

Walter Roberson
Walter Roberson on 7 Dec 2013
MATLAB does not know the constant "e" and so thinks it is a variable. The user needs to enter
exp(-0.5*x)*cos(3*x)-exp(-x)
  1 Comment
Lionheart
Lionheart on 8 Dec 2013
You're absolutely right! I was messing with my code for 3 hours and after all it was the fuction that was wrong. Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!