I tried to simulate a block diagram with Matlab code but it gives me wrong results, the block diagram is shown in the uploaded picture and the Matlab code is shown below
clear all;close all;clc % define the global variable global max centx centy p1 p2 p12 p21 root wx ax cx wy ay cy h global uxsave uysave tsave
uxsave=[]; uysave=[]; tsave=[];
%Nonlinear map parameters max = 1; % max value of nonlinear map centx = -1; % x-coordinate of center of nonlinear map centy = -1; % y-coordinate of center of nonlinear map p1 = 1; % values in Hessian (P) p2 = 0.5; p12 = 0; p21 = 0; root = 1; % can be used to spread map
% Extremum Seeking parameters wx = 20; % x-loop perturbation frequency ax = .05; % x-loop perturbation amplitude cx = 20; % x-loop gain
wy = 20; % y-loop perturbation frequency ay = .05; % y-loop perturbation amplitude cy = 20; % y-loop gain
% filter h=1;
% simulation t0=0; % start time t1=30; % end time
%initial condition of the state x0=[1,1,0];
% solving the ode tspan=[t0 t1]; [t,x]=ode23('pointmass_derivatives',tspan,x0);
%%%%%%%%%%%%%%%%%% for i=1:length(t) idx = find(tsave-t(i)==0); ux(i)=uxsave(idx(length(idx))); uy(i)=uysave(idx(length(idx))); end;
% trajectory of the states xp=x(:,1); yp=x(:,2); J=max./(1+p1.*(xp-centx).^2+p2.*(yp-centy).^2).^(root);
figure plot(t,J,'b','LineWidth',3); xlabel('time (sec)','FontSize',18,'FontWeight','bold'); ylabel('output','FontSize',18,'FontWeight','bold'); title('Objective Function','FontSize',18,'FontWeight','bold'); grid on; set(gca,'FontSize',12,'FontWeight','bold');
figure plot(xp,yp,'r','LineWidth',3); xlabel('x','FontSize',18,'FontWeight','bold'); ylabel('y','FontSize',18,'FontWeight','bold'); grid on; set(gca,'FontSize',12,'FontWeight','bold');
the mousa_derivatives function is as follows
mousa_derivatives
Is there anyone have an idea why the results are not correct?
Many thanks