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!