matlab 考试

%二重积分
%1
[x,y]=solve(‘y=’,’ ',‘x’,‘y’)
syms x y
f=x;
int(int(f,y,0,1),x,0,1)
%2 极坐标计算 r
clear
syms r f
int(int(r
rr,r,0,sqrt(2)),f,0,0.5pi)
%三重积分
%1 取投影面(二重积分),对第三轴积分
syms x y z
int(int(int(xyyzzz,z,0,xy),y,0,x),x,0,1)
%2 柱坐标 r
syms s r z
int(int(int(z
r,z,rr,sqrt(2-rr)),r,0,1),s,0,2pi)
%3 球坐标 rr
sin(f)
syms s f r a
int(int(int(rcos(f)rrsin(f),r,0,2acos(f)),f,0,0.25pi),s,0,2pi)
%弧长曲线积分
syms t
I=int(tt,t,1,0)+int(tt,t,0,2)+int((tt+(1-0.5t)^2)sqrt(1+0.25),t,2,0)
%坐标曲线积分 error!
syms s
A=3
int(sin(s)3+cos(s)3,s,0,0.5pi)
%面积曲面积分 一轴化为另两轴且微分 week5 1.3
A=3
int(int(sqrt(1+4rr)(2-rr)r,r,0,sqrt(2)),s,0,2pi)
%坐标曲面积分

-----------------------------week1---------------------------------
%1.1
syms x y
f=x/(1+x*y);
int(int(f,y,0,1),x,0,1)

%1.2
clear
syms x y
int(int(x/(y+1),y,2x,xx+1),x,0,1)

%1.3
clear
syms x y
int(int(1-x-y,y,0,1-x),x,0,1)

%2.1
clear
syms r f
int(int(rrr,r,0,sqrt(2)),f,0,0.5pi)
%2.2

clear
syms r f
int(int(1,r,0,sin(f)/(cos(f)cos(f))),f,0,0.25pi)
%2.3
clear
syms r f
int(int(r^(-2),r,1/(sin(f)+cos(f)),1),f,0,0.5pi)
%2.4
clear
syms r f
int(int(r
rsin(f)/cos(f),r,1/cos(f),2/cos(f)),f,0,0.25pi)

%3.1
clear
syms r f
int(int(2,r,0,cos(3*f)),f,0,(1/6)*pi)

%3.2
clear
syms r f
int(int(1,r,0,1-sin(f)),f,0,2pi)
%3.3

clear
syms r f
int(int(2,r,1+cos(f),3*cos(f)),f,0,(1/3)pi)
%3.4
clear
syms r f
int(int(1/r,r,1,3),f,0,2
pi)

--------------------week2--------------------------------
%1
syms x y z
int(int(int(xyyzzz,z,0,xy),y,0,x),x,0,1)
%2
syms s r z
int(int(int(zr,z,1,2),r,1,sqrt(2)),s,0,2pi)
%3
syms x y z
int(int(int(1/(1+x+y+z)^3,z,0,1-x-y),y,0,1-x),x,0,1)
%4
syms x y z
int(int(int(xz,z,0,y),y,xx,1),x,0,1)
%5.1
syms s r z
int(int(int(zr,z,rr,sqrt(2-rr)),r,0,1),s,0,2pi)
%5.2
syms s r z
int(int(int(rrr,z,0.5rr,2),r,0,2),s,0,2pi)
%6.1
syms s f r
int(int(int(r
rrrsin(f),r,0,1),f,0,pi),s,0,2pi)
%6.2
syms s f r a
int(int(int(rcos(f)rrsin(f),r,0,2acos(f)),f,0,0.25pi),s,0,2pi)

----------------------------------week3------------------------------
%1
syms t
I=int((sqrt(2)/3)t^(9/2)(1+t),t,0,1)
%2
clear
syms a t
I=int(a3*sin(t)2sqrt(2-2cos(t)),t,0,2pi)
%3
clear
syms a t b
I=int(a
abtcos(t)sin(t)sqrt(aa+bb),t,0,2pi)
%4
clear
syms a s
I=int(a0.5sqrt(0.5aa+0.5aacos(s)),s,0,2pi)
%5
clear
syms a s
I=int(12a(7/3)*sin(s)*cos(s)*(cos(s)4+sin(s)^4),s,0,0.5pi)
%7
clear
syms t
I=int(tt,t,1,0)+int(tt,t,0,2)+int((tt+(1-0.5t)^2)sqrt(1+0.25),t,2,0)
%8
clear
syms a s
I=int(a^3
(-cos(s)*cos(s)/2+sin(s)sin(s)/6),s,0,2pi)

-------------------------------------------week4---------------------------
%1:
syms a t
A=int(aasin(t)sin(t)+asin(t),t,0,2pi)
%2:
syms a s
A=int(sin(2
s),s,0,2pi)
%3:
syms t
A=int(14
t+6,t,0,1)
%4:
syms x
A=int(2x5-4*x4-2x^3+xx,x,1,-1)
%5:
syms a s
A=int(2+a
(exp(2s)+exp(-2s)),s,0,1)
%6:
syms x y
A=int(xx,x,1,2)+int(4-yy,y,0,1)+int(1+xx,x,2,1)+int(1-yy,y,1,0)
%7:
syms z
A=3int(-z^3/sqrt(1-zz)-1+zz,z,0,1)
% %
syms s
A=3
int(sin(s)3+cos(s)3,s,0,0.5pi)
%8.1:
syms x
A=int(x-6
x5-2*x3,x,0,1)
%8.2:
syms x
A=int(2x+xx,x,0,1)+int(2-2x+xx,x,1,2)

-------------------------------------week5------------------------------
syms r s x y a h
%1.1
A=int(int(sqrt(1+4rr)r,r,0,sqrt(2)),s,0,2pi)
%1.2
A=int(int(sqrt(1+4rr)rrr,r,0,sqrt(2)),s,0,2pi)
%1.3
A=3int(int(sqrt(1+4rr)(2-rr)r,r,0,sqrt(2)),s,0,2pi)
%2.1
A=int(int(sqrt(2)rr
r,r,0,1),s,0,2pi)
%2.2
A=int(int(2
rrr,r,0,sqrt(3)),s,0,2pi)
%3.1
A=int(int(4
sqrt(61)/3,y,0,3-3x/2),x,0,2)
%3.2
A=int(int(3
(2xy-2xx-3x+6-2y),y,0,3-x),x,0,3)
%3.3
A=int(int(ar,r,0,sqrt(aa-hh)),s,0,2pi)

------------------------------------------------week6----------------------------
syms x y z r s R
%1
A1=int(int(-r5*cos(s)2sin(s)2*sqrt(R2-r^2),r,0,R),s,0,2pi)
%2
A2=int(int(sqrt(1-yy),z,0,3),y,0,1)+int(int(sqrt(1-xx),z,0,3),x,0,1)
%3
A3=int(int(1,y,x-1,0),x,0,1)
%4
A4=int(int(x-xx-xy+y-yy,y,0,1-x),x,0,1)
%5
disp(‘int(int(-sqrt(3)P(x,y,z)/2-Q(x,y,z)/sqrt(3)+R(x,y,z),y,0,3-1.5x),x,0,2)’)
disp('int(int(-2
xP(x,y,z)-2yQ(x,y,z)+R(x,y,z),r,0,2sqrt(2)),s,0,2pi)’)
%6
A6=int(int(exp(2),r,1,2),s,0,2
pi)

----------------------------------------------week7----------------------
%1
P1=binocdf(45,100,0.5)
P2=binopdf(45,100,0.5)
x=0:100;
Px1=binocdf(x,100,0.5);
Px2=binopdf(x,100,0.5);
stairs(x,Px1);
figure
stairs(x,Px2);
%2

X=[1 2 4 2;2 4 3 3;3 3 4 4;4 5 5 5];
geom=geomean(X)
harm=harmmean(X)
meanX=mean(X)
medianm=median(X)
rangem=range(X)
varX=var(X)
vra1X=var(X,1)
stdX=std(X)
covX=cov(X)
moment1=moment(X,1)
moment2=moment(X,2)
moment3=moment(X,3)
moment4=moment(X,4)
R=corrcoef(X)

%3

x1=[1 2 3 4 5 6 7 8 9 10];
x2=[10 9 8 7 6 5 4 3 2 1];
X=x1’*x2;
geom=geomean(X)
harm=harmmean(X)
meanX=mean(X)
medianm=median(X)
rangem=range(X)
varX=var(X)
vra1X=var(X,1)
stdX=std(X)
covX=cov(X)
moment1=moment(X,1)
moment2=moment(X,2)
moment3=moment(X,3)
moment4=moment(X,4)
R=corrcoef(X)

%4.1

m=magic(5);
n1=nansum(m)
n2=nanmean(m)

%4.2

m([1 7 13 19 25])=[ NaN NaN NaN NaN NaN];
n1=nansum(m)
n2=nanmean(m)
n3=nanmin(m)
n4=nanmax(m)
n5=nanmedian(m)
n6=nanstd(m)

-------------------------------------week8------------------------------------
%1
x=[0.1 0.8 1.3 1.9 2.5 3.1];
y=[1.2 1.6 2.7 2.0 1.3 0.5];
p=interp1(x,y,2.0,‘cubic’)
p=interp1(x,y,2.0,‘linear’)
%2
x=[0 1 2 3 4 ];
y=[0 1 2 3 4];
z=[4 0 -4 0 4
3 2 -2 2 3
2 1 0 1 2
3 2 -2 2 3
4 0 -4 0 4];
subplot(1,2,1)
mesh(x,y,z)
x1=0:0.1:4;
y1=0:0.1:4;
[x2,y2]=meshgrid(x1,y1);
t1=interp2(x,y,z,x2,y2,‘cubic’);
subplot(1,2,2)
mesh(x1,y1,t1);
%3
[X,Y,Z,v] = flow(3)
x1=1:1:3
y1=1:1:3
z1=1:1:3
Q=interp3(X,Y,Z,v,x1,y1,z1)

-----------------------------------------------week9-------------------
%1
x=[0.1 0.8 1.3 1.9 2.5 3.1];
y=[1.2 1.6 2.7 2.0 1.3 0.5];
p=interp1(x,y,2.0,‘cubic’)
p=interp1(x,y,2.0,'linear
')
%2
x=[0 1 2 3 4 ];
y=[0 1 2 3 4];
z=[4 0 -4 0 4
3 2 -2 2 3
2 1 0 1 2
3 2 -2 2 3
4 0 -4 0 4];
subplot(1,2,1)
mesh(x,y,z)
x1=0:0.1:4;
y1=0:0.1:4;
[x2,y2]=meshgrid(x1,y1);
t1=interp2(x,y,z,x2,y2,‘cubic’);
subplot(1,2,2)
mesh(x1,y1,t1);
%3
[X,Y,Z,v] = flow(3)
x1=1:1:3
y1=1:1:3
z1=1:1:3
Q=interp3(X,Y,Z,v,x1,y1,z1)

------------------------------------------------week10-------------------------

function y=f1(x)
y=-x.*x/2
function y=f2(x)
y=exp(sin(x))
function y=f3(x)
y=1./(1+x.*x.x)
function y=f4(x)
y=1./(5+x)
function y=f5(x)
y=exp(-x.x/2)
%1 order:
I1=quad(@f1,0,1)/(sqrt(2
pi))
I2=quad(@f2,0,pi/2)
I3=quad(@f3,0,1.5)
I4=quad(@f4,-1,1)
I5=quad(@f5,0,2)/(sqrt(2
pi))

%2
i1=dblquad(inline(’(exp(-x.2-y.2))./(x+y)’,‘x’,‘y’),0,4,1,2)

i2=dblquad(inline(‘sin(x+y)./(x+y)’,‘x’,‘y’),0,5,1,3)

%3
triplequad(inline(‘x+exp(y)+sin(z)’,‘x’,‘y’,‘z’),-2,2,-2,2,0,4)

---------------------------------------------------week11----------------------
function y=f1(x)
y=exp(-x.*x/2)
function y=f2(x)
y=exp(sin(x))
function y=f3(x)
y=1./(1+x.*x.x)
function y=f4(x)
y=1./(5+x)
function y=f5(x)
y=exp(-x.x/2)
%1 order:
I1=quad(@f1,0,1)/(sqrt(2
pi))
I2=quad(@f2,0,pi/2)
I3=quad(@f3,0,1.5)
I4=quad(@f4,-1,1)
I5=quad(@f5,0,2)/(sqrt(2
pi))

%2
i1=dblquad(inline(’(exp(-x.2-y.2))./(x+y)’,‘x’,‘y’),0,4,1,2)

i2=dblquad(inline(‘sin(x+y)./(x+y)’,‘x’,‘y’),0,5,1,3)

%3
triplequad(inline(‘x+exp(y)+sin(z)’,‘x’,‘y’,‘z’),-2,2,-2,2,0,4)

-------------------------------week12----------------------------------------
%1
function ex
ODE45(@ff,[0,1],2)
function f=ff(x,y)
f=8-3y;
%2
function y=fu(x,y)
f=[y(2);2
x.y(2)/(1+x.x)]
function exx
ode15s(@fu,[0,10],[1,3])
%3
function y=fun(x,y)
y=[y(2);2
y(2)-y(1)]
function exx1
ode15s(@fun,[0,10],[1,3])
%4
function exxx
ODE45(@funn,[0,10],[1.5,0])
function f=funn(t,y)
f=[exp(t)+3
y(2)+2y(1);-3y(1)-y(2)]

---------------------------------------week13--------------------------
%1
function y=f1(x)
y=x-exp(-x);

fplot(@f1,[-1,1]);

fsolve(@f1,0)

%2
function y=f2(x)
y=5*x.xsin(x)-exp(-x)

fplot(@f2,[0,10]);

fsolve(@f2,0)
fsolve(@f2,3)
fsolve(@f2,6)
fsolve(@f2,9)

%3
function y=f3(x)
y(1)=x(1)-0.7sin(x(1))-0.2cos(x(2));
y(2)=x(2)-0.7cos(x(1))-0.2sin(x(2));

x0=[0.1,0.1]; %初值?

fsolve(@f3,x0)

%4
function y=f4(x)
y=x.^2*exp(-x.*x)-0.2;

fplot(@f4,[-3,3]);

fsolve(@f4,-1.5)
fsolve(@f4,-0.5)
fsolve(@f4,0.5)
fsolve(@f4,1.5)

---------------------------------------week14---------------------
f=-[3,2,-8,5];
A2=[-3,6,-5,2;7,-3,-1,3];
b1=[-3,-1];
A=[1,8,1,-1];
b=[-2];
LB=[0,-inf,0];
[X,fv]=linprog(f,A2,b1,A,b,LB)

clear
f=[-1,1,1,1,-1];
A=[0,0,1,0,6;1,-4,0,0,2;0,2,0,1,2];
b=[9,2,9];
LB=[0,0,0,0,0];
[X,fv]=linprog(f,[],[],A,b,LB)

clear
f=[100,100,100,100,100,100,100];
A=-[1,0,0,1,1,1,1;1,1,0,0,1,1,1;1,1,1,0,0,1,1;1,1,1,1,0,0,1;1,1,1,1,1,0,0;0,1,1,1,1,1,0;0,0,1,1,1,1,1];
b=-[16,15,16,19,14,12,18];
LB=[0,0,0,0,0,0,0];
[X,fv]=linprog(f,A,b,[],[],LB)

fun=’(x5+x3+x2-1)/(exp(x2)+sin(-x))’
ezplot(fun,[-5,5])
[X,fval,exitflag,output]=fminbnd(fun,-5,5)
%分析:此时仅计算了局部最优解
%解决方法:画出函数图像后将仅含一个极小值的区间作为x的取值区间

clear
fu=‘x^2+4*x+4’
ezplot(fu,[-10,10])
[X,fval,exitflag,output]=fminbnd(fu,-5,0)

clear
funn=’(x-2) 4*sin(x)-(x-1)2*cos(x)’
ezplot(funn,[-10,10])
[X,fval]=fminsearch(funn,-8)

--------------------------------week15-------------------------

f=-[3,2,-8,5];
A2=[-3,6,-5,2;7,-3,-1,3];
b1=[-3,-1];
A=[1,8,1,-1];
b=[-2];
LB=[0,-inf,0];
[X,fv]=linprog(f,A2,b1,A,b,LB)

clear
f=[-1,1,1,1,-1];
A=[0,0,1,0,6;1,-4,0,0,2;0,2,0,1,2];
b=[9,2,9];
LB=[0,0,0,0,0];
[X,fv]=linprog(f,[],[],A,b,LB)

clear
f=[100,100,100,100,100,100,100];
A=-[1,0,0,1,1,1,1;1,1,0,0,1,1,1;1,1,1,0,0,1,1;1,1,1,1,0,0,1;1,1,1,1,1,0,0;0,1,1,1,1,1,0;0,0,1,1,1,1,1];
b=-[16,15,16,19,14,12,18];
LB=[0,0,0,0,0,0,0];
[X,fv]=linprog(f,A,b,[],[],LB)

fun=’(x5+x3+x2-1)/(exp(x2)+sin(-x))’
ezplot(fun,[-5,5])
[X,fval,exitflag,output]=fminbnd(fun,-5,5)
%分析:此时仅计算了局部最优解
%解决方法:画出函数图像后将仅含一个极小值的区间作为x的取值区间

clear
fu=‘x^2+4*x+4’
ezplot(fu,[-10,10])
[X,fval,exitflag,output]=fminbnd(fu,-5,0)

clear
funn=’(x-2)4*sin(x)-(x-1)2*cos(x)’
ezplot(funn,[-10,10])
[X,fval]=fminsearch(funn,-8)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值