I am trying to satisfy an equation by varying two feedback gains over a loop in Matlab. Could anyone help me?

조회 수: 1 (최근 30일)
Hi all
I am trying to run a code which analyses the power control criteria for an aircraft. My code needs to analyse a matrix 'A' with gains 'kw' and 'kq' that affect the matrix values. I need to satisfy the equation of N = + or - 20 degrees by varying the values of Kw and Kq at the same time. This will allow me to find the feedback gains which meet the requirements of the aircraft
I have attached a code which I am trying to use. I can't seem to get any outputs but I am a matlab novice.
Xe=0;
Ze=-4.5;
Mbe=-2.0964;
for kw=0:0.001:-3
for kq=0:0.001:-3
A=[-0.03,(-0.0308-(kw*Xe)),(0-(kq*Xe)),-9.8065;-0.02,(-0.92115-(kw*Ze)),(200-(kq*Ze)),0;-0.000024,(-0.002613-(kw*Mbe)),(-0.46-(kq*Mbe)),0;0,0,1,0];
N(length(N)+1)=(Mbe*A(2,2)*200)/(2*9.8065*(-0.46*A(2,2))-(A(3,2)*200));
deg=radtodeg(N);
end
end
I would appreciate it if any one could help give me any tips.
Thanks J

답변 (1개)

Star Strider
Star Strider 2014년 5월 10일
편집: Star Strider 2014년 5월 10일
You can decrement in loops, but you have to have the interval as a decrement as well. So if you want a loop counter or vector go to from 1 to -10:
v = 1:-1:-10;
Your loops weren’t iterating.
I added a counter for N, changed the radtodeg call (there is no such function in MATLAB), and changed the loops to decrement. I didn’t wait for it to complete all its 9E+6 iterations, so I can only guarantee it runs and produces results for A and N (until I stopped it).
Note that deg appears after N and isn’t stored. You might want to make it into deg(Nk) = ... to store the result. I also added a timer and a save statement so you can store the results and not have to re-run what may be very long code to work with your calculations. Each save file is unique, so one doesn’t overwrite the previous ones. (See the documentation for save and load for details.) Change the ‘J_Otter’ part of the name of the file to one you want. I used that as a default.
Xe=0;
Ze=-4.5;
Mbe=-2.0964;
Nk = 0;
T0 = clock
for kw=0:-0.001:-3
for kq=0:-0.001:-3
A=[-0.03,(-0.0308-(kw*Xe)),(0-(kq*Xe)),-9.8065;-0.02,(-0.92115-(kw*Ze)),(200-(kq*Ze)),0;-0.000024,(-0.002613-(kw*Mbe)),(-0.46-(kq*Mbe)),0;0,0,1,0];
Nk = Nk + 1;
N(Nk)=(Mbe*A(2,2)*200)/(2*9.8065*(-0.46*A(2,2))-(A(3,2)*200));
deg=N*180/pi;
end
end
T2 = clock;
te = etime(t1,t0)
ts = datestr(now, 'yyyymmdd-HHMMSS');
save(['J_Otter_' ts '.mat'], 'N', 'T0', 'T1')

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by