I have many cells A and B, and the dimension that should pass the ode45 function is 2by2 for both of them. I want to apply the ode for every class. I have around 58 classes, and they each structure 2by2 matrix.
A= cellfun(@(n,m) -inv(n)*m, L,R, 'UniformOutput',false);B= cellfun(@(n) inv(n), L, 'UniformOutput',false);Vp = sqrt(2)*120;n =60;h=0.000167; % step size
t = 0:h:0.1; % the range of t
x = zeros(2,length(t)); % Calculates upto x(360)
K = [1;0];u = K*Vp;%this is State Space Model (Euler's Method)
dx = arrayfun(@(t,x) cellfun(@(n,m) n*x+ m*u*sin(377*t+pi/2),A,B),'UniformOutput',false);for i = 1:(length(t)-1) t(i+1) = t(i)+h; x(:,i+1) = x(:,i)+ h*dx(t(i),x(:,i));end
%for ODE45
tspan = [0 0.167];iniCon = zeros(2,11);[t,x] = ode45(@myode, tspan, iniCon);function dx = myode(t,x)A= cellfun(@(n,m) -inv(n)*m, L,R, 'UniformOutput',false);B= cellfun(@(n) inv(n), L, 'UniformOutput',false); Vp = 120*sqrt(2); K = [Vp;0]; u = K*sin(377.*t+(pi/2)); dx = cellfun(@(n,m) n.*x+ m.*u*sin(377*t+pi/2),A,B,'UniformOutput',false);end
Best Answer