You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
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?
1 view (last 30 days)
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
deep
on 12 Mar 2015
I am numerically integrating the equation whose RHS is say velocity to obtain the distance. This equation in itself has a time varying component i.e Xdash in the eg. Can an integration be performed on a variable when the component comprising it also changes with time. Hope I am clear to you.
deep
on 13 Mar 2015
Thank you Torsten, I have implemented the integration, but i have to read a data at each time step from an external source(eg excel, or txt file) as i understand xlsread wont help to read at each timestep.Making it more clear i want my code to read the data from an external source at each step.Could you help me with this?
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
I am talking about the first case where Xdash is already been calculated and has to be called in to the code ,I am figuring out a suitable way for this.Any help would be appreciated Thank you for assisting me.This being my first query in the forum, im not sure how clear i was with my doubt.
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
Dear Torsten,Thank you for the suggestion to interpolate.I am new to Matlab ,i wanted to know how can i introduce or call my accumulated Xdash and time array into the code prior to doing the interpolation.Will Xlsread suffice.
deep
on 17 Mar 2015
I would like to clarify further, say i have a column matrix X with 300*1 elements, total run time is 300 with a step of 0.5, I need to read elements from the matrix in such a way that X11 is read at t1, X21 at t2,X31 at t3 and so on. Could you help with this?
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
Thank you once again.I am guessing this will resolve my issues.In case i face some further issues i would get back.Thank you for your quick responses highly appreciate it :)
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)