Clear Filters
Clear Filters

Format of return value of user defined function

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 18 Mar 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

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!