概述:

1  定积分概念

2  利用梯形求面积

1 clear all;
2 X1=[1 2 3 4 5 6 7]
3 z1=trapz(X1)
4 X2=[1 2 3;3 6 8;2 5 9]
5 z2=trapz(X2)
6 z3=trapz(X2,2)
7 x=[1 2 3]
8 z4=trapz(x,X2)

3  利用矩形求面积

1 clear all;
2 X1=[1 2 3 4 5 6 7]
3 z1=cumsum(X1)
4 X2=[1 2 3;3 6 8;2 5 9]
5 z2=cumsum(X2)
6 z3=cumsum(X2,1)
7 z4=cumsum(X2,2)
8 z5=cumsum(X2,3)
 1 clear all;
 2 x=0:0.01:5*pi;
 3 y=cos(x./2)\';
 4 z=cumsum(y)*0.01;
 5 z1=z(end)
 6 z2=trapz(x,y)
 7 figure;
 8 plot(x,y,\'r-\');
 9 hold on;
10 plot(x,z,\'b:\')
11 legend(\'被积函数\',\'积分曲线\'); 

4  单变量数值积分求解

1 function y=myfun1(x)
2 y=1./(sin(x)+exp(-x.^2));
1 clear all;
2 syms x;
3 f=inline(\'1./(sin(x)+exp(-x.^2))\')
4 y=quad(f,0,1.3)
5 y1=quad(@myfun1,0,1.3)
6 y2=quad(@myfun1,0,1.3,1.e-10)
1 clear all;
2 syms x;
3 f=inline(\'1./(sin(x)+exp(-x.^2))\',\'x\');
4 y=quadl(f,0,1.3)
5 y1=quadl(f,0,1.3,1.e-20)

5  双重积分求解

 

1 function z= integrnd(x,y)
2 z=y*sin(x)+x*cos(y);
1 clear all;
2 syms x;
3 f=inline(\'x*cos(y)+y*sin(x)\',\'x\',\'y\');
4 y=dblquad(f,pi,2*pi,0,pi)
5 y1=dblquad(@integrnd,pi,2*pi,0,pi)
6 y2=dblquad(@(x,y) x*cos(y)+y*sin(x),pi,2*pi,0,pi)

6  三重积分求解

1 clear all;
2 f=inline(\'z*cos(x)+y*sin(x)\',\'x\',\'y\',\'z\');
3 q=triplequad(f,0,pi,0,1,-1,1)
4 %采用匿名函数的形式
5 q1=triplequad(@(x,y,z) (y*sin(x)+z*cos(x)),0,pi,0,1,-1,1)
6 q2=triplequad(@(x,y,z) (y*sin(x)+z*cos(x)),0,pi,0,1,-1,1,1.e-10)
7 q3=triplequad(@(x,y,z) (y*sin(x)+z*cos(x)),0,pi,0,1,-1,1,1.e-10,@quad)

7  常微分方程

1 clear all;
2 f1=dsolve(\'Dy-y=sin(x)\')
3 f2=dsolve(\'Dy-y=sin(x)\',\'x\')

求微分方程的特解

1 clear all;
2 dsolve(\'Dy=a*y\',\'y(0)=b\')

求微分方程的解

1 clear all;
2 dsolve(\'D2y+2*Dy+exp(x)=0\',\'x\')

 

版权声明:本文为xiaochi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xiaochi/p/8890790.html