寻找三阶 ODE 和直线之间的交点?
如何找到三阶 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要查找交点的数值:
创建一个匿名函数,该函数在您的解与您要查找的线之间的交点处为零:
然后,如果您想以图形方式查找值:
或通过优化例程以数字方式查找:
它将查找函数的零接近 0。它不会找到所有零,因此您需要在您期望交集的值附近启动 fzero 函数。
希望这会有所帮助,
安德鲁
编辑:二分法的操作方法。
一旦我们有了匿名一维函数“my_func”,如果您不想使用优化方法来求解方程,但碰巧知道一个范围 [range_{min} range_{max}],其中 my_func = 0 那么如果您使用的是连续函数,以下算法将为您找到函数的零:
所以一些解释:如果函数是连续的,并且您的函数是连续的,那么如果它在 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:
then, if you want to find the values graphically:
or numerically, by optimization routine:
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:
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