フィルターのクリア

How to change a parameter in a model

4 ビュー (過去 30 日間)
Gaetano Ruocco
Gaetano Ruocco 2023 年 2 月 27 日
回答済み: Star Strider 2023 年 2 月 27 日
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
Luca Ferro 2023 年 2 月 27 日
h, k should be random beween [-10,10] or linearly increase from -10 to 10 in sync or..?
Gaetano Ruocco
Gaetano Ruocco 2023 年 2 月 27 日
They should increase by 1 at a time each. I have to consider all the possible couples such as h=-10,k=-10, h=-10,k=-9 and so on

サインインしてコメントする。

回答 (2 件)

Luca Ferro
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

Star Strider
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.)
.

カテゴリ

Help Center および File ExchangePlot Customization についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by