Format of return value of user defined function

1 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical 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