please help
i am writting a code for the trapz rule for numerical integration and i keep getting that error
Array indices must be positive
integers or logical values.
Error in sym/subsref (line 900)
R_tilde =
builtin('subsref',L_tilde,Idx);
Error in tarpz (line 12)
y(i) = F(x(i));
and that is my code
clc
clear all
syms x
A = input('the upper limit = ');
B = input (' the lower limit = ');
N = input (' number of intervals = ');
H = (B-A)/N;
F = input ('function = ');
sum = 0;
for i = 1:1:N-1
x(i) = A + i * H;
y(i) = F(x(i));
sum=sum+y(i);
end
Area = H/2*(F(A)+F(B)+2*sum);
fprintf (' integration value is %.4f\n',Area);

 채택된 답변

Star Strider
Star Strider 2020년 4월 9일

0 개 추천

The Symbolic Math Toolbox does knt know that ‘F’ is a function.
Try this instead:
F(x) = input ('function = ');
That worked when I tried it.

댓글 수: 2

Hazem Abouzeid
Hazem Abouzeid 2020년 4월 9일
yeah it worked thank you so much
Star Strider
Star Strider 2020년 4월 9일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

질문:

2020년 4월 9일

댓글:

2020년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by