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

조회 수: 5 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 7일
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
Lionheart
Lionheart 2013년 12월 8일
You're absolutely right! I was messing with my code for 3 hours and after all it was the fuction that was wrong. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by