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
0 个评论
回答(1 个)
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')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!