How to determine where the function is equal to zero

25 ビュー (過去 30 日間)
Lauren Stearns
Lauren Stearns 2017 年 5 月 10 日
コメント済み: Lauren Stearns 2017 年 5 月 11 日
Ultimately I need to figure out the first time my function is equal to zero, but to start I just want to save the x value as a new variable whenever y = 0. Here is my code so far:
close all; clear all; clc
% Prepared by Lauren Stearns
x= 0:10;
x(1)= 1E-5;
f= @(x) (2*besselj(1,x)./x).^2; % The Given Function
y=f(x) % replace the first element in the array
plot(x,y,'b-'); % Plot the Airy pattern
hold on;
xq=0:10; % Points of inquiry
xq(1)=0.0001;
yq3 = interp1(x,y,xq,'cubic'); % Cubic Interpolation
plot(xq,yq3,'b.'); % Plotting the Cubic Interpolation
for y = 0 % Trying to save the x value as a new variable
when y = 0
x = Dark_Fringe
end
xlabel('x');
ylabel('f(x)');
title('Airy Pattern Three');
disp(Dark_Fringe)

採用された回答

Matt J
Matt J 2017 年 5 月 10 日
編集済み: Matt J 2017 年 5 月 10 日
Ultimately I need to figure out the first time my function is equal to zero,
This is the simpler of the two problems. It is equivalent to finding where the bessel function is equal to zero. Using online tables or your plots, you can see that the first root lies in the interval [3.5,4.5]
>> [xroot,fval] = fzero(@(x) besselj(1,x), [3.5,4.5])
xroot =
3.8317
fval =
7.2971e-17
You can do similarly for the other roots in the interval [0,10]
  1 件のコメント
Lauren Stearns
Lauren Stearns 2017 年 5 月 11 日
It worked! Thank you so very much for your help! :D

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

その他の回答 (1 件)

Ahmed Hossam
Ahmed Hossam 2017 年 5 月 10 日
Try to use symbolic calculation to find 'the zeros'. Otherwise use numerical newton raphson algorithm.

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by