help with fzero function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,I don't know why this is not correct. Could you please help me to modify it.
phi=3+t1;
beta=2*t1;
fun=@(t1) phi-beta;
x0=[1 9];
z=fzero(fun,x0);
disp(z)
----------------
and the command window shows
Error using fzero (line 242)
Function values at interval endpoints must be finite and real.
Error in Untitled (line 5)
z=fzero(fun,x0);
Please help. Thank you very much. If you can make it correct, I will really appreciate this.
0 Kommentare
Antworten (1)
Star Strider
am 5 Apr. 2016
You have to make anonymous functions out of ‘phi’ and ‘beta’, and then refer to them as functions in the fzero call:
phi = @(t1) 3+t1;
beta = @(t1) 2*t1;
fun=@(t1) phi(t1)-beta(t1);
x0=[1 9];
z=fzero(fun,x0);
disp(z)
1 Kommentar
John D'Errico
am 5 Apr. 2016
Think of it like this. As you wrote it, phi is NOT a function. It is a simple variable that takes on some known value, as long as t1 is already defined.
phi=3+t1;
beta=2*t1;
So, whatever t1 was at that point, phi is just a number, NOT a function. Had t1 not been defined before that point, MATLAB would have generated an error, telling you that t1 was undefined.
As Star points out, you can explicitly define phi and beta as functions of some parameter (call it t1), and then use them in the function fun.
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!