ode45 is not evluated at requried interval?

1 回表示 (過去 30 日間)
Michael Kollmann 036893899
Michael Kollmann 036893899 2018 年 12 月 2 日
Greetings,
I'm trying to run the following code for solving the linear 2nd order ODE y''=y+1; for 0<=x<=10, with boundary condituions y(0)=1, y(10)=0, and a step size of h=0.01. I give only the first part of the code, because this is where I face this issue.
The code was pretty much used as is from this page : https://www.mathworks.com/help/symbolic/odetovectorfield.html#bvlvtw5-1
*--------*
clear all; clc;
h=0.01;
xspan=[0:h:10];
y1=[1 1];
syms y(x)
[V] = odeToVectorField(diff(y, 2) == (y+1));
M = @(x,Y)[Y(2); Y(1)+1];
sol1=ode45(M,xspan,y1);
*--------*
the solution I get is:
*--------*
sol1 =
struct with fields:
solver: 'ode45'
extdata: [1×1 struct]
x: [0 0.0100 0.0600 0.3100 1.1195 2.1035 3.1035 4.1035 5.1035 6.1035 7.1035 8.1035 9.1035 10]
y: [2×14 double]
stats: [1×1 struct]
idata: [1×1 struct]
*--------*
The question is why the resulting y vector is solved for the given x and not in the intervals I specified in xspan?
I know ode45 solves for its own step size, but as far as I understand it is still supposed to be evaluated in the intreval above mentioned
Thanks so much in advance
Michael

採用された回答

Stephan
Stephan 2018 年 12 月 2 日
編集済み: Stephan 2018 年 12 月 2 日
Hi,
you get this if you specify the ode45 call this way:
[x, y]=ode45(M,xspan,y1);
Note that this forces Matlab to calculate much more points as needed with respect to a solution inside the tolerance range.
Best regards
Stephan
  1 件のコメント
Michael Kollmann 036893899
Michael Kollmann 036893899 2018 年 12 月 5 日
編集済み: Michael Kollmann 036893899 2018 年 12 月 5 日
Dear Stephan,
This was very helpful, thanks a lot and sorry for the late reply.
Best,
Michael

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

その他の回答 (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