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

6 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Dic. de 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 comentario
Lionheart
Lionheart el 8 de Dic. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by