ODE45 using array input
Show older comments
I am trying to solve a set of differential equations in which some parameters are random generated arrays. However when I run the code I get an following error. Does ode45 take the complete array for each iteration causing the error, if so how do I resolve it.
Unable to perform assignment because the left and right sides have a different number of elements.
Error in PDE_Backstepping>deq (line 21)
x(2) = -e + r_prime;
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in PDE_Backstepping (line 8)
[t,x] = ode45(@deq, ts, Xin, options);
Here's the code I am using:
Xin = [0, 0];
ts = [0:0.00001:10];
k = 1e-6;
r = rand(1,1000001);
r_prime = [0 diff(r)];
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
[t,x] = ode45(@deq, ts, Xin, options);
function f = deq(t,x)
k = 1e-6;
w = 212.28;
zeta = 0.1;
BLE = -1.4099e-08;
BTE = -1.375e-08
r = rand(1,1000001);
r_prime = [0 diff(r)];
e = x(1) - r;
x(2) = -e + r_prime;
u = x(2) - (x(2) - r_prime) - k*(x(2) - r_prime + e);
f(1,1) = x(2);
f(2,1) = -2*zeta*w*x(2) - w^2*x(1) + (BLE+BTE)*u;
end
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!