How to change a parameter in a model
1 次查看(过去 30 天)
显示 更早的评论
Hi, I'm just getting started using MATLAB and I don't know how to solve this problem.
I have a LTI system described by the following matrices
A = [ -1 0 0; -1 h k; 0 0 -3];
B = [ 1; 1; 0];
C = [0 7 0];
d = [0];
I need to determine the properties of the system for .
How can I make the parameters automatically change their value ?
Thank you for your help
2 个评论
Luca Ferro
2023-2-27
h, k should be random beween [-10,10] or linearly increase from -10 to 10 in sync or..?
回答(2 个)
Luca Ferro
2023-2-27
Here is one solution:
elements = {-10:1:10, -10:1:10}; %cell array with N vectors to combine
combinations = cell(1, numel(elements)); %set up the varargout result
[combinations{:}] = ndgrid(elements{:});
combinations = cellfun(@(x) x(:), combinations,'uniformoutput',false); %there may be a better way to do this
result = [combinations{:}]; % NumberOfCombinations by N matrix. Each row is unique.
[rows,~]=size(result);
B = [ 1; 1; 0];
C = [0 7 0];
d = 0;
for jj=1:rows
A = [ -1 0 0; -1 result(jj,1) result(jj,2); 0 0 -3]; %h k
%your calculations here
end
Note: for the permutation generation i referenced this answer: https://ch.mathworks.com/matlabcentral/answers/98191-how-can-i-obtain-all-possible-combinations-of-given-vectors-in-matlab#answer_252633
0 个评论
Star Strider
2023-2-27
Try something like this —
A = @(h,k) [ -1 0 0; -1 h k; 0 0 -3]; % Create As Anonymous Function
B = [ 1; 1; 0];
C = [0 7 0];
d = [0];
ssfcn = @(h,k) ss(A(h,k),B,C,d); % Create As Anonymous Function
[H,K] = ndgrid(-10:10); % Grids Of (h,k) Values
hk = [H(:), K(:)]; % Matrix Of (h,k) Values (Avoids Nested Loops)
wv = logspace(-3, 2, 75)*2*pi; % Radian Frequency Vector
figure
tiledlayout(5,5) % Change To Plot Different Numbers Of PArameters
% for kk = 1:size(hk,1) % Plot All Val;ues
for kk = 1:fix(size(hk,1)/24):size(hk,1) % Plot Subset Of Values
nexttile
[mag,phs,w] = bode(ssfcn(hk(kk,1),hk(kk,2)), wv);
semilogx(w, mag2db(squeeze(mag)))
grid
ylim([-50 30])
title(sprintf('h=%3d, k=%3d',hk(kk,:)))
end
I use bode here, however any function you want will likely work, with appropriate changes in the plot call and arguments to the function you are plotting. (The tiledlayout function does not work directly with bode or bodeplot, so it is necessary to get the outputs and plot them separately. The same is likely true for other Control System Toolbox functions that produce plots.)
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stability Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!