Prev: axes tick
Next: problem optimization with fmincon
From: moussams SALEY on 25 Jul 2010 18:56 Hi I am a new new user of Matlab and have a system of non linear ODE but I am having a problem on the index. I have four variables T1,T2,T3,T4(T is the temperature) depending on time and varying with j. I would like to solve the system using ode45 and need your help on how I have to use the index with a loop to solve it. The coefficients K1 to K17 are known as well for the initial conditions. the system is: dT1dt(j)= K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5 dT2dt(j)= K6*T1(j)+K7*T3(j)+K8*(T1(j)).^4+K9*T2(j)+K10*(T2(j)).^4+K11 dT3dt(j)= K12*T2(j)+K13*T3(j)+K14*T3(j-1) dT4dt(j)= K15*T3(j)+K16*T4(j)+K17 j=1.....N For N=4, I have used this loop but it does not work: for j=1:4 if (j==1) dT1dt(1)= K1*T1(j)+K2*(T1(1)).^4+K3*T2(1)+K4*(T2(1)).^4+K5; dT2dt(1)= K6*T1(1)+K7*T3(1)+K8*(T1(1)).^4+K9*T2(j)+K10*(T2(1)).^4+K11; dT3dt(1)= K12*T2(1)+K13*T3(1)+K14*298; %T3(0)=298 dT4dt(1)= K15*T3(1)+K16*T4(1)+K17; else dT1dt(j)= K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5; dT2dt(j)= K6*T1(j)+K7*T3(j)+K8*(T1(j)).^4+K9*T2(j)+K10*(T2(j)).^4+K11; dT3dt(j)= K12*T2(j)+K13*T3(j)+K14*T3(j-1); dT4dt(j)= K15*T3(j)+K16*T4(j)+K17; end end and i have gotten a message: ??? Attempted to access T1(2); index out of bounds because numel(T1)=1. Error in ==> HYBRID at 138 dT1dt(j)=K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5; Thanks in advance for your help Best regards
From: us on 25 Jul 2010 20:05 "moussams SALEY" <moussa_mounk(a)yahoo.fr> wrote in message <i2ife4$j9i$1(a)fred.mathworks.com>... > Hi > I am a new new user of Matlab and have a system of non linear ODE but I am having a problem on the index. I have four variables T1,T2,T3,T4(T is the temperature) depending on time and varying with j. I would like to solve the system using ode45 and need your help on how I have to use the index with a loop to solve it. > The coefficients K1 to K17 are known as well for the initial conditions. > the system is: > dT1dt(j)= K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5 > dT2dt(j)= K6*T1(j)+K7*T3(j)+K8*(T1(j)).^4+K9*T2(j)+K10*(T2(j)).^4+K11 > dT3dt(j)= K12*T2(j)+K13*T3(j)+K14*T3(j-1) > dT4dt(j)= K15*T3(j)+K16*T4(j)+K17 > j=1.....N > > For N=4, I have used this loop but it does not work: > for j=1:4 > if (j==1) > dT1dt(1)= K1*T1(j)+K2*(T1(1)).^4+K3*T2(1)+K4*(T2(1)).^4+K5; > dT2dt(1)= K6*T1(1)+K7*T3(1)+K8*(T1(1)).^4+K9*T2(j)+K10*(T2(1)).^4+K11; > dT3dt(1)= K12*T2(1)+K13*T3(1)+K14*298; %T3(0)=298 > dT4dt(1)= K15*T3(1)+K16*T4(1)+K17; > else > dT1dt(j)= K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5; > dT2dt(j)= K6*T1(j)+K7*T3(j)+K8*(T1(j)).^4+K9*T2(j)+K10*(T2(j)).^4+K11; > dT3dt(j)= K12*T2(j)+K13*T3(j)+K14*T3(j-1); > dT4dt(j)= K15*T3(j)+K16*T4(j)+K17; > end > end > and i have gotten a message: > > ??? Attempted to access T1(2); index out of bounds because numel(T1)=1. > > Error in ==> HYBRID at 138 > dT1dt(j)=K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5; > > Thanks in advance for your help > Best regards well... the error message is rather self-explanatory: your var T1 is a scalar, ie, one single value - but you try to access values J = 1:4 us
From: Steven_Lord on 25 Jul 2010 22:52 "moussams SALEY" <moussa_mounk(a)yahoo.fr> wrote in message news:i2ife4$j9i$1(a)fred.mathworks.com... > Hi > I am a new new user of Matlab and have a system of non linear ODE but I am > having a problem on the index. I have four variables T1,T2,T3,T4(T is the > temperature) depending on time and varying with j. I would like to solve > the system using ode45 and need your help on how I have to use the index > with a loop to solve it. > The coefficients K1 to K17 are known as well for the initial conditions. > the system is: dT1dt(j)= K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5 > dT2dt(j)= K6*T1(j)+K7*T3(j)+K8*(T1(j)).^4+K9*T2(j)+K10*(T2(j)).^4+K11 > dT3dt(j)= K12*T2(j)+K13*T3(j)+K14*T3(j-1) > dT4dt(j)= K15*T3(j)+K16*T4(j)+K17 > j=1.....N Why do you have an index at the end of your dT*dt and T* variables? As the help for the ODE solvers indicate, your ODE function (the function you pass into the solver as the first input argument) should accept inputs t and y and return a variable dydt, the values of dy/dt at the time the function received as input. Therefore, I think all your (j) indices should be removed. However, there is one little wrinkle I just noticed. In the expression for dT3dt, you attempt to use the value of T3 at an earlier time. This means you do NOT have a system of ordinary differential equations; you have a system of _delay-differential equations_ instead. In that case, ODE45 is NOT the right tool for this job; you will need to use DDE23 or DDESD, which are very similar. Review the help and/or the reference page for those solvers for more information about how you will need to set up your code. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: moussams SALEY on 28 Jul 2010 05:36 "Steven_Lord" <slord(a)mathworks.com> wrote in message <i2ita5$h1e$1(a)fred.mathworks.com>... > > > "moussams SALEY" <moussa_mounk(a)yahoo.fr> wrote in message > news:i2ife4$j9i$1(a)fred.mathworks.com... > > Hi > > I am a new new user of Matlab and have a system of non linear ODE but I am > > having a problem on the index. I have four variables T1,T2,T3,T4(T is the > > temperature) depending on time and varying with j. I would like to solve > > the system using ode45 and need your help on how I have to use the index > > with a loop to solve it. > > The coefficients K1 to K17 are known as well for the initial conditions. > > the system is: dT1dt(j)= K1*T1(j)+K2*(T1(j)).^4+K3*T2(j)+K4*(T2(j)).^4+K5 > > dT2dt(j)= K6*T1(j)+K7*T3(j)+K8*(T1(j)).^4+K9*T2(j)+K10*(T2(j)).^4+K11 > > dT3dt(j)= K12*T2(j)+K13*T3(j)+K14*T3(j-1) > > dT4dt(j)= K15*T3(j)+K16*T4(j)+K17 > > j=1.....N > > Why do you have an index at the end of your dT*dt and T* variables? As the > help for the ODE solvers indicate, your ODE function (the function you pass > into the solver as the first input argument) should accept inputs t and y > and return a variable dydt, the values of dy/dt at the time the function > received as input. Therefore, I think all your (j) indices should be > removed. > > However, there is one little wrinkle I just noticed. In the expression for > dT3dt, you attempt to use the value of T3 at an earlier time. This means > you do NOT have a system of ordinary differential equations; you have a > system of _delay-differential equations_ instead. In that case, ODE45 is > NOT the right tool for this job; you will need to use DDE23 or DDESD, which > are very similar. Review the help and/or the reference page for those > solvers for more information about how you will need to set up your code. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > To contact Technical Support use the Contact Us link on > http://www.mathworks.com Dear, Thank you very much for your suggestions. Best regards
|
Pages: 1 Prev: axes tick Next: problem optimization with fmincon |