parvector not able to pass

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);

 Risposta accettata

Star Strider
Star Strider il 18 Ott 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 Commenti

Devyani
Devyani il 18 Ott 2014
Modificato: Devyani il 18 Ott 2014
isn't this the same thing wht i have done? and ya its working now :)
Star Strider
Star Strider il 18 Ott 2014
No, because you are not passing ‘parVector’ to your ODE functions. The error is the result of your ODE function not being able to find ‘parVector’.
With my ode45 call syntax, your functions should integrate successfully.
Devyani
Devyani il 18 Ott 2014
yup its working thanks!
Star Strider
Star Strider il 18 Ott 2014
My pleasure!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by