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