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 件のコメント

David Hill
David Hill 2020 年 11 月 10 日
What have you done? Your equation should be:
eqn=@(x)((1/5*x)+1).*sqrt(1+exp(-2*x));
leyla ahmed
leyla ahmed 2020 年 11 月 10 日
clear all
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));
leyla ahmed
leyla ahmed 2020 年 11 月 10 日
This is what i got now, but i still get the same error.

サインインしてコメントする。

 採用された回答

Stephan
Stephan 2020 年 11 月 10 日

0 投票

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));

その他の回答 (1 件)

David Hill
David Hill 2020 年 11 月 10 日

0 投票

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));

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2020 年 11 月 10 日

回答済み:

2020 年 11 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by