필터 지우기
필터 지우기

How to show in edittext the polynomial ordered from highest to lowest grade?

조회 수: 1 (최근 30일)
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?

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 4일
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
Erwin Avendaño
Erwin Avendaño 2017년 11월 5일
y = is the polynomial that is obtained after doing operations in my program z=simplify(y) set(handles.edit23,'String',char(z))
Walter Roberson
Walter Roberson 2017년 11월 5일
편집: Walter Roberson 2017년 11월 5일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by