How to Write MATLAB Code for Control Systems with Variable K?

In summary: To create a plot of the system response, you can use the MATLAB plotting functions such as plot and step. To create an unstable system, you can choose any value of K outside the stable region, which is 0 < K < 61.75.
  • #1
Badger33
36
0
I have a given system and I need to
A) determine the transfer function
B) find the values of K form Routh-Hurwitz
C) Determine the values of K for the stable region
D) Create the simulink model.

I want to know how to write my MATLAB code so that I can solve what I need to. I DO NOT want the answers! I want to do it my self. Please provide the code entries and how to input them properly, use examples if you can it will help a lot!

This system is a proportional controller. My closed loop transfer function is 4K/s3+13s2+19s+4K

I know the range of my system to be 61.75>K>0 from the Routh-Hurwitz stability conditions.

So I want to be able to sole the C.E. I would like to do this in MATLAB using the roots command. But my issue is that my equation is s3+13s2+19s+4K So I want to have K be a variable change it then resolve for roots. I think i can do it with root locus too but this is how I want to do it, but you can TEACH me both I won't mind. I keep trying to do the following code but it is wrong.
>>K=.001
>>SysP1=[1 13 19s 4K];
>>roots(SysP1)

That is my first solution then the next would be
>>K=.1; roots(SysP1)
Obviously I could just keep changing that last line and getting new solutions.
Help me please.



Next I create the simulink model and want to make a plot of the system response to a step change so I just create my moddel and output to scope and that's the result. If I want an angle input to my step function I can just input that π/4 rad as the step input. Also I want an unstable system and that will be any value of K outside the stable region (or is it were my roots to the CE are positive?)




P.S. This is my first course that I have ever had to use MATLAB for and well have not had a formal introduction to matlab, thus I know very little. I know how to do simulink well though. Seeing as I have no background in MATLAB I have been getting no where and just frustrated and well want to throw my computer out the window!
 
Physics news on Phys.org
  • #2
To solve the transfer function equation, you can use the symbolic toolbox in MATLAB. The following code will help you to solve the equation for different values of K: % Define symbolic variable syms s K; % Define transfer function SysP1 = 4*K/s^3 + 13*s^2 + 19*s + 4*K; % Solve the equation for different values of K for k = 0:0.1:61.75 SysP1_k = subs(SysP1,K,k); % Substitute value of K rts = roots(SysP1_k); % Solve the equation disp(rts); % Display the roots end To create the Simulink model, you can drag and drop blocks from the Simulink library and connect them accordingly. The step input should be connected to the input port of your system. To change the value of K, you can use a Constant block. For example, if K is 0.1, you can set the value of the Constant block to 0.1. You can then observe the response of the system by connecting the output port of your system to the Scope block.
 

FAQ: How to Write MATLAB Code for Control Systems with Variable K?

What is Matlab and how is it used in control systems?

Matlab is a high-level programming language and interactive environment used for numerical computation, data visualization, and algorithm development. In control systems, Matlab is used for designing, simulating, and analyzing control systems, as well as implementing control algorithms on hardware.

What are the advantages of using Matlab for control systems?

There are several advantages of using Matlab for control systems, including its user-friendly interface, powerful built-in functions and toolboxes, and extensive documentation and support. Matlab also allows for easy integration with other software and hardware, making it a versatile tool for control system design and implementation.

Can Matlab be used for both linear and nonlinear control systems?

Yes, Matlab can be used for both linear and nonlinear control systems. It offers a wide range of tools and functions for designing and analyzing both types of systems, including linear and nonlinear control system design tools, as well as simulation and optimization tools.

How does Matlab handle time-domain and frequency-domain analysis of control systems?

Matlab has built-in functions and toolboxes for both time-domain and frequency-domain analysis of control systems. Time-domain analysis tools include step response, impulse response, and frequency response plots, while frequency-domain analysis tools include Bode plots, Nyquist plots, and root locus plots.

Is Matlab suitable for real-time control system implementation?

While Matlab is primarily used for control system design and simulation, it can also be used for real-time control system implementation. It offers various options for code generation and deployment to hardware, making it suitable for real-time applications in industries such as aerospace, automotive, and robotics.

Similar threads

Replies
13
Views
2K
Replies
1
Views
2K
Replies
1
Views
1K
Replies
5
Views
2K
Replies
1
Views
1K
Back
Top