Borrar filtros
Borrar filtros

Format of return value of user defined function

1 visualización (últimos 30 días)
Md Monirul Islam
Md Monirul Islam el 18 de Mzo. de 2017
Editada: Walter Roberson el 18 de Mzo. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by