How to add additional input to Ode45 function
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, i need to optimaze the code of a PSO search for the interplanetary transefer exercise.
I accomplished the exercise using globals but it results quite slow, so i wanted to add the constants parameters as the input of the integration function of the ODE45 as follows:
function dw = eqni_archi(t,X,alfa,beta,mi)
dw(1)=X(3);
dw(2)=X(4)/X(1);
dw(3)=X(4)^2/X(1)-mi/X(1)^2+beta/X(1)^2*cos(alfa)^3;
dw(4)=-X(3)*X(4)/X(1)+beta/X(1)^2*cos(alfa)^2*sin(alfa);
end
then i wrote the valuating function script for the PSO has follow:
function J = Jarc(In)
load D:\Documents\MATLAB\Traiettorie\SecondoTentativo\Variabili\optionsode.mat
load D:\Documents\MATLAB\Traiettorie\SecondoTentativo\Variabili\mi.mat
load D:\Documents\MATLAB\Traiettorie\SecondoTentativo\Variabili\beta.mat
load D:\Documents\MATLAB\Traiettorie\SecondoTentativo\Variabili\Rm.mat
load D:\Documents\MATLAB\Traiettorie\SecondoTentativo\Variabili\Rt.mat
%Pesi
A= 10000; %Raggio
B= 1000; %Radiale
C= 1000; %Tangenziale
[t1,X1]=ode45(@(t,A)eqni_archi(t,A,In(1),beta,mi), [0 In(4)*24*60*60] , [Rt, 0, 0, sqrt(mi/Rt)] ,optionsode);
[t2,X2]=ode45(@(t,A)eqni_archi(t,A,In(2),beta,mi), [0 In(5)*24*60*60] , X1(end,1:4) ,optionsode);
[t3,X3]=ode45(@(t,A)eqni_archi(t,A,In(3),beta,mi), [0 In(6)*24*60*60] , X2(end,1:4) ,optionsode);
J = (abs(In(4)+In(5)+In(6)))+A*abs(Rm-X3(end,1))/Rm+B*abs(sqrt(mi/Rm)-X3(end,4))/sqrt(mi/Rm)+C*abs(X3(end,3))/sqrt(mi/Rm);
Then there is a last external scripts to run the PSO, but it works i've tested it already.
I never did an ODE integration with additional input other then the variables. Running the "Jarc" function with In=[1,1,1,2,2,2] (that are not the wanted value but just a trial) lead to the error related to this rows:
[t1,X1]=ode45(@(t,A)eqni_archi(t,A,In(1),beta,mi), [0 In(4)*24*60*60] , [Rt, 0, 0, sqrt(mi/Rt)] ,optionsode);
[t2,X2]=ode45(@(t,A)eqni_archi(t,A,In(2),beta,mi), [0 In(5)*24*60*60] , X1(end,1:4) ,optionsode);
[t3,X3]=ode45(@(t,A)eqni_archi(t,A,In(3),beta,mi), [0 In(6)*24*60*60] , X2(end,1:4) ,optionsode);
Errors:
>>Jarc([1,1,1,2,2,2])
Not enough input arguments.
Error in beta (line 19)
y = exp(betaln(z,w));
Error in Jarc>@(t,A)eqni_archi(t,A,In(1),beta,mi) (line 16)
[t1,X1]=ode45(@(t,A)eqni_archi(t,A,In(1),beta,mi), [0 In(4)*24*60*60] , [Rt, 0, 0, sqrt(mi/Rt)] ,optionsode);
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 Jarc (line 16)
[t1,X1]=ode45(@(t,A)eqni_archi(t,A,In(1),beta,mi), [0 In(4)*24*60*60] , [Rt, 0, 0, sqrt(mi/Rt)] ,optionsode);
I don't understand why, all the variables should be declared. Also alfa beta and mi are scalars while X is a 4 components vectors.
Thank you in advance.
2 comentarios
darova
el 25 de Nov. de 2019
What these lines mean?
Error in beta (line 19)
y = exp(betaln(z,w));
Respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!