Not sure why vector changes assignment when using ode45
이전 댓글 표시
I am going to simplify the problem out of context as I believe this will be easier to understand, obviously I will be corrected if this is actually unhelpful.
There's 3 m files. Main, secondfun, thirdfun.
In main I have defined an 8 element vector i.e.
vector=[var1 var2 var3 var4 var5 var6 var7 var8]
In main I then call the second function with vector as one of the inputs i.e.
[out1, out2]=secondfun(in1, in2, in3, vector)
Where secondfun m file has secondfun(x,y,z,vector):
y0=[vector(1);vector(2);vector(3)]
[~,out3]=ode45(@thirdfun,t,y0,vector)
and thirdfun, thirdfun(~,vector) has:
out3=zeros(3,1);
out3(1)=(vector(5)-vector(1))/vector(7); *****
out3(2)=(vector(5)-vector(2))/vector(8);
out3(3)=(vector(4)-vector(3))/vector(6);
So running this I get the error that on the second line in thirdfun: Index exceeds matrix dimensions.
I narrowed this error down to where I'm using ode45 in secondfun. Before that line the vector function is a 8 element row vector as it should be. After that line it's turned into y0 only (3 element column vector), i.e. it's being passed into secondfun fine as far as I understand but I don't understand where or how it's being redefined as that?
Any advice on this would be much appreciated.
Thanks.
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!