ode45 error Unable to perform assignment because the indices on the left side are not compatible with the size of the right side
5 views (last 30 days)
Show older comments
Hi Guys,
I am trying to solve a set of 3 differential equations using ode45. But i can't get it to work because I am getting the following error:
%Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
%Error in freylaw_stat (line 29)
%dy(1,1)=-Ct+(R+r)*y(3); %Mr the constant r is introduced here according to Looft et al.(2018) and is an intended variation of the
%original equation
%Error in Gesamtskript_stat>@(t,y)freylaw_stat(t,y,t_min,Fext_M_P,MVC_Verlauf_P) (line 119)
%[t,y]=ode45(@(t,y) freylaw_stat(t,y,t_min,Fext_M_P,MVC_Verlauf_P),timerange,IC); %PROZENT MUs
%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 Gesamtskript_stat (line 119)
%[t,y]=ode45(@(t,y) freylaw_stat(t,y,t_min,Fext_M_P,MVC_Verlauf_P),timerange,IC); %PROZENT MUs
following is the code I am using for ode45:
timerange=[T0_min tEnd_min];
IC=[100; 0; 0];
MVC_Verlauf_P=100;
[t,y]=ode45(@(t,y) freylaw_stat(t,y,t_min,Fext_M_P,MVC_Verlauf_P),timerange,IC);
with Fext_M_P being of the type 741979x1 double and using the following function:
function dy=freylaw_stat(t,y,t_min,Fext_M_P,MVC_Verlauf)
L=10; %Modellspezifischer Faktor
r=15; %rest-recovery-multiplier nach 2018#Looft et al.
F=0.00912; %Ermüdungsfaktor nach Frey Law (2012)
R=0.00094; %Erholungsfaktor nach Frey Law (2012)
Fext_I=Fext_M_P;
MVC=MVC_Verlauf-y(3);
TL0=(Fext_I/MVC)*100;
if (y(2)<TL0)&(y(1)>(TL0-y(2)))
Ct=L*(TL0-y(2)); %if Ma<TL and Mr>(TL-Ma)
elseif (y(2)<TL0)&(y(1)<(TL0-y(2)))
Ct=L*y(1); %if Ma<TL and Mr<(TL-Ma)
else
Ct=L*(TL0-y(2)); %if Ma>=TL
end
dy(1,1)=-Ct+(R+r)*y(3); %Mr
dy(2,1)=Ct-F*y(2); %Ma
dy(3,1)=F*y(2)-R*y(3); %Mf
end
Can someone tell me what I am doing wrong here, and how to change it? Your help is greatly appreciated!
Thank you and best regards,
Christian
8 Comments
Ameer Hamza
on 20 Mar 2020
To solve them as a differential equation with ode45, you need dy to be 3*1, not 741979*3. The equation you pasted also show that C(t) is a function of time. So you need to specify, how the time t is related to the elements of vector Ct. For example, if t=0, C(0) is the first element of Ct, i.e., Ct(1), then at the next time step, say t=0.1, which elemnt of Ct is equal to the value of C(0.1).
Answers (1)
Ameer Hamza
on 24 Mar 2020
Check the following code. I created a random vector Fext_M_P to test the output of my code. Also the time range is from 0 to 10.
Fext_M_P = rand(741979, 1);
timerange=linspace(0, 10, numel(Fext_M_P));
IC=[100; 0; 0];
MVC_Verlauf_P=100;
[t,y]=ode45(@(t,y) freylaw_stat(t,y,timerange,Fext_M_P,MVC_Verlauf_P),timerange,IC);
function dy=freylaw_stat(t,y,timerange,Fext_M_P,MVC_Verlauf)
L=10; %Modellspezifischer Faktor
r=15; %rest-recovery-multiplier nach 2018#Looft et al.
F=0.00912; %Ermüdungsfaktor nach Frey Law (2012)
R=0.00094; %Erholungsfaktor nach Frey Law (2012)
index = floor(interp1(timerange([1 end]), [1 numel(Fext_M_P)], t));
Fext_I=Fext_M_P(index);
MVC=MVC_Verlauf-y(3);
TL0=(Fext_I/MVC)*100;
if (y(2)<TL0)&(y(1)>(TL0-y(2)))
Ct=L*(TL0-y(2)); %if Ma<TL and Mr>(TL-Ma)
elseif (y(2)<TL0)&(y(1)<(TL0-y(2)))
Ct=L*y(1); %if Ma<TL and Mr<(TL-Ma)
else
Ct=L*(TL0-y(2)); %if Ma>=TL
end
dy(1,1)=-Ct+(R+r)*y(3); %Mr
dy(2,1)=Ct-F*y(2); %Ma
dy(3,1)=F*y(2)-R*y(3); %Mf
end
See Also
Categories
Find more on Calculus 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!