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 = 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
x=[-4:.04:4]; y=x; [X,Y]=meshgrid(x,y); z=X.^2 + Y.^2; mesh(X,Y,z)
To plot your Lyapunov function V(x)=xTPxV(x) = x^T P x in 3D, you need to generate a grid of ee and e?\dot{e} values and calculate VV at each point on that grid. Here's how you can do it step by step:
meshgrid
.mesh
function.
% Define P matrix (example values, modify as needed) p1 = 1; p2 = 0.5; p3 = 0.5; p4 = 2; P = [p1, p2; p3, p4]; % Define the range of e and ed values e_range = -4:0.04:4; % Example range ed_range = -4:0.04:4; % Example range % Create a grid of e and ed values [E, ED] = meshgrid(e_range, ed_range); % Initialize V matrix V = zeros(size(E)); % Compute V for each (e, ed) pair for i = 1:size(E, 1) for j = 1:size(E, 2) x = [E(i, j); ED(i, j)]; V(i, j) = x' * P * x; % Lyapunov function calculation end end % Plot the result figure; mesh(E, ED, V); xlabel('e'); ylabel('ed'); zlabel('V(e, ed)'); title('Lyapunov Function V(e, ed)'); grid on;
Matrix Dimensions:
meshgrid
Usage:
meshgrid
generates two 2D matrices EE and EDED that define the grid of ee and e?\dot{e} values.Double Loop:
for
loop iterates over the grid points, computes VV for each (e,e?)(e, \dot{e}), and stores it in the corresponding entry of VV.Plotting with mesh
:
mesh
function plots V(e,e?)V(e, \dot{e}) as a 3D surface.To avoid the double loop, you can vectorize the calculation of V:
% Vectorized computation of V V = P(1,1)*E.^2 + (P(1,2) + P(2,1))*E.*ED + P(2,2)*ED.^2; % Plot the result figure; mesh(E, ED, V); xlabel('e'); ylabel('ed'); zlabel('V(e, ed)'); title('Lyapunov Function V(e, ed)'); grid on;
Let me know if you need further assistance!
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.