Using count with negatives
조회 수: 5 (최근 30일)
이전 댓글 표시
I've written a code (as below), and now i'm trying to count the values of S_coeff_fact, however it won't work for the negative numbers?! I don't know why as ive never had this problem before.
function [S, R] = poly_fact(P, Q)
sizeP = size(P); rowsP = sizeP(2);
sizeQ = size(Q); rowsQ = sizeQ(2);
diff_in_length = rowsP - rowsQ;
i = diff_in_length+1;
count = 0;
while i>0
i = i-1;
count = count+1;
zero_input = zeros(1,diff_in_length);
Q = [Q zero_input];
S_coeff_fact = P(1, 1)/Q(1,1);
Q = Q*S_coeff_fact
P = P - Q
P = P(find(P ~= 0)); % Removing zeros from P.
Q = Q(find(Q ~= 0)); % Removing zeros from Q.
sizeP = size(P); rowsP = sizeP(2);
sizeQ = size(Q); rowsQ = sizeQ(2);
diff_in_length = rowsP - rowsQ;
S(count) = count(S_coeff_fact)
end
S = S
R = P
end
댓글 수: 2
Image Analyst
2013년 4월 10일
What does " count the values of S_coeff_fact" mean? Do you mean length(S_coeff_fact), or sum(S_coeff_fact)??? Can you put some comments in to explain the code (actually that might help you realize a logic error)? Can you supply some small sample arrays for P and Q so we can try it?
답변 (1개)
Jan
2013년 4월 10일
Your variable count is a scalar, such that indexing it with count(S_coeff_fact) must fail for anything but S_coeff_fact == 1. Therefore I claim, that this code did not work properly ever.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!