I need to add time varying component to the equation to be solved,i need to read these parameters at every time step and include the variation in the equations to be solved.Can anyone assist me on this?
Show older comments
for eg X = X1 + T1 + X2 + X3 + X4+ X5+Xdash;
Xdash is the time varying component, I am integrating the above equation and the value of Xdash changes at every time step at the same time the integration also takes place. I am planning to read the variable Xdash from an external file at every time step. can these type of problems be solved easily.
12 Comments
Torsten
on 3 Mar 2015
What do you mean by "I'm integrating the above equation" ?
Best wishes
Torsten.
deep
on 12 Mar 2015
Torsten
on 12 Mar 2015
Take a look at MATLAB's ODE solvers, e.g. ODE45.
Best wishes
Torsten.
deep
on 13 Mar 2015
Roger Stafford
on 13 Mar 2015
Either you are talking about a procedure in which the "Xdash" values have already been calculated, or else in which these values are being furnished in real time.
In the first case, you need to somehow import these values into a matlab array where they can be used in the standard numerical integration process.
In the second case, you have posed a nearly impossible problem. Matlab's integration procedures do not in ordinary circumstances operate in real time. It would either proceed too fast or too slow, or perhaps a combination of both. I would suppose that if it is such that matlab can be guaranteed to always take each time step more quickly than in real time, you could pull some trick with the 'pause' function to keep the time aligned properly and you might get a crude approximation of your desired distance, but I wouldn't count on it to be very accurate.
The same is true if you are solving a differential equation with time as the independent variable.
deep
on 13 Mar 2015
Torsten
on 13 Mar 2015
If Xdash has already been calculated and you have two arrays, one with the times and another with Xdash at these times, use MATLAB's interp1 to interpolate Xdash to the time requested by the solver in the routine where you supply the time derivatives for X.
Best wishes
Torsten.
deep
on 16 Mar 2015
deep
on 17 Mar 2015
Torsten
on 17 Mar 2015
Look at the variables supplied in the function subroutine from ODE45: these are the actual time t and the solution variables y. Now if you make a call to MATLAB's interpolation routine interp1 in the function subroutine as
Xdash = interp1(T,X,t)
with your predefined arrays T and X, you get an interpolated value for X at time t.
Does this answer your question ?
Best wishes
Torsten.
deep
on 17 Mar 2015
deep
on 18 Mar 2015
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!