Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

interpolation - Matlab: Find a root of y-values given by a differential equation

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.

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!

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...