parvector not able to pass
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Devyani
el 18 de Oct. de 2014
Comentada: Star Strider
el 18 de Oct. de 2014
I have created this simple functon file to call other functions.
function [conc ] = getconc( expConditions,parVector )
c(1) = expConditions(1);
c(2) = expConditions(2);
c(3) = expConditions(3);
[t cout1] = ode45('model1',[0:1:9],expConditions);
[t cout2] = ode45('model2',[0:1:9],expConditions);
[t cout3] = ode45('model3',[0:1:9],expConditions);
[t cout4] = ode45('model4',[0:1:9],expConditions);
[t cout5] = ode45('model5',[0:1:9],expConditions);
[t cout6] = ode45('model6',[0:1:9],expConditions);
[t cout7] = ode45('model7',[0:1:9],expConditions);
[t cout8] = ode45('model8',[0:1:9],expConditions);
[t cout9] = ode45('model9n',[0:1:9],expConditions);
[t cout10] = ode45('model10',[0:1:9],expConditions);
conc=[cout1(:,1) cout2(:,2) cout3(:,1) cout4(:,2) cout5(:,1) cout6(:,2) cout7(:,1) cout8(:,2) cout9(:,1) cout10(:,2)];
end I give inputs for expConditions and parVector as [1 1 1 1 1 1 1 1 1 1] and [5 5 50]. I am getting the following error :
Attempted to access parVector(1); index out of bounds because numel(parVector)=0.
The parVector input is required in my function files which i am calling for ode45solver. example for ne model function file is as follows
function [fdot] = model1(t,c,parVector )
r=-parVector(1);
fdot(1)=r;
fdot(2)=r;
fdot(3)=0;
fdot=fdot'
I am calling function as follows:
>> parVector=[1 1 1 1 1 1 1 1 1 1];
>> expConditions=[5 5 50];
>> getconc(parVector,expConditions);
0 comentarios
Respuesta aceptada
Star Strider
el 18 de Oct. de 2014
It is easiest to use the ‘anonymous function’ construction to pass ‘parVector’ to your ODE functions.
For example in ‘getconc’:
[t cout1] = ode45(@(t,c) model1(t,c,parVector ),[0:1:9],expConditions);
See if that does what you want. If it does, change your other ode45 calls to the same syntax.
4 comentarios
Más 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!