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

 채택된 답변

darova
darova 2020년 6월 16일

0 개 추천

Can you explain what you are trying to do?

댓글 수: 6

Amit Bhayadia
Amit Bhayadia 2020년 6월 16일
The r here is the reference input to the set of ode. e is the error defined such that the output of the ode (x(1)) is teh same as r. Usually r is afunction that iterates with time but here I am using an array which I dont have the defibing function for. Using an pre determined array leads to a dimensionality problem when using ode45, So I am looking for a way to work around it.
darova
darova 2020년 6월 16일
try this
% r = rand(1,1000001);
r = rand;
Amit Bhayadia
Amit Bhayadia 2020년 6월 16일
That would work since now r is a single number but in actuality the r I am using is a saved array. I just used a random array here as an example. So if r were a predetermined array how do I make it work. Is there a way too use a for loop in the function to make it work.
darova
darova 2020년 6월 17일
I understand, here is an example:
function main
r = (your_array);
time = (appropriate_time_array);
function du = f(t,u)
r1 = interp1(time,r,t); % extract current r
du = (ode_equation);
end
end
Amit Bhayadia
Amit Bhayadia 2020년 6월 17일
Can you explain the purpose of having a function within function? Also in my ode do I use the r1 value?
darova
darova 2020년 6월 17일
You should try. My typing skills are poor. Don't want to explain that

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2020년 6월 15일

댓글:

2020년 6월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by