Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to judge the existence of a fzero equation?

2 visualizaciones (últimos 30 días)
Ziqiang Gao
Ziqiang Gao el 8 de Abr. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
This codes are just a example of my troubles. I need to solve a fzero equation and judge whether it has solution or not.(Must be fzero I think.) If yes, I can use that value. if not, I can know and do others. I try to use 'exist', but I just get an error. It's my pleasure to receive your help. Thank you so much.
%
phi=@(t1) t1*t1;
beta=@(t1) -1;
fun=@(t1) phi(t1)-beta(t1);
x0=[0 9];
z=fzero(fun,x0);
A = exist('z','var');
disp(z)
disp(A)
--------------
Error using fzero (line 274)
The function values at the interval endpoints must differ in sign.
Error in Untitled (line 5)
z=fzero(fun,x0);
I will very grateful if you can give me a correct code to achieve this. Thanks.
  2 comentarios
Maneet Goyal
Maneet Goyal el 8 de Abr. de 2016
Hi:
Can you upload an image of the equation you want to solve?
fzero is basically a modified version of the bisection method. So, your initial guesses should be such that f(guess 1)*f(guess 2) < 0 (a negative value). Or simply put, their signs should be different.
Ziqiang Gao
Ziqiang Gao el 8 de Abr. de 2016
Sure. When I saw you explanation, I realize that I don't have to use fzero.If you prefer, you can use solve, maybe? Here is my equation. I want to get the result when phi=beta. The angle '(pi/4)' is a variables, so it depend on the random number generater. So please help. Thanks a lot.
%
phi=@(t1) (15*10^(-6)*sin(2.76*10^7*(1.5*10^(-7)+t1)))/(200*10^(-6));
beta=@(t1) abs(414*t1*cos(pi/4)-18*10^(-6))/(200*10^(-6)-414*t1*sin(pi/4));
fun=@(t1) phi(t1)-beta(t1);
x0=[0 2.28*10^(-7)];
z=fzero(fun,x0);

Respuestas (1)

Maneet Goyal
Maneet Goyal el 8 de Abr. de 2016
We don't need to use 'fsolve' because your equation is a non-linear equation in single variable. So using 'fzero' would be sufficient.
I merged phi-beta into a single function, gaofun (Hope you dont mind me using your name :) ). Function:
function out = gaofun(t1)
out = ((15*10^(-6)*sin(2.76*10^7*(1.5*10^(-7)+t1)))/(200*10^(-6))) - (abs(414*t1*cos(pi/4)-18*10^(-6))/(200*10^(-6)-414*t1*sin(pi/4)));
end
Function Driver:
fzero(@(t1) gaofun(t1),[0.5*1e-6,1*1e-6])
Results:
ans =
6.8319e-07
You should always make an appropriate choice of initial guesses while using fzero. For doing that, consider plotting the error function (phi-beta) v/s t1. I have done the same:
This would give you an idea regarding the guesses to be made.
Best of Luck!

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by