Error using trustnleqn (line 28)
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm trying to solve non linear equations system using fsolve. I'm beginner in matlab I just have no idea what's going on with my program when I tried to run it, there's an error message in the command window:
function F = BEB(x)
n = 50; %number of stations
F(1) = x(1) - (2) / (1-x(2))*((1+x(2))+ 16*(1+2*x(2))+ ((x(2)^3)/(1-2*x(2)))*((x(2)/1-x(2))-((x(2)/1-x(2))^6)/((x(2)/1-x(2))^2))*((64*x(2)^3)/1-3*x(2))*(2*(x(2)/1-x(2))-((2*(x(2)/1-x(2)))^6))/(2*(x(2)/1-x(2))^2));
F(2) = (1-x(1))^n + x(2) -1;
i run it:
fun = @BEB
x0 = [0 0]
x = fsolve (fun, x0)
0 个评论
回答(1 个)
Walter Roberson
2020-2-24
Part of your expression is
((x(2)/1-x(2))^6)/((x(2)/1-x(2))^2))
The right hand side of that is (x(2)/1 - x(2))^2 which is (x(2) - x(2))^2 which is 0^0 which is 0. You are dividing by that zero. Division by 0 is going to get you one of -inf, +inf, or nan, depending what the numerator works out as. Your numerator happens to work out as 0 because it also has the X(2)/1-x(2) basic unit.
Therefore your expression always includes 0 / 0 which is NaN, so BEB always returns NaN as the first value. Most routines will give up when they see a nan result.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!