I dont understand why the variable x is incorrect.

Please explain to me what is wrong!

댓글 수: 4

John D'Errico
John D'Errico 2023년 4월 27일
편집: John D'Errico 2023년 4월 27일
It is so much easier to help you if you paste in the code itself, instead of a picture of your code. Why would you want to make it more difficult to get help?
N = 1 + randi(15); % define number of zeros to be found, [1 16]
r = zeros(N,2); % preallocate r vector
% Define the function handles.
syms x;
bessel0 = @(x) besselj(0,x);
bessel1 = @(x) besselj(1,x);
% Set the arguments for FZERO.
options = optimset('Display','none','TolX',1e-8);
% Develop iterative scheme for finding first N zeros of J0
r(1,:) = [bessel1(1)/bessel0(1), bessel0(bessel1(1)/bessel0(1))];
for n = 2:N
% Use previous extremum location as initial guess for current extremum
x0 = r(n-1,1) + pi;
% Find current extremum using fzero
r(n,:) = [fzero(bessel0, x0, options), 0];
% Calculate corresponding value of Bessel function for current extremum
r(n,2) = bessel0(r(n,1));
end
%%%%% Plot the function and the extrema %%%%%%%%%%.
% Define the x values.
%x = 0:0.1:30; % use this range when you are trying to get a sense of the problem
x = 0:0.1:r(N,1); % use this range when you want to see all your zeros
% make figure
figure; hold on; grid on;
plot(x,bessel0(x),'k')
plot(x,bessel1(x),'Color',[0.6350 0.0780 0.1840])
plot(r(:,1),r(:,2),'o','Color',[0 0.4470 0.7410])
plot(r(:,1),0*r(:,1),'x','Color',[0.4660 0.6740 0.1880])
axis([0 max(x) -1 1]);
legend('Bessel J of Order Zero','Bessel J of Order One','Extrema of Order Zero','Zeros of Order One')
Question:
What is the purpose of your syms x; line ?
Nam
Nam 2023년 4월 27일
i remove it and the answer is still wrong

댓글을 달려면 로그인하십시오.

답변 (1개)

Paul
Paul 2023년 4월 27일

0 개 추천

Hi Nam,
What is the justification for the computation of r(1,:)?
If you're trying to find the extrema of J0, why use fsolve to find points where J0 = 0?

댓글 수: 2

Nam
Nam 2023년 4월 27일
Hi Paul
What do you suggest? I don't really understand.
Paul
Paul 2023년 4월 27일
I'm afraid I can't be of much more help other than suggesting to reread:
the problem statement and figure out what the condition is for J0 to have an extremum, which will determine what needs to be solved using fsolve, and
reread item 4 to understand how to initialize the solution.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

태그

질문:

Nam
2023년 4월 27일

댓글:

2023년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by