MATLAB: Problem with “Conversion to logical from sym is not possible.”

MATLABsyms logical

Hello, i am using a really simple example for this problem, which I just can't get to work. I tried most of the examples which where suggested in similiar topics. I defined this function:
function [FDInt] = mg(x)
if x<0.8686
FDInt = 1/(0.27+exp(-x));
else
FDInt = (4/(3*sqrt(pi)))*(x^2 + pi^2/6)^(3/4);
end
end
and I call it here:
syms EF
solve(mg(EF)==10^20, EF)
I get this error message: "Error in mg (line 3) if x<0.8686 " I tried using vpa(x) or double(x) without working. I think the solution should be really easy – however, I just can't get it to work. If someone could give me a hint, that would be nice 🙂

Best Answer

There seems to be only one value that meets that criterion. Just use an anonymous function and fzero:
mg = @(x) (x<0.8686).*(1./(0.27+exp(-x))) + (x>=0.8686).*((4./(3*sqrt(pi)))*(x.^2 + pi^2/6).^(3/4));
EF = fzero(@(x) mg(x)-1E+20, 1)
EF =
26.0470e+012
Related Question