# How to change a parameter in a model

2 vues (au cours des 30 derniers jours)
Gaetano Ruocco le 27 Fév 2023
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 = ;
I need to determine the properties of the system for .
How can I make the parameters automatically change their value ?
##### 2 commentairesAfficher AucuneMasquer Aucune
Luca Ferro le 27 Fév 2023
h, k should be random beween [-10,10] or linearly increase from -10 to 10 in sync or..?
Gaetano Ruocco le 27 Fév 2023
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

Connectez-vous pour commenter.

### Réponses (2)

Luca Ferro le 27 Fév 2023
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
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Star Strider le 27 Fév 2023
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 = ;
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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Plot Customization dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!