寻找三阶 ODE 和直线之间的交点?

发布于 2024-10-16 11:34:56 字数 173 浏览 3 评论 0原文

如何找到三阶 ODE 的解与直线 y=x 之间的交点?

我的 ODE 代码是

sol=dsolve('D3y-4*D2y+Dy+2*y=0,y(0)=-4,Dy(0)=-6,D2y(0)=-4')
x=0:2
y=subs(sol,'t',x)
plot(x,y)

How can I find the intersection points between the solution of a 3rd order ODE and a line y=x?

My ODE's code is

sol=dsolve('D3y-4*D2y+Dy+2*y=0,y(0)=-4,Dy(0)=-6,D2y(0)=-4')
x=0:2
y=subs(sol,'t',x)
plot(x,y)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人事已非 2024-10-23 11:34:56

要查找交点的数值:

创建一个匿名函数,该函数在您的解与您要查找的线之间的交点处为零:

sol = dsolve('D3y-4*D2y+Dy+2*y=0,y(0)=-4,Dy(0)=-6,D2y(0)=-4');
my_func = @(x) subs(sol,'t',x) - x; % Your solution - x is equal to zero at the %intersections

然后,如果您想以图形方式查找值:

plot(-5:.01:5,my_func(-5:.01:5))

或通过优化例程以数字方式查找:

x = fzero(my_func,0); % I find x = -.6847

它将查找函数的零接近 0。它不会找到所有零,因此您需要在您期望交集的值附近启动 fzero 函数。

希望这会有所帮助,

安德鲁

编辑:二分法的操作方法。

一旦我们有了匿名一维函数“my_func”,如果您不想使用优化方法来求解方程,但碰巧知道一个范围 [range_{min} range_{max}],其中 my_func = 0 那么如果您使用的是连续函数,以下算法将为您找到函数的零:

range_min = 0; % say our range is [0 2]
range_max = 2;

error_tolerance = .0001; % will find the answer to within .0001

while (range_max - range_min < error_tolerance)
range_temp = (range_max + range_min)/2;
if ((my_func(range_temp) <0 & my_func(range_max)>0) | (my_func(range_temp) >0 & my_func(range_max)<0))
range_min = range_temp;

else if ((my_func(range_min)<0 & my_func(range_temp)>0) | (my_func(range_min)>0 & my_func(range_temp)<0))
    range_max = range_temp;

else if (my_func(range_temp == 0)
range_min = range_temp;
range_max = range_temp;

    end

end

t_intersection = (range_min + range_max)/2;

所以一些解释:如果函数是连续的,并且您的函数是连续的,那么如果它在 t_intersection 处与 y=t 相交,则在我们修改后的函数处my_func(t) = sol(t)-t 在 t_intersection 处为零。由于 my_func 是连续的,因此只要我们知道函数的两个值,一个大于零,一个小于零,我们就可以找到函数的零。

因此,我们从这些已知点开始,定义一个范围 [range_min range_max],其中 my_func(range_min)<0 和 my_func(range_max)>0 或反之亦然。然后我们通过创建中点 range_temp =mean(range_min 和 _max) 将这个范围减半。现在,我们创建一个新范围 [range_temp range_max] 或 [range_min range_temp],以便在该范围内保留 my_func 的符号变化。我们重复这个过程,直到达到满意的精度。

但需要注意的是,这只会在您提供的初始范围内找到一个零。这是大多数零查找方法的根本挫败之处,更普遍的是,零查找可以被视为优化领域的特殊情况。

我认为这涵盖了它,祝你好运。

——安德鲁

To find the numerical values of the intersections:

Create an anonymous function that is zero at the intersections between your solution and the line you seek:

sol = dsolve('D3y-4*D2y+Dy+2*y=0,y(0)=-4,Dy(0)=-6,D2y(0)=-4');
my_func = @(x) subs(sol,'t',x) - x; % Your solution - x is equal to zero at the %intersections

then, if you want to find the values graphically:

plot(-5:.01:5,my_func(-5:.01:5))

or numerically, by optimization routine:

x = fzero(my_func,0); % I find x = -.6847

which will look for a zero of the function near to 0. It will not find all the zeros so you will need to start the fzero function near values where you expect the intersections to be.

Hope this helps,

Andrew

Edits: a how to of the bisection method.

Once we have our anonymous one dimensional function "my_func" if you don't want to use an optimization method to solve the equation, but happen to know a range [range_{min} range_{max}]in which my_func = 0 then the following algorithm will find the zero of the function for you, provided you're working with a continuous function:

range_min = 0; % say our range is [0 2]
range_max = 2;

error_tolerance = .0001; % will find the answer to within .0001

while (range_max - range_min < error_tolerance)
range_temp = (range_max + range_min)/2;
if ((my_func(range_temp) <0 & my_func(range_max)>0) | (my_func(range_temp) >0 & my_func(range_max)<0))
range_min = range_temp;

else if ((my_func(range_min)<0 & my_func(range_temp)>0) | (my_func(range_min)>0 & my_func(range_temp)<0))
    range_max = range_temp;

else if (my_func(range_temp == 0)
range_min = range_temp;
range_max = range_temp;

    end

end

t_intersection = (range_min + range_max)/2;

So some explanation: if the function is continuous, and yours is, then if it intersects y=t at t_intersection then at our modified function my_func(t) = sol(t)-t will have a zero at t_intersection. Since my_func is continuous then we can find a zero of the function provided we know two values of the function, one that is greater than zero and one that is less than zero.

So we start with these known points and define a range [range_min range_max] where either my_func(range_min)<0 and my_func(range_max)>0 or vise-versa. Then we cut this range in half, by creating the midpoint range_temp = mean(range_min and _max). We now create a new range [range_temp range_max] or [range_min range_temp] so that we preserve a sign change of my_func over the range. We repeat this process until we reach a satisfactory accuracy.

One caveat though, this will only find one zero within the initial range you provide. That is a fundamental frustration with most zero finding methods, and more generally the field of optimization of which zero finding can be considered a special case.

I think that covers it, good luck.

--Andrew

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文