How do I fix this invalide expression error?

조회 수: 15 (최근 30일)
Connor
Connor 2023년 4월 18일
이동: Image Analyst 2023년 4월 21일
I keep receiving this error with my code:
Here is my code, Line 5 is in the "%Define the function handles" section, specifically "bessel0".
N = 1 + randi(15); % define number of zeros to be found, [1 16]
r = zeros(N,2); % preallocate r vector
% Define the function handles.
bessel0 = @x besselj(0, x);
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
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, 1) = 0;
r(1, 2) = bessel0(0);
for k = 2:N
x0 = r(k-1, 1) + pi;
r(k, 1) = fzero(bessel0, x0, options);
r(k, 2) = bessel0(r(k, 1));
end
r = sortrows(r);
%%%%%%%%%%% 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')

답변 (2개)

Chunru
Chunru 2023년 4월 18일
bessel0 = @(x) besselj(0, x);

Stephen23
Stephen23 2023년 4월 18일
이동: Image Analyst 2023년 4월 21일
bessel0 = @(x) besselj(0, x);
% ^ ^ missing parentheses

카테고리

Help CenterFile Exchange에서 Bessel functions에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by