Info
This question is closed. Reopen it to edit or answer.
How to judge the existence of a fzero equation?
1 view (last 30 days)
Show older comments
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 Comments
Maneet Goyal
on 8 Apr 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.
Answers (1)
Maneet Goyal
on 8 Apr 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!
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!