MATLAB Answers

function/solve for variable that is constantly changing/ Question is explained in detail at the end of code

2 views (last 30 days)
Sebastian Remar
Sebastian Remar on 24 Jun 2020
Answered: Maadhav Akula on 1 Jul 2020
clear all
close all
poles = [-1,-2,-10];
a = poly(poles);
gs = tf(1,a)
% ess (step input) = 0 ; z = 0.147
% Finding w_n associated with damping from plot
%% STEP 1 Transient characteristics
z = 0.174;
wn = [0,10];
figure(1)
rlocus(gs)
sgrid(z,wn) % sgrid to find the point where z is at RL
w_n = 3.98; % natural frequency from plot
%% Step 2 pole locations
[DPLp,DPLn,re,ima] = Remar_Sebastian_DPL (z , w_n);
%% Step 3 - plotting desire poles
figure(2)
rlocus(gs)
hold on % Keep using the same fig
plot(re,ima/i,'ko','Markersize',5) % DPL with black marker
plot(re,-1*ima/i,'ko','Markersize',5) % DPL with black marker
%% Step 4 - plotting
% p_c = 0; % Compensator
z = 0;
%% Step 5 - Lemma #2
% Using a function in this hw now.
[p_c , theta_pc] = Remar_Sebastian_Lemma2 (ima , re , poles,z)
%% Step #6 Lemma #1
num = [p_c]; % Tf numerator of compensator
den = [z]; % Tf denominator of compensator
%%%%%%%%%%%%%%%%%%%%%% Here is my question %%%%%%%%%%%%%%%%%%%%
gc = tf(poly(num) , poly(den)); % Tf compensator
glemma = (1 / (gc*gs)) % Transfer function to find K
syms s
s = DPLp; % s is equal to positive DPL
k = abs( s^4 + 13 s^3 + 32 s^2 + 20 s / (s + 0.006991)); % Finding k
My question is, how can I create a function that does this last part. K is equal to the transfer function glemma,
now I am just displaying glemma in the command window and then writing the transfer function manually. How can I create a function
that takes glemma, DPL, as an input and somehow plug in DLPp into it and solve for k.
I want to achieve this because I am designing PID controllers and I am constantly changing my transfer function, it takes time
to display the glemma and copy paste the num/den and then run program again. I was able to recreate function for everything else
but this step.
thanks!
[SL: moved the actual question out of the code section]

  0 Comments

Sign in to comment.

Answers (1)

Maadhav Akula
Maadhav Akula on 1 Jul 2020
Hi Sebastian,
I believe you want to substitute the value of DPLp in place of s in your Transfer Function glemma, right? For that you can use the following function evalfr, or you can also utilise freqresp.
Hope this helps!

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!