How can I find the root of function without initial point?
I have a parametrized function, with one variable, N
a=@(N)(something)
How can I find the values of N without initial point , where a=0 ? ... I've tried fzero but apparently it works only with initial value. Please help

 Respuesta aceptada

Cristian Garcia Milan
Cristian Garcia Milan el 22 de Mayo de 2020
Editada: darova el 22 de Mayo de 2020

2 votos

You have to use a initial value (it can be 0). The fzero function uses a combination of bisection, secant, and inverse quadratic interpolation methods, but have to look around a point.
Actually, it doesn't really matter how precisse you are, but the problem could be that the function reaches it maximum number of iterations (which you can modify) before it get you the root value.

6 comentarios

Ani Asoyan
Ani Asoyan el 22 de Mayo de 2020
So there's no option to not choose initial value?
Cristian Garcia Milan
Cristian Garcia Milan el 22 de Mayo de 2020
No. But maybe if you tell us more about your function i could help finding a x0.
I would recommend use x0=0 if you dont know where to start.
Ani Asoyan
Ani Asoyan el 22 de Mayo de 2020
ok,, it's a function with the following parameters,
a=2, b=2, c=1, d=0.5, e=0.9, l=0.5 , m=0.7, n=0.4
fun=@(N) (-c*l.*(N.^(l-1))+d.*e-m.(b-m.*N.*e).*e/a+2*e.*n.*N)
Cristian Garcia Milan
Cristian Garcia Milan el 22 de Mayo de 2020
Editada: Cristian Garcia Milan el 22 de Mayo de 2020
Okey. I have used
fun=@(N) (-c*l.*(N.^(l-1))+d.*e-m.*(b-m.*N.*e).*e/a+2*e.*n.*N)
(with an extra * betwenn m and (b-m.*N.*e)
There are some extra . but it doen't matter.
I see why you can't use x0=0, you have a divergence there. In that case you can use x0 = 1. Actually it worked for me with:
a=2; b=2; c=1; d=0.5; e=0.9; l=0.5; m=0.7; n=0.4;
fun=@(N) (-c*l.*(N.^(l-1))+d.*e-m.*(b-m.*N.*e).*e/a+2*e.*n.*N);
fun(fzero(fun,1))
ans =
0
Ani Asoyan
Ani Asoyan el 22 de Mayo de 2020
Ok thank you ...but changing initial value I get different results...
Ani Asoyan
Ani Asoyan el 26 de Mayo de 2020
thank you !

Iniciar sesión para comentar.

Más respuestas (1)

Abdolkarim Mohammadi
Abdolkarim Mohammadi el 22 de Mayo de 2020
Editada: Abdolkarim Mohammadi el 22 de Mayo de 2020

1 voto

Finding values of inputs that minimizes or maximizes an objective function is an optimizaiton problem. I don't know about your function, but If your function is linear, then you run the following code and optimize your function:
[x, fval] = linprog (u_g, [], []);
If your function is unimodal and relatively smooth, then you run the following code and optimize your function:
[x, fval] = fmincon (u_g, x0, [], []);
Be aware that fmincon uses an initial point x0. If the landscape of your function is unknown, i.e., you don't know whether it is linear, nonlinear, multi-modal, non-smooth, etc, then you run the following code and optimize your function:
[x, fval] = ga (u_g, nvars);
Where nvars i the number of variables. You can refer to the documentation of each solver for more information. Finding the roots of a function is translated into an optimization problem as f(x) = 0; so you need to provide this as a constraint to the solvers mentioned above or any other solvers.

3 comentarios

Ani Asoyan
Ani Asoyan el 22 de Mayo de 2020
thank you but sorry I don't quite understand how I will translate finding the root into an optimization problem.... I don't want to maximize or minimize the function, I want to see where it will be equal to zero.
Abdolkarim Mohammadi
Abdolkarim Mohammadi el 22 de Mayo de 2020
Editada: Abdolkarim Mohammadi el 22 de Mayo de 2020
In terms of an optimization problem, your objective function to be minimized is the differnence of the value of your function from zero. Your objective function would be something like this: "Min |f(x)-0|". You can also define your problem as a feasiblity problem (you can take a look at this comment). This way you have "Min 0; subject to f(x)==0". However, each run of the optimization problem gives you one of possibly many zeros of the function or might never give you some of the zeros.
Ani Asoyan
Ani Asoyan el 26 de Mayo de 2020
thank you !

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 22 de Mayo de 2020

Comentada:

el 26 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by