Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to judge the existence of a fzero equation?

조회 수: 1 (최근 30일)
Ziqiang Gao
Ziqiang Gao 2016년 4월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Maneet Goyal
Maneet Goyal 2016년 4월 8일
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 2016년 4월 8일
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);

답변 (1개)

Maneet Goyal
Maneet Goyal 2016년 4월 8일
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!

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by