Help with coding (integral)
조회 수: 20 (최근 30일)
이전 댓글 표시
How can i solve this integral ((1/5*x)+1)*sqrt(1+exp(-2x)) by using Simpsons method? The upper limit is 1 and the lower limit is 0. I know how to solve it, but i keep getting these errors. It says "Invalid expression. Check for missin multiplication operator...".
댓글 수: 3
채택된 답변
Stephan
2020년 11월 10일
Typo in line 18 - use sum_f instead of sum_ f
a = 0;
b = 1;
n = 20;
m = n/2;
dx = (b-a)/n;
x = a;
sum_f = ((1/5*a)+1).*sqrt(1+exp(-2*a));
eqn = @(x) ((1/5*x)+1).*sqrt(1+exp(-2*x));
for i = 1:m-1
x = x + dx;
sum_f = sum_f + 4*((1/5*x)+1).*sqrt(1+exp(-2*x));
x = x + dx;
sum_f = sum_f + 2*((1/5*x)+1).*sqrt(1+exp(-2*x));
end
x = x + dx;
sum_f = sum_f + 4*((1/5*x)+1).*sqrt(1+exp(-2*x));
sum_f = sum_f + b/((1/5*b)+1).*sqrt(1+exp(-2*b));
댓글 수: 0
추가 답변 (1개)
David Hill
2020년 11월 10일
a = 0; b = 1; n = 20;
h = (b-a)/n;
x = linspace(a,b,n+1);
f = ((1/5*x)+1).*sqrt(1+exp(-2*x));
F = h/3*(f(1)+2*sum(f(2:2:end-1))+4*sum(f(1:2:end-1))+f(end));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!