How to show in edittext the polynomial ordered from highest to lowest grade?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Erwin Avendaño
il 4 Nov 2017
Modificato: Walter Roberson
il 5 Nov 2017
What happens is that my program in edittext edit the polynomial but all messy can you print but in an orderly way? From highest to lowest?
0 Commenti
Risposta accettata
Walter Roberson
il 4 Nov 2017
Use the two-output form of coeffs to extract the coefficients and the corresponding powers. The powers will be sorted in descending order. You can then construct a character string from the parts.
[cs, pows] = coeffs(YourPolynomial, AppropriateVariable);
temp = sprintf( '%s * %s +', [cs(:), pows(:)].' ); %transpose is important
temp(end-1:end) = []; %trim trailing ' +'
3 Commenti
Walter Roberson
il 5 Nov 2017
Modificato: Walter Roberson
il 5 Nov 2017
syms x y = expand((x-1)^3+x);
[cs, pows] = coeffs(y, x); z = sprintf( '%s * %s + ', [cs(:), pows(:)].' ); %transpose is important z(end-2:end) = []; %trim trailing ' + ' set(handles.edit23,'String',char(z))
You can get fancier, such as suppressing '1 *' if it occurs, or the final '* 1' if it occurs, and by handling negative values. The easiest way to handle those is probably to do some pattern matching on z using regexprep.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!