how to solve for fsolve
3 次查看(过去 30 天)
显示 更早的评论
how can i degug these code? %optimal gamma_j (SNR of user j)
y = sym('y');
eqn = (1 + y).^L_i - (1 + gamma_i ./ (y + 1)).^L_j;
func = matlabFunction(eqn,'Vars',{y});
xo=[0,0];
option = optimset('Display','off');
yj = fsolve(func ,[x0],option); %#ok<NBRAK>
gamma_j = min(yj, Gamma_j);
0 个评论
回答(1 个)
Walter Roberson
2022-3-27
编辑:Walter Roberson
2022-3-27
y = sym('y');
That is a scalar symbol
eqn = (1 + y).^L_i - (1 + gamma_i ./ (y + 1)).^L_j;
We cannot tell how many items that expands to. We can see that it does not distinguish elements of y, such as by trying to use y(2). We cannot prove from that whether y is expected to be scalar or vector inside that context. Nothing in that line contradicts the possibility that y is scalar.
func = matlabFunction(eqn,'Vars',{y});
That is going to produce a function handle in which each time y is unindexed. If any of the values such as gamma_i are non-scalar then eqn would have expanded to a non-scalar before getting to matlabFunction, and y would be used in full at each location. For example
eqn = y*v
where v=[2, 3] would already have expanded to eqn=[y*2,y*3] and when matlabFunction of that is taken, at each point all of y would be used. It would not expand to [y(1)*2,y(2)*3] - not with scalar symbol y.
xo=[0,0];
but you are passing a vector in for y at the fsolve level. However many elements were implied by gamma_i and so on, you are going to get an output twice as wide as you expect. Except if one of the locations came out to be independent of y... in that case you would probably end up with an error.
9 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

