how to solve for fsolve
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 27 Mar 2022
Modificato: Walter Roberson
il 27 Mar 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Number Theory in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

