matlab p0 err k y,(数值计算方法)matlab的使用

一、实验内容

1>有一块矩形木板,宽度为5m,欲飘过直角拐弯的水渠,水渠尺寸见下图,问木板长度不能超过多长,才能飘过水渠?

0818b9ca8b590ca3270a3433284dd417.png

1>已知某抛物线经过点(1,4)、(2,7)、(3,14),求抛物线方程。

2>用Matlab符号运算验证以下等式:

0818b9ca8b590ca3270a3433284dd417.png

一、实验设备

操作系统:Windows平台

实验软件:matlab

二、实验步骤

0818b9ca8b590ca3270a3433284dd417.png

可得出f(θ)=(10-5*cosθ)/sinθ+(12-5*sinθ)/cosθ,求导得df(θ)=(5-10*cosθ)/((sinθ)^2)+(-5+12sinθ)/((cosθ)^2),当df(θ)=0时取得最大值,此时木板的长度为最大长度。用牛顿迭代法在matlab上求解。

newton.m文件如下:

function[p0,err,k,y]=newton(f,df,p0,delta,epsilon,max1)

%Input - f is the object functioninput as a string 'f'

%  - df is the derivative of f input as a string 'df'

%  - p0 is the initial approximation to a zero of f

%  - delta is the tolerance for p0

%  - epsilon is the tolerance for the function values y

%  - max1 is the maximum number of iterations

%Output - p0 is the Newtonapproximation to the zero

%            - err is the error estimate for p0

%            - k is the number of iterations

%            - y is the function value f(p0)

for k=1:max1

p1=p0-feval(f,p0)/feval(df,p0);

err=abs(p1-p0);       relerr=2*err/(abs(p1)+delta);

p0=p1;     y=feval(f,p0);

if(err

end

首先作出其导数图像,得到其df(θ)=0时大概在20度到60度

0818b9ca8b590ca3270a3433284dd417.png

然后用牛顿迭代法求出df(θ)=0时的数值解。Matlab代码如下:

ff=@(x)(10-5*cos(x))/sin(x)+(12-5*sin(x))/cos(x);

f=@(x)(cos(x)*(5*cos(x) - 10))/sin(x)^2 -(sin(x)*(5*sin(x) - 12))/cos(x)^2;

fd=@(x)- (5*cos(x) - 10)/sin(x) - (5*sin(x) - 12)/cos(x) -(5*cos(x))/sin(x) - (5*sin(x))/cos(x) - (2*cos(x)^2*(5*cos(x) - 10))/sin(x)^3 -(2*sin(x)^2*(5*sin(x) - 12))/cos(x)^3

a=deg2rad(10);b=deg2rad(80);

delta=0.000001;epsilon=0.000001;max=100000;

[c1,c2,c3,c4]=newton(f,fd,a,delta,epsilon,max);

feval(ff,c1)

rad2deg(c1)

求得c1=0.7320,c2=7.1711e-08,c3=7,c4= -5.1514e-14,将c1的结果带入ff求得长度为21.0372米,固木板长度不超过21.0372米即可飘过水渠。

1>设二次函数为y=ax^2+bx+c.把三个点代入,得到方程组,用matlab的矩阵运算,代码如下:

a=[1,1,1;4,2,1;9,3,1];

b=[4;7;14];

inv(a)*b

可得a,b,c分别为:

2.0000

-3.0000

5.0000

3>

symsa11 a12 a13 a21 a22 a23 a31 a32 a33

a=[a11,a12,a13;a21a22 a23;a31 a32 a33];

a2=[a11,a12,a13;0a22 a23;0 a32 a33];

I=[1,0,0;-a21/a11,1,0;-a31/a11,0,1];

I2=[1,0,0;0,1,0;0,-a32/a22,1];

I*a

I2*a2

得出结果:

ans =

[a11,a12,a13]

[0,a22-(a12*a21)/a11,a23-(a13*a21)/a11]

[0,a32-(a12*a31)/a11,a33-(a13*a31)/a11]

ans =

[a11,a12,a13]

[0,a22,a23]

[0,0,a33-(a23*a32)/a22]

与结果符合。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值