how to rectify Index out of bounds error......

1 view (last 30 days)
Deepthi Birudu
Deepthi Birudu on 16 Apr 2015
Commented: Image Analyst on 16 Apr 2015
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
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
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.

Sign in to comment.

Answers (2)

the cyclist
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.

Star Strider
Star Strider on 16 Apr 2015
Your initial conditions vector sets the length of ‘Tm’, so be sure it is a 6-element vector.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!