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

 채택된 답변

Star Strider
Star Strider 2014년 10월 18일

0 개 추천

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

Devyani
Devyani 2014년 10월 18일
편집: Devyani 2014년 10월 18일
isn't this the same thing wht i have done? and ya its working now :)
Star Strider
Star Strider 2014년 10월 18일
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 2014년 10월 18일
yup its working thanks!
Star Strider
Star Strider 2014년 10월 18일
My pleasure!

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

추가 답변 (0개)

카테고리

질문:

2014년 10월 18일

댓글:

2014년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by