Filter löschen
Filter löschen

Format of return value of user defined function

1 Ansicht (letzte 30 Tage)
Md Monirul Islam
Md Monirul Islam am 18 Mär. 2017
Bearbeitet: Walter Roberson am 18 Mär. 2017
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 18 Mär. 2017
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

Weitere Antworten (0)

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by