Operands to the || and && operators must be convertible to logical scalar values. Need help
2 views (last 30 days)
Show older comments
A=1.202E6;
kB=1.38E23;
f=(1.5*1.6E-19:0.25*1.6E-19:7*1.6E-19);
J=2.735E8;
fzero(@(T) A*T^2*exp(-f/(kB*T))-J,2000)
I got this error messageOperands to the and && operators must be convertible to logical scalar valuesError in fzero (line 308) elseif ~isfinite(fx) ~isreal(fx)
Can anyone help me with this? Thanks
0 Comments
Answers (2)
Jan
on 18 Oct 2015
The function must return a scalar value. Due to the vector f your function replies several outputs, wo how can fzero find a zero?
Walter Roberson
on 18 Oct 2015
You did not constrain your answer at all, so there is nothing stopping fzero from looking at larger and larger T to try to find a zero crossing. Eventually you get to the point where you hit floating point overflow. Try guesses closer to 0.
There are two solutions that are the negatives of each other. If you do not want negative solutions than you can use 0 as the lower bound when you fzero.
The analytic solutions are at (1/2)*f(i)/(kB*LambertW( +/- (1/2)*sqrt(A*f(i)^2/(kB^2*J))))
0 Comments
See Also
Categories
Find more on Financial Data Analytics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!