MATLAB中定积分求解
用int()函数方法求解
我们以求解e^x在[0,2]内的定积分为例。
∫
0
2
e
2
d
t
.
\int_0^2e^2dt\,.
∫02e2dt.
操作步骤如下:
1. 定义变量
在matlab命令窗口中输入命令:syms x
![matlab中显示](https://img-blog.csdnimg.cn/20200606124014235.png)
2. 再输入命令:y=exp(x)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200606124602148.png)
3. 最后计算定积分,输入命令:int1=int(y,x,0,2)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200606124739395.png)
得到如下图所示:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200606124940423.png)
这里的结果还没有得出最后值,需要利用vpa()函数来计算出精度得到值。
4.计算出精度。输入命令:f1=vpa(int1)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200606125645287.png)
最后得到e^x在[0,2]内的定积分结果为:6.389560…
所有代码如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200606130758821.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDQ2NTYxMw==,size_16,color_FFFFFF,t_70)