How to solve (find zero) of nonanalitical function fzero or fsolve ?

1 回表示 (過去 30 日間)
Ole
Ole 2015 年 5 月 9 日
編集済み: Image Analyst 2015 年 5 月 9 日
I have a vector y(x) that does not necessarily have point on y = 0 axis (and is not analytical function).
How can I solve (find the zero crossing) without fitting.
For example:
y = [-1 -0.3 -4 -0.1 0.25 0.4 0.2 0.9 ]
x = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7]
I would like to solve for y(x)=0

採用された回答

Star Strider
Star Strider 2015 年 5 月 9 日
This works:
y = [-1 -0.3 -4 -0.1 0.25 0.4 0.2 0.9];
x = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7];
yx = find(y>0,1,'first'); % Choose 1st ‘y’ Point >0
y0 = 0;
x0 = interp1(y(yx-1:yx),x(yx-1:yx),y0); % Find Zero Cross Between Bracket Points
figure(1)
plot(x, y)
hold on
plot(x0, y0, 'bp')
hold off
grid
  1 件のコメント
Image Analyst
Image Analyst 2015 年 5 月 9 日
編集済み: Image Analyst 2015 年 5 月 9 日
Of course that's fitting a line between adjacent points, which makes perfect sense. Sam answer I would have given. I never did figure out why "not fitting" was a requirement. Who cares as long as it gets the job done? You could also use splines (demo attached).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by