How to know results
이전 댓글 표시
I have a polynomial and parameters in it,
a=2, c=1, d=2 , g=0.5, k=2 , f=2
e=[2,8,5,4]
b=[1,2,3,4]
p=[ -c.*k+ (f.^2)*(e.^2)/a+2*e.*g, d.*e-(f*b.*e)/a]
roots(p)
I calculate roots of polynomial given parameter values.
But e an b parameters have vector values.
I want to know if it obtains roots for every combination of the e and b values or
it simply gets roots when e=2, b=1 , then b=8,e=2,... ?
채택된 답변
추가 답변 (1개)
Steven Lord
2020년 6월 2일
As written your code solves for the roots of the 7th order polynomial whose coefficients are:
p =
8 134 53 34 2 0 -5 -8
This is:
8*x^7 + 134*x^6 + 53*x^5 + 34*x^4 + 2*x^3 - 5*x - 8
If instead you want to find the roots of the four first order polynomials created by specifying each element of e and b in the expression for p, use a for loop instead.
>> for q = 1:numel(e)
p=[ -c.*k+ (f.^2)*(e(q).^2)/a+2*e(q).*g, d.*e(q)-(f*b(q).*e(q))/a]
end
p =
8 2
p =
134 0
p =
53 -5
p =
34 -8
If you want to find the roots of the sixteen first order polynomials with elements taken from e and from b (and not necessarily the same element of each vector) the easiest way is to use a double for loop.
댓글 수: 2
Ani Asoyan
2020년 6월 2일
Steven Lord
2020년 6월 2일
It is not first order as you've written it. Use one or two for loops to construct and solve the four or sixteen first order polynomials or use the explicit formula for the solution of a linear equation.
% if q*x = w then x = w./q
a=2, c=1, d=2 , g=0.5, k=2 , f=2
e=[2,8,5,4]
b=[1,2,3,4]
q = -c.*k+ (f.^2)*(e.^2)/a+2*e.*g;
w = d.*e-(f*b.*e)/a;
x = w./q % Using ./ instead of / because w and q are vectors
check = q.*x - w % Should be all 0's or close to it
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!