フィルターのクリア

Format of return value of user defined function

1 回表示 (過去 30 日間)
Md Monirul Islam
Md Monirul Islam 2017 年 3 月 18 日
編集済み: Walter Roberson 2017 年 3 月 18 日
i was using this function below to evaluate a non linear equation with False Position Method. this function is working pretty well but the value it returns is NOT in long format.
for example if i use this function to solve the following non linear equation,
f(x)=10-2.1*x-.01*x^3;
a=4;b=5;
then i get
z=50306586349162394761257938446687780/11523119672512394327137541804059681
how can i resolve this problem?
% this fuction evaluates the root of a equation with
% the use of False Position Method.
tol=1e-5;
FU=f(upper);
FL=f(lower);
while (abs(upper-lower)/upper)>tol
x=lower-((FL*(upper-lower))/(FU-FL));
FX=f(x);
if(FX*FL<0)
upper=x;
elseif(FX*FU<0)
lower=x;
else
break
end
end
end

採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 18 日
With difficulty. Your code does not assign anything to z and your code is not a function so we cannot guess that you assigned an output to z.
But mostly, do not use
syms x
f(x)=10-2.1*x-.01*x^3
Instead use
f = @(x) 10-2.1*x-.01*x^3
  1 件のコメント
Md Monirul Islam
Md Monirul Islam 2017 年 3 月 18 日
thanks a lot. it solved the problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by