How can I solve a polynomial where coefficients are vector arrays?

12 views (last 30 days)
Hi there!
I have a system of equations which 4 of them feed into a final equation (code shown below). The first four equations all work beautifully, no issues, even while using large arrays as one of my variables.
The variable I am concerned with here is "psidot" - when I make psidot a single value, say 90, the entire equation works beautiful and my roots come out appropriately and I get the correct answer. However, as soon as I make "psidot" an array, say [90 80 70], my roots get all messed up and I don't get the right answers anymore. I get a lot of negative numbers and certainly none of the right answers.
Essentially what I'm looking for is to evaluate the roots of the polynomial at each of these values of "psidot", individually. I'm just not sure what i'm doing wrong. Can anyone provide some insight?
Thanks so much in advance! Caitlin
v1=674; %ft/sec velocity of aircraft 1
v2=760; %ft/sec velocity of aircraft 2
theta1=0; %degrees reckoning of aircraft 1
theta2=180; %degres reckoning of aircraft 2
psi1=[90 80 70]; %degrees degrees of error (should be array)
psidot=3; %degrees/sec rate of error change
syms t; %time variable
x1=6049; %x position of aircraft 1
y1=12089; %y position of aircraft 1
x2=90735; %x position of aircraft 2
y2=120980; %y position of aircraft 2
d=500; %distance they should be apart for a problem, in feet
k1=v1*cos(theta1+psi1)-v2*cos(theta2);
k2=((v1/psidot)*(sin(theta1+psi1)-sin(theta1)))-cos(theta1+psi1)*v1.*(psi1/psidot)+x1-x2;
k3=v1*sin(theta1+psi1)-v2*sin(theta2);
k4=(v1/psidot)*(cos(theta1)-cos(theta1+psi1))-sin(theta1+psi1)*v1.*(psi1/psidot)+y1-y2;
k5=k1.^2+k3.^2; %"a" in the polynomial
k6=2*(k1.*k2+k3.*k4); %"b" in the polynomial
k7=k3.^2+k4.^2-500; %"c" in the polynomial
p = [k5 k6 k7]; % creating the polynomial
r = roots(p); %solving for roots
r=real(r)/60 %getting real answers
  2 Comments
Andy L
Andy L on 8 Aug 2014
Star Strider is correct in his answer below. However I noticed that in k2 and k4 you divide two vectors without using the ./ operator. This means MATLAB will be trying to divide the two matrices as opposed to their elements, which is not possible as the inner dimensions will disagree - i'm assuming this is your error?

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 8 Aug 2014
Edited: Star Strider on 8 Aug 2014
If psidot is a vector, use a loop:
psidotvct = [90 80 70]; %degrees/sec rate of error change
for k1 = 1:size(psidotvct,2)
psidot = psidotvct(k1);
.... CODE ...
rr(k1,:) = real(r)/60 %getting real answers
end
This creates the rr array to store one row for every value of psidot. (I changed your code to create rr because it would otherwise cause problems with r just before it in subsequent loop iterations.)
I also don’t understand the ‘syms t’ call. It doesn’t look like you’re using it anywhere. You might consider deleting that line to speed things up.
  12 Comments
Caitlin
Caitlin on 16 Aug 2014
turns out - i found a way to run through iterations just using a call to a matrix!
c=combk(1:Nr_AC;2)
will give me a matrix c of all possible combinations of aircrafts 1-Nr_AC, and then from that...i can pull into my equations which pairs to reference and then pull the actual data from the data matrix.
done and done!
and as far as the # of aircrafts changing as time goes on in the sector...luckily, this is an experimental data with many limitations and assumptions, so holding the # static at the largest possible number is fine, covering a "worst case scenario."
whew :-)
Star Strider
Star Strider on 16 Aug 2014
Great!
I’d have suggested combnk but I thought you had to go through all aircraft, not just selected ones. If you’re sampling a representative subset of your aircraft, that will work.
I’m glad you were able to restrict your sector traffic to make your problem more tractable. That problem concerned me, because it’s not obvious.
I don’t know if you intend to publish your research (not all theses and dissertations are published in referred journals), but if you do, I’d appreciate a PDF. My contact information is in my File Exchange profile.
Have fun, stay safe, and avoid occluded fronts!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!