Prev: Problems with parfor, sim and non local workers
Next: How to use matlab functions as callback functions in dll's?
From: Charbel on 29 Jun 2010 05:16 Hey, I'm trying to do a differential equation using Matlab: I'm trying to identify the temperature evolution in a Diesel Engine, so my equation is written as follows: dT=-(1/m*Cv)*(m*r*(dV/V)*T+(k*S*T^0.25(T-515))/(6*N)) or m,r,N are constants V is the cylinder volume, varying function of the cranck angle (theta) ( V is a vector of 720 data point) dV is the volume derivative, also known and is varying function of theta... (720 datapoint) k,Cv, and S are also varying function of theta (720 datapoint each vector) and dT will be function of theta also and T0=295; According to Matlab, and Regardless of the solver, the ODE is written as follows: [Temp,Y]=solver(dT,[0:720],295); My questions are : - which solver works in my case - [0:720] we need to switch it to time so we can have dT/dt? ( [0:720] are in Cranck angle]....[0:720]*(6*N) ( CA----->sec) ..... and if we want dT/dtheta we switch from CA to radian by multiplying [0:720]*pi/180 ( CA----->radian) - k,Cv,S,dV and V varies function of theta.... Should i insert a counter 'i' that varies with theta in the dT equation? dT=-(1/m*Cv(i))*(m*r*(dV(i)/V(i))*T+(k(i)*S(i)*T^0.25(T-515))/(6*N)) For the users familiars with the ODEs in Matlab, this should be a simple question. Unfortunately i'm not one of them.... Best Regards. Charbel
From: Steven Lord on 29 Jun 2010 09:30 "Charbel " <charboul23(a)hotmail.com> wrote in message news:i0cdkl$ku$1(a)fred.mathworks.com... > Hey, > > I'm trying to do a differential equation using Matlab: I'm trying to > identify the temperature evolution in a Diesel Engine, so my equation is > written as follows: > > dT=-(1/m*Cv)*(m*r*(dV/V)*T+(k*S*T^0.25(T-515))/(6*N)) > > or m,r,N are constants > > V is the cylinder volume, varying function of the cranck angle (theta) ( V > is a vector of 720 data point) > > dV is the volume derivative, also known and is varying function of > theta... (720 datapoint) Since this appears on the right-hand side you're going to have to interpolate this for values of theta for which you don't actually have a data point. See INTERP1. > k,Cv, and S are also varying function of theta (720 datapoint each vector) See above. > and dT will be function of theta also And you're looking for T(theta)? > and T0=295; > > According to Matlab, and Regardless of the solver, the ODE is written as > follows: > [Temp,Y]=solver(dT,[0:720],295); > > My questions are : - which solver works in my case That depends on how stiff your problem is. Start off with ODE45 and if that takes too long or says something about not being able to reduce the step size enough, try one of the stiffer solvers. There's a table in DOC ODE45 that explains which solvers handle nonstiff problems and which handle stiff problems. > - [0:720] we need to switch it to time so we can have dT/dt? ( [0:720] > are in Cranck angle]....[0:720]*(6*N) ( CA----->sec) No, you can solve dT/dtheta = f(theta, T) just fine. > .... and if we want dT/dtheta we switch from CA to radian by multiplying > [0:720]*pi/180 ( CA----->radian) > > - k,Cv,S,dV and V varies function of theta.... Should i insert a counter > 'i' that varies with theta in the dT equation? No, but as I said above you will need to interpolate/evaluate each of these vectors/functions at values of theta for which you may not have exact data (i.e. if you know the values of V(theta) for theta = 0:720, you may need to interpolate for V(theta = 45.63). Try following one of the examples given in HELP ODE45 and/or this documentation page, then try writing up your own. If you encounter difficulties while writing up your own problem, post what you've tried to the newsgroup and explain where you're having trouble and someone may respond. -- 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: Charbel on 30 Jun 2010 04:23 Hey Steve, I did as u suggested: 1st: I interpolated all the variables used in the dydt equation that are already known to me 2nd: i have created an m.file named myode as follows: function dydt=odefun(t,y) % with a the time intervall and y is the temperature ..... .... .... % at the end dydt=-(1/m*Cv)*((m*r*(dV_interp/V_interp))*y+(h_interp*S_interp*(y-515)/(6*N)); % with all the variables already known are interpolated all over the t intervall and m,r and N are constants... 3rd: i saw the examples in the Matlab help for ode45 and after saving my m.file(odefun) i wrote this in my command window: [T Y]=ode45('odefun',[0 720/(6*4000)],295); i've obtained the following error: Error using ==> funfun\private\odearguments Solving ODEFUN requires an initial condition vector of length 1. Error in ==> ode45 at 173 [neq,tspan,..... althought the initial condition is defined as 295 in my function call... Did i do anything wrong? Best Regards
From: Steven Lord on 30 Jun 2010 09:52
"Charbel " <charboul23(a)hotmail.com> wrote in message news:i0eutr$rot$1(a)fred.mathworks.com... > Hey Steve, > I did as u suggested: > > 1st: I interpolated all the variables used in the dydt equation that are > already known to me > > 2nd: i have created an m.file named myode as follows: > function dydt=odefun(t,y) % with a the time intervall and y is the > temperature > .... > ... > ... > % at the end > dydt=-(1/m*Cv)*((m*r*(dV_interp/V_interp))*y+(h_interp*S_interp*(y-515)/(6*N)); > % with all the variables already known are interpolated all over the t > intervall and m,r and N are constants... > > 3rd: i saw the examples in the Matlab help for ode45 > and after saving my m.file(odefun) i wrote this in my command window: > [T Y]=ode45('odefun',[0 720/(6*4000)],295); > > i've obtained the following error: > Error using ==> funfun\private\odearguments > Solving ODEFUN requires an initial condition vector of length 1. > Error in ==> ode45 at 173 > [neq,tspan,..... > > althought the initial condition is defined as 295 in my function call... > > Did i do anything wrong? There's a known issue with the error message that you received -- length 1 is the length of the initial condition vector you passed in, but it's expecting something of a different size. More than likely you need to perform elementwise operations in your ODE function; to check this, call your ODEFUN with inputs 0 (for t) and 295 (for y) and look at the size of the result. In this case it should return a scalar value; I'm guessing it does not. Modify your ODEFUN so it does return a scalar. -- 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 |