how to reset/change the initial data?

6 ビュー (過去 30 日間)
Rose
Rose 2012 年 7 月 26 日
Hi there, I am working on a non linear system of 4 ordinary differential equations with time varying coefficients. I solved them numerically using ode 15s. It worked well. But now i want to stop my solver every 2 or 3 years and change/reset the initial data and run it again. I dont know how to do it. Any guidance/help is greatly appreciated.
  2 件のコメント
John Petersen
John Petersen 2012 年 7 月 26 日
How did you start it in the first place? Can't you just do that?
Rose
Rose 2012 年 7 月 26 日
i gave certain initial values to the dependent variables in he beginning and ran the code for almost 20 years. but now i want to change/ rest the initial values every 2 or 3 years. i am not sure how to do this.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2012 年 7 月 26 日
編集済み: Star Strider 2012 年 7 月 26 日
You can give the ODE solvers a vector of time points at which to evaluate your ODE function. I've done this often, especially because it constrains the integration time without significantly affecting the accuracy of the integration.
From the documentation for the ODE solvers http://www.mathworks.com/help/techdoc/ref/ode23.html :
tspan — A vector specifying the interval of integration, [t0,tf]. The solver imposes the initial conditions at tspan(1), and integrates from tspan(1) to tspan(end). To obtain solutions at specific times (all increasing or all decreasing), use tspan = [t0,t1,...,tf].
For tspan vectors with two elements [t0 tf], the solver returns the solution evaluated at every integration step. For tspan vectors with more than two elements, the solver returns solutions evaluated at the given time points. The time values must be in order, either increasing or decreasing.
  4 件のコメント
Rose
Rose 2012 年 8 月 1 日
but i got the error:
??? Index exceeds matrix dimensions.
Error in ==> mai at 30 sol(2)=sol(2)-sol(2).*0.6;
Star Strider
Star Strider 2012 年 8 月 1 日
編集済み: Star Strider 2012 年 8 月 1 日
I do not know what the dimensions of ‘sol’ are, but you later refer to it as a structure ‘sol.x’ and ‘sol.y’, and then in your plot command you refer to Y being an [N x 4] matrix. I suspect you need to refer to it differently in the line that gives you the error. (I do not know what you want to do in that line so I cannot suggest a way to correct it.)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by