Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
How to judge the existence of a fzero equation?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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.
답변 (1개)
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!
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!