Problem in generating iterations in 3/8 simpson rule
이전 댓글 표시
I want to make simpson rule algorithm for my function for different intervals (here, 3^p), and plot the error vs p. The code below is showing error in the use of syms in 1st line and the iteration of line 9 (Itr=Itr+f(N+1)/2). Please tell what is wrong in this and how can I correct it.
syms p
N=3^p;
h=1/N;
for i=1,N;
x=i*h;
f(i)=exp(-x^2)
Itr=f(1)/2;
Itr=Itr+(3/2)*f(i);
Itr=Itr+f(N+1)/2;
end
Itr=Itr*h;
for p=1,10;
plot(p,itr)
end
Error using sym/subsindex (line 857)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in sym/subsref (line 902)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in simpson3by8rule (line 9)
Itr=Itr+f(N+1)/2;
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!