Lyapunov Plotting: using 'mesh' and 'meshgrid' with matricies

15 views (last 30 days)
I'm trying to plot a 3d graph of a Lyapunov function of a control system I've created. The function is:
V(x)=xT*P*x
where x is a 2x1 matrix of the errors, e and de/dt:
x = [e;ed];
Therefore x transpose is a 1x2 matrix:
xT = [e, ed];
and the P matrix is 2x2 of constants (ie p1=const,p2=const,p3=const,p4=const):
P = [ p1 p2 ; p3 p4];
"e" and "ed" are a 1xn set of data from my simulation thus V ends up being a 1xn matrix
This is my code right now, I don't know what to do from here:
e = ErrorData.signals.values(:,1);
ed = ErrorData.signals.values(:,2);
for i=1:3420
V(i) = [e(i) , ed(i)] * P * [e(i) ; ed(i)] ;
end
I'm trying to plot (x,y,z) = (e,ed,V) in 3 dimensions but I can't seem to be able make my final vector V suitable for plotting in 3d. for e and ed you can use meshgrid, but I can't get V in the proper form.
I was using this code as an example from ( Lyapunov Example ):
x=[-4:.04:4];
y=x;
[X,Y]=meshgrid(x,y);
z=X.^2 + Y.^2;
mesh(X,Y,z)

Accepted Answer

Daniel Cleveland
Daniel Cleveland on 5 Apr 2015
Found the solution. I had to replicate what mesh does.
e = ErrorData.signals.values(:,1);
ed = ErrorData.signals.values(:,2);
[E,ED] = meshgrid(e,ed);
for i=1:3420
for j=1:3420
V(i,j) = [E(i,j) , ED(i,j)] * P * [E(i,j) ; ED(i,j)] ;
end
end

More Answers (2)

Daniel Cleveland
Daniel Cleveland on 4 Apr 2015
Hi, Nope, didn't work unfortunately. It doesnt' seem to "connect the dots" per say in the way I want. Here's the result:
  1 Comment
Roger Stafford
Roger Stafford on 4 Apr 2015
That result tells me you should be using dots for your plot marker, not lines. You will then see a crude representation of your desired "surface". Your data is not in suitable form to use with 'surf', which requires a mesh form of input.

Sign in to comment.


Roger Stafford
Roger Stafford on 4 Apr 2015
To get the V you need for plot3, do this:
V = sum(x.*(P*x),1);
Don't do a meshgrid on e and ed for use in plot3. You were probably thinking of 'surf', but that kind of surface plotting is not suitable for your particular problem.
  1 Comment
Intan Utari
Intan Utari on 1 Apr 2021
Dear Sir How are you? Hope you are well and healthy. I have a model of the spread of diphtheria by vaccination and I achieved the linearization of the model through the lyapunov function constructed using the krasovskii method but actually I don't know how to check the stability of the SIR mathematical model of diphtheria spread by vaccination using the Lyapunov stability theorem in Matlab. Would you, if possible help me in this matter, Please. thank you

Sign in to comment.

Categories

Find more on Matrix Computations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!