用matlab求积分问题
要求e^(x^2)在0到1上的积分,用矩形公式求,n的取值是10到100的所有整数。我这么写为什么不对?clc;clear;a=0;b=1;Lvalue=0forn=10...
要求e^(x^2)在0到1上的积分,用矩形公式求,n的取值是10到100的所有整数。我这么写为什么不对?
clc;
clear;
a = 0;
b = 1;
Lvalue = 0
for n = 10:1:100
for x = 0:(b-a)/n:1-(b-a)/n
Lvalue = Lvalue + exp(x^2)
Lvalue = (b-a)/n *Lvalue
end
end
Lvalue 展开
clc;
clear;
a = 0;
b = 1;
Lvalue = 0
for n = 10:1:100
for x = 0:(b-a)/n:1-(b-a)/n
Lvalue = Lvalue + exp(x^2)
Lvalue = (b-a)/n *Lvalue
end
end
Lvalue 展开
展开全部
用积分的定义式Σf(x)dx。
取N=100,则dx = 1/N =0.01
clc;
clear;
N = 100;
dx = 1/N;
x = 0:dx:1;
fx = exp(x.^2);
y = sum(fx*dx)
y =
1.4813
若想用for循环则
clc;
clear;
Lvalue = 0;
N = 100;
dx = 1/N;
for x = 0:dx:1
fx = exp(x^2);
Lvalue = Lvalue + fx*dx;
end
Lvalue
结果为
Lvalue =
1.4813
当N=10000时
Lvalue =
1.4628
取N=100,则dx = 1/N =0.01
clc;
clear;
N = 100;
dx = 1/N;
x = 0:dx:1;
fx = exp(x.^2);
y = sum(fx*dx)
y =
1.4813
若想用for循环则
clc;
clear;
Lvalue = 0;
N = 100;
dx = 1/N;
for x = 0:dx:1
fx = exp(x^2);
Lvalue = Lvalue + fx*dx;
end
Lvalue
结果为
Lvalue =
1.4813
当N=10000时
Lvalue =
1.4628
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询