Operands to the || and && operators must be convertible to logical scalar values. Need help
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Jan
2015-10-18
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
2015-10-18
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Data Analytics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!