MATLAB How to Plot a Symbolic Function in MATLAB for Full State Feedback Problem?

AI Thread Summary
The discussion centers on a MATLAB problem related to plotting the output of a state feedback control system. The user has defined a system in state variable form and derived the state transition matrix to compute the output y(t) as a function of time. However, the output y is a symbolic function, leading to an error when attempting to plot it using standard numerical methods. The user seeks a solution to plot y over a specified time range. A resolution is provided, suggesting the use of the `ezplot` function to handle the symbolic nature of y, allowing for successful visualization of the output as a function of time.
maverick280857
Messages
1,774
Reaction score
5
Hi everyone,

I have a small MATLAB problem which arose while trying to solve a full state feedback problem in control theory.

I have a system in state variable form

\dot{x} = Ax + Bu
y = Cx

where u = -Kx, so the system reduces to

\dot{x} = (A-BK)x

The solution is

x(t) = exp((A-BK)t)x(0)

I know x(0), A, B and K and want to plot

y(t) = Cexp((A-BK)t)x(0)

as a function of time t.

This is the code I used to compute the state transition matrix

Code:
function [phi] = statetrans(A)
  t = sym('t');
  phi = expm(A * t);
end

And here is the code to compute y

Code:
A = [0, 1, 0, 0;4.4537,0,0,0;0,0,0,1;-0.5809,0,0,0];
B = [0;-0.3947;0;0.9211];
C = [0,0,1,0];
K = place(A,B,[-3,-2,-2+j,-2-j]); % this is used to determine the feedback gain after placing closed loop zeros at the desired location

x0 = [0.01;0.01;0.1;0.1]; % initial state

% The real code starts below
phi = statetrans((A-B*K));
x   = phi*x0;
y   = C*x;

The problem is that y is a symbolic function of t. How can I plot y as a function of t for t in some range (using something like t = 0:0.01:10)?

Code:
>> t = 0:0.01:10;
>> plot(t,y);
? Error using ==> plot
Conversion to double from sym is not possible.

Thanks in advance.

Cheers
Vivek
 
Physics news on Phys.org
Got it, can use ezplot.
 

Similar threads

Replies
8
Views
2K
Replies
4
Views
1K
Replies
2
Views
3K
Replies
9
Views
3K
Replies
18
Views
4K
Back
Top