Azzera filtri
Azzera filtri

Approximating parameters with ODE, error using vertcat dimesions of arrays being concatenated are not consistent

3 visualizzazioni (ultimi 30 giorni)
Hi guys, I have a project to approximate a function with radial basis function, basically I want to approximate the parameters of radial basis function. We are talking about dynamic learning and I have 14 differential equations to solve, dx/dt, dx_approx/dt, dtheta_1/dt...dtheta_12/dt. I am trying to use ode45 or ode23 to solve this differential equations and approximate the thetas. However, when I am using ode either 23 or 45 I am getting this error:
"Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in odRBF (line 70)
[t,x]=ode45(@(t,x) [f(t,x(1),sin(t));dxdt_approx(t,x(2),sin(t),x(3:end))],tspan,[x0, x0*ones(1,num_RBF)],...
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);"
Can anyone pinpoint what I am doing wrong? Here is my code.
xmin=-1; xmax=1;
% Width
n=0.4;
% Number centers
num_RBF=12;
c=(xmin:(xmax-xmin)/(num_RBF-1):xmax);
% Gradient descent algorithm to update the weights
gamma=0.1;
theta=rand(1,num_RBF);
am=1;
sigma=0.4;
% Define the dynamical system
f=@(t,x,u) (sin(3.3*x)-0.7*x.*(9+x.^2))./(0.5*(8+x.^2))+u;
x0=-0.3; % initial condition
tspan=[0 20];
%RBF approximation function
fhat=@(x,theta) sum(theta.*exp(-((x-c).^2)./sigma^2));
%differential equation for the approximation
dxdt_approx=@(t,x,u,theta) -am.*x+am.*fhat(x,theta)+am*u;
%derivative of the approximation weights
dtheta_approx=@(x,x_approx,theta,gamma,e) gamma.*e.exp(-((x-c).^2)./sigma^2).(x-x_approx);
% Define the error filter
Z=zeros(num_RBF,2);
for i=1:num_RBF
Z(i,1)=exp(-((xmin-c(i)).^2)./sigma^2);
Z(i,2)=exp(-((xmax-c(i)).^2)./sigma^2);
end
[t,x]=ode45(@(t,x) [f(t,x(1),sin(t));dxdt_approx(t,x(2),sin(t),x(3:end))],tspan,[x0, x0*ones(1,num_RBF)],...
odeset('RelTol',1e-6,'AbsTol',1e-6));
% Plot the true and estimated output
figure; hold on;
plot(t,x(:,1),'linewidth',2);
plot(t,x(:,2),'linewidth',2);
legend('x','x_approx','fontsize',14);
xlabel('Time','fontsize',14);

Risposte (1)

Torsten
Torsten il 25 Feb 2023
If you debug your code, you will see that c has dimension 1x12 while theta has dimension 1x11 in the function "fhat".
Thus
theta.*exp(-((x-c).^2)
cannot be evaluated.

Community Treasure Hunt

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

Start Hunting!

Translated by