how to rectify Index out of bounds error......
1 view (last 30 days)
Show older comments
Hai everyone, here is the code i am trying to attempt..but it's showing Attempted to access Tm(5); index out of bounds because numel(Tm)=4.
the code is
function Fv=funsys(t,Tm)
a1 = 1.71*10^(-3);
a2 = -0.0447;
a3 = -56.46*10^(-6);
b1 = -6.57*10^(-3);
b2 = 14.84*10^(-6);
Tm(1)= 773;
Tm(4)= 493;
Fv(1,1) = a1+(a2*(Tm(1)-300))+(a3*(Tm(1)-Tm(4)));
Fv(2,1) = a1+(a2*(Tm(2)-300))+(a3*(Tm(2)-Tm(5)));
Fv(3,1) = a1+(a2*(Tm(3)-300))+(a3*(Tm(2)-Tm(6)));
Fv(4,1) = (b1*((-3*Tm(4))+(4*Tm(5))+(-1*Tm(6))))+(b2*(Tm(1)-Tm(4)));
Fv(5,1) = (b1*((-1*Tm(4))+Tm(6)))+(b2*(Tm(2)-Tm(5)));
Fv(6,1) = (b1*((1*Tm(4))+(-4*Tm(5))+(3*Tm(6))))+(b2*(Tm(3)-Tm(6)));
please help me how to rectify my problem and also give suggestions how to solve this system of ode equations....reply me soon...
3 Comments
Jan
on 16 Apr 2015
Note: While 1.71*10^(-3) is an expensive calculation, 1.71e-3 is a constant. So prefer the 2nd.
Image Analyst
on 16 Apr 2015
How did you call this function? What did you send in for t and Tm? And have you seen this, which will definitely solve your problem.
Answers (2)
the cyclist
on 16 Apr 2015
Just adding a little specificity to what pfb commented on:
In the line
Fv(2,1) = a1+(a2*(Tm(2)-300))+(a3*(Tm(2)-Tm(5)));
you reference the element
Tm(5)
but you have not yet defined the Tm(5) element.
0 Comments
Star Strider
on 16 Apr 2015
Your initial conditions vector sets the length of ‘Tm’, so be sure it is a 6-element vector.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!