Solutions using ODE with different initial conditions

3 ビュー (過去 30 日間)
Charles
Charles 2011 年 9 月 29 日
I wish to take the difference between two solutions with different initial conditions to a driven nonlinear oscillator. It is of interest to examine the sensitivity to initial conditions. The solutions to ODE are vectors of different lengths. To take the difference they need to be vectors of the same size, hence the issue. How does one do this? Thanks for any help. Chuck

回答 (2 件)

Matt Tearle
Matt Tearle 2011 年 9 月 29 日
As well as Walter's solution, you can also simply specify fixed timesteps for ode45 to use:
tvals = % make a vector of time points here
[t,y] = ode45(@odefun,tvals,y0);
Note that ode45 will still use a variable timestep, but it will just return solution values at the requested time points.
  1 件のコメント
Jan
Jan 2011 年 9 月 29 日
+1: Actually ODE45 is a interpolator on steroids, so it is efficient to let it perform the interpolation implicitely.

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


Walter Roberson
Walter Roberson 2011 年 9 月 29 日
If you know the time range for each, you could interp() the solution vector of each on to a constant time range.
For example,
[T1,Y1] = ode45(....); %first run
[T2,Y2] = ode45(....); %second run
gridpoints = 50; %regrid to 50 points (say)
allT = [T1(:),T2(:)];
minT = min(allT);
maxT = max(allT);
uniformT = linspace(minT,maxT,gridpoints);
newY1 = interp(T1, Y1, uniformT);
newY2 = interp(T2, Y2, uniformT);
You may need to do a minor amount more work if Y1 or Y2 has multiple columns.

カテゴリ

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