Matlab:查找由微分方程给出的y值的根 [英] Matlab: Find a root of y-values given by a differential equation
问题描述
我已经解决了一个初始值微分方程,并绘制了ODE45给定的Y值.从图中可以隐约地知道根应该在哪里,但是在给定的任务中,我需要非常精确地找到它.
I've solved an initial value differential equation and plotted the Y values given by ODE45. From the plot I can vaguely tell where the root should be, but in the given task I need to find it with great accuracy.
我的第一个猜测是将多项式调整为X和Y值,然后求解多项式方程.但是我使用了polyfit并有69个已知值,这给了我68级的多项式,我无法解决.因此,有人知道我如何在不知道实际方程的情况下找到一组给定的Y值的根"吗?在任务中写道,应该使用插值!
My first guess was to adjust a polynom to my X and Y values, and then solve the polynom equation. But I used polyfit and had 69 know values which gave me a polynom of the 68grade which I couldn't solve. So, does anyone know how I could find a "root" to a set of given Y values without knowing the actual equation? It's written in the task that interpolation should be used!
提前谢谢!
推荐答案
给定一个Y值的向量(按照相应的X值稳定增长的顺序排列),您可能会很容易发现根位于哪个X值附近.根要么是Y值为零,要么是两个连续Y值之间的正负号,它们会更改符号.这个代码片段说明了这个想法:
Given a vector of Y values (ordered in the sense that the corresponding X values are steadily increasing), you may find easily near which X values the roots are located. The roots are either where a Y value is zero or between two consecutive Y values that change sign. The idea is illustrated in this code snippet:
X = -1:0.1:1;
Y = X.*X - 0.4;
root_exact_pos = find(Y==0);
root_approx_pos = find(diff(sign(Y))~=0);
根在X
值中,或者在X(root_exact_pos(k))
中,或者在X(root_approx_pos(k))
和X(root_approx_pos(k)+1)
之间,k
从1到各个根位置数组的元素数.
The roots are in the X
values, either in X(root_exact_pos(k))
, or between X(root_approx_pos(k))
and X(root_approx_pos(k)+1)
, k
going from 1 to the number of elements of the respective root position array.
从现在开始,您可以应用任何想要的插值来找到更好的根近似值(我想在两点之间使用线性).
From here on you may apply whatever interpolation you'd like to find a better approximation of the root (I would go with linear, between the 2 points).
这篇关于Matlab:查找由微分方程给出的y值的根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!