How to know results

조회 수: 1 (최근 30일)
Ani Asoyan
Ani Asoyan 2020년 6월 2일
댓글: Ameer Hamza 2020년 6월 3일
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
Ani Asoyan
Ani Asoyan 2020년 6월 2일
I want to know if it takes into account cross-combinations of e and b ?

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 2일
편집: Ameer Hamza 2020년 6월 2일
Your current code does not solve the problem, as you described. You need to use for-loop
a=2, c=1, d=2 , g=0.5, k=2 , f=2
e=[2,8,5,4]
b=[1,2,3,4]
r = zeros(numel(e), 1) % polynomial is 1st order so there will be only one root
for i=1:numel(e)
p = [ -c.*k+(f.^2)*(e(i).^2)/a+2*e(i).*g, d.*e(i)-(f*b(i).*e(i))/a]
r(i) = roots(p)
end
  댓글 수: 5
Ani Asoyan
Ani Asoyan 2020년 6월 2일
like in cross combinations, for example e=8,b=1 or e=8,b=3 ,ect...
Ameer Hamza
Ameer Hamza 2020년 6월 3일
Following code use cross-combination
a=2, c=1, d=2 , g=0.5, k=2 , f=2
e=[2,8,5,4]
b=[1,2,3,4]
[E, B] = ndgrid(e, b);
e = E(:);
b = B(:);
r = zeros(numel(e), 1) % polynomial is 1st order so there will be only one root
for i=1:numel(e)
p = [ -c.*k+(f.^2)*(e(i).^2)/a+2*e(i).*g, d.*e(i)-(f*b(i).*e(i))/a]
r(i) = roots(p)
end
sol = [e, b, r]
1st column of 'sol' is 'e' value, 2nd is 'b' values, and 3rd is the corresponding root.

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

추가 답변 (1개)

Steven Lord
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
Ani Asoyan 2020년 6월 2일
sorry I didn't understand... my polynomial is 1st order
Steven Lord
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

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by