How to know results

1 Ansicht (letzte 30 Tage)
Ani Asoyan
Ani Asoyan am 2 Jun. 2020
Kommentiert: Ameer Hamza am 3 Jun. 2020
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 Kommentar
Ani Asoyan
Ani Asoyan am 2 Jun. 2020
I want to know if it takes into account cross-combinations of e and b ?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 2 Jun. 2020
Bearbeitet: Ameer Hamza am 2 Jun. 2020
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 Kommentare
Ani Asoyan
Ani Asoyan am 2 Jun. 2020
like in cross combinations, for example e=8,b=1 or e=8,b=3 ,ect...
Ameer Hamza
Ameer Hamza am 3 Jun. 2020
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord
Steven Lord am 2 Jun. 2020
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 Kommentare
Ani Asoyan
Ani Asoyan am 2 Jun. 2020
sorry I didn't understand... my polynomial is 1st order
Steven Lord
Steven Lord am 2 Jun. 2020
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by