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

6 ビュー (過去 30 日間)
Lionheart
Lionheart 2013 年 12 月 7 日
コメント済み: Lionheart 2013 年 12 月 8 日
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 Center および File ExchangeScope 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