Hi, I have the following code but when i run it gives an error . The code :
function lambda = drive_zr17t9001 format short e; Params = load('saved_data.mat'); theta = pi/2; zeta = cos(theta); I = eye(Params.n,Params.n); Q = zeta*I-Params.p*Params.p';
%T is a matrix(5,5)
Mroot = Params.M.^(1/2); %optimization
T = Mroot*Q*Mroot;
%find the eigen values
E =real( eig(T));
%find the negative eigen values — %find the smallest negative eigen value
gamma = min(E);
%now solve for lambda
bounds = sort([0, -1/gamma]); %in case gamma is positive
M_inv = inv(Params.M); %optimizationlambda = fzero(@(lambda) zr17t9001(lambda,M_inv,Q,Params.zm),bounds); %do the searching
% end
function r = zr17t9001(lambda, M_inv, Q, zm) Winv = inv(M_inv+lambda.*Q); r = -(Params.zm)'*M_inv*Winv*Q*Winv*M_inv*(Params.zm); %end
The error
??? Error using ==> fzero FZERO cannot continue because user supplied function_handle ==> @(lambda) zr17t9001(lambda, M_inv, Q, Params.zm) failed with the error below.Undefined variable "Params" or class "Params.zm". Error in ==> drive_zr17t9001 at 19 lambda = fzero(@(lambda) zr17t9001(lambda, M_inv, Q, Params.zm), bounds); %do the searching
Best Answer