《MATLAB程序设计教程》第7章 MATLAB解方程与函数极值

合集下载

MATLAB第七章

MATLAB第七章

第七章MATLAB解方程与函数极值班级:工自03-1班姓名:陈录平学号:030544103 7-1(1)A=[2,3,5;3,7,4;1,-7,1];b=[10,3,5];c=inv(A);[L,U]=lu(A);x=c*b'y=A\b'z=U\(L\b')x =-1.8060-0.53733.0448y =-1.8060-0.53733.0448z =-1.8060-0.53733.0448(2)A=[6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2];b=[-4,13,1,11];c=inv(A);[L,U]=lu(A);x=c*b'y=A\b'z=U\(L\b')x = 0.6667-1.00001.5000-0.0000y =0.6667-1.00001.5000-0.0000z = 0.6667-1.00001.5000-0.00007-2(1)A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6];b=[0.95,0.67,0.52];x=A\b'x = 1.20000.60000.6000(2)A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6];b=[0.95,0.67,0.53];x=A\b'x = 3.0000-6.60006.6000(3)A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6];c=cond(A)c =1.3533e+003矩阵条件数很大,因此个别元素的微小扰动会引起解向量的很大变化。

7-3(1)建立函数文件function fx=fun(x)fx=x^41+x^3+1;调用函数求根z=fzero('funx',-1)z =-0.9525(2)建立函数文件function fx=fun(x)fx=x-sin(x)./x;调用函数求根z=fzero('funx',0.5)z =0.8767(3)建立函数文件function fx=fun(x)fx=3*x+sin(x)-exp(x);调用函数求根z=fzero('funx',1.5)z =1.8900(4)建立函数文件function fx=fun(x)fx=x-1./x+5;调用函数求根z=fzero('funx',1)z =0.19267-4(1)建立函数文件function q=myfun(p)x=p(1);y=p(2);q(1)=x^2+y^2-9;q(2)=x+y-1;调用函数x=fsolve('myfun',([3,0]),optimset('display','off'))x =2.5616 -1.5616(2)建立函数文件function q=myfun(p)x=p(1);y=p(2);z=p(3);q(1)=sin(x)+y^2+log(z)-7;q(2)=3*x+2*y-z^2+1;q(3)=x+y+z-5;调用函数x=fsolve('myfun',([1,1,1]),optimset('display','off')) x =0.0715 2.4541 2.47447-5建立函数function xdot=lorenz(t,x)xdot=[-0.5,1;-1,-0.5]*x;调用函数x0=[0;1]';[t,x]=ode23('lorenz',[0,4*pi],x0);plot(x(:,1),x(:,2));axis([10,10,10,10]);t = 00.00010.00050.00250.01250.06250.27400.54190.81441.08541.35031.61421.88112.15082.42382.69382.95813.2224 3.48973.75994.03344.30234.56614.83095.09855.36915.64315.91116.17436.43956.70766.97857.25317.52037.78298.04858.31708.58848.86249.12899.39169.65769.926410.198210.470910.736710.999911.266311.535511.807812.079312.344512.5664x = 0 1.00000.0001 1.00000.0005 0.99980.0025 0.99880.0124 0.99370.0605 0.9674 0.2358 0.8395 0.3930 0.6536 0.4836 0.4572 0.5137 0.2719 0.4966 0.1122 0.4458 -0.01850.3721 -0.1183 0.2859 -0.1862 0.1965 -0.2236 0.1135 -0.2341 0.0425 -0.2239 -0.0153 -0.1991 -0.0588 -0.1645 -0.0879 -0.1248 -0.1032 -0.0842 -0.1065 -0.0470 -0.1008 -0.0155 -0.0888 0.0100 -0.0726 0.0289 -0.0544 0.0413 -0.0359 0.0475 -0.0193 0.0484 -0.0053 0.0453 0.0059 0.0396 0.0141 0.0320 0.0193 0.0236 0.0218 0.01530.0219 0.0079 0.0204 0.0017 0.0176 -0.0033 0.0141 -0.0068 0.0102 -0.0090 0.0065 -0.0100 0.0032 -0.0099 0.0004 -0.0091 -0.0017 -0.0078 -0.0033 -0.0062 -0.0042 -0.0044 -0.0046 -0.0027 -0.0045 -0.0013 -0.0041 -0.0000 -0.0035 0.0009 -0.0027 0.0016 -0.0019 0.0020 -0.0012 0.0021 -0.0005 0.0020 -0.0000 0.0019-0.2-0.100.10.20.30.40.50.6-0.4-0.20.20.40.60.817-6建立函数文件 function yp=funt(t,y) yp=-(1.2+sin(10*t)*y);调用函数t0=0;tf=5;y0=1;[t,y]=ode23('funt',[0,5],y0)t = 00.06670.13960.20200.27000.34780.42570.49090.55440.63300.68580.73860.78730.84770.90260.95631.01671.10091.16261.22431.28791.38011.45381.51701.58541.67331.73881.80431.8666 1.93762.00652.07552.13862.20832.30232.36752.43272.49542.56812.63232.69652.75972.82922.92252.98823.05393.11663.18773.25763.32753.39083.46153.56003.62493.68983.75283.82713.89123.95544.01884.08984.19014.25484.31954.38264.45784.52194.58594.64944.72124.82594.89004.95425.0000y = 1.00000.89990.76170.64420.53470.43900.36550.30860.24770.15910.09380.0282 -0.0301 -0.0990 -0.1606 -0.2239 -0.3032 -0.4321 -0.5339 -0.6286 -0.7049 -0.7690-0.8009-0.8385-0.9096-1.0621-1.2121-1.3657-1.4818-1.5485-1.5508-1.5294-1.5298-1.5868-1.7822-1.9781-2.1766-2.3171-2.3730-2.3363-2.2683-2.2273-2.2617-2.4739-2.7132-2.9630-3.1384-3.1999-3.1264-3.0009-2.9254-2.9514-3.2241-3.5123-3.8003 -3.9883 -4.0188 -3.9011 -3.7374 -3.6246-3.6363-3.9520-4.2870-4.6180-4.8267-4.8387-4.6777-4.4668-4.3206-4.3262-4.7137-5.0980-5.4626-5.6371(2)建立函数文件function yp=funt(t,y)yp=cos(t)-(1/(1+t.*t)).*y; 调用函数t0=0;tf=5;y0=1;[t,y]=ode23('funt',[t0,tf],y0)t = 00.50000.80161.10331.40771.75372.23012.52152.81292.97273.13263.30013.50913.75494.03754.36374.75845.0000y = 1.00001.01461.03631.04501.01620.91570.64510.41220.1437-0.0122-0.1699-0.3330-0.5273-0.7327-0.9233-1.0649-1.1040-1.0534(3)建立函数文件function xdot=vdpol(t,x)ydot(1)=(-3*y(2)-2.*T.*y(2))./(1+t^2) ydot(2)=y(1);ydot=ydot';调用函数to=0;tf=5;y0=[0;1];[t,y]=ode45('vdpol',[0,5],y0)t = 00.00000.00000.00010.00010.00020.00020.00030.00040.0008 0.00120.00170.00210.00420.00630.00840.01040.02090.03140.04180.05230.10460.15700.20930.26160.36170.46180.56200.66210.77330.88460.99591.1072 1.2148 1.3223 1.4299 1.5375 1.6625 1.78751.91252.0375 2.1625 2.28752.41252.53752.66252.78752.91253.03753.16253.28753.41253.53753.66253.78753.91254.03754.16254.28754.41254.53754.65314.76874.88445.0000y = 0 1.0000 -0.0001 1.0000-0.0001 1.0000-0.0002 1.0000-0.0002 1.0000-0.0005 1.0000-0.0007 1.0000-0.0010 1.0000-0.0012 1.0000-0.0025 1.0000-0.0037 1.0000-0.0050 1.0000-0.0062 1.0000-0.0125 1.0000-0.0188 0.9999-0.0251 0.9999-0.0315 0.9998-0.0632 0.9993-0.0951 0.9985-0.1271 0.9974-0.1593 0.9959-0.3219 0.9833 -0.4852 0.9622-0.6467 0.9325-0.8040 0.8945-1.0848 0.7997-1.3274 0.6787-1.5216 0.5357-1.6622 0.3758-1.7541 0.1850-1.7812 -0.0123-1.7495 -0.2092-1.6673 -0.3997-1.5487 -0.5730-1.3996 -0.7319-1.2278 -0.8734-1.0402 -0.9954-0.8104 -1.1112-0.5758 -1.1979-0.3430 -1.2552-0.1175 -1.28390.0966 -1.28510.2962 -1.26040.4789 -1.21170.6433 -1.14140.7884 -1.05170.9138 -0.94511.0195 -0.82411.1057 -0.69101.1730 -0.54841.2222 -0.39851.2541 -0.24361.2699 -0.08571.2705 0.07331.2571 0.23141.2310 0.38701.1933 0.53861.1452 0.68491.0879 0.82461.0225 0.95650.9501 1.07990.8779 1.18560.8014 1.28270.7215 1.37080.6388 1.4495(4)建立函数function ydot=vdpol(t,y)ydot(1)=cos(t)+5*(cos(2*t)./(t+1)^2).*y(1)-y(2)-(1/(3+sin(t))).*y(3); ydot(2)=y(1);ydot(3)=y(2);ydot=ydot';ydot'=ydot'';调用函数t0=0;tf=5;y0=[1;0;2];[t,y]=ode45('vdpol',[0,5],y0)t = 00.00010.00010.00020.00020.00050.00070.00100.00120.00250.00370.00500.00620.01250.01880.02510.03130.06270.09410.12550.15690.2195 0.28200.34450.40700.53200.65700.78200.90701.02111.13521.24931.36341.48841.61341.73841.86341.98842.11342.23842.36342.48842.61342.73842.86342.98843.11343.23843.36343.48843.61343.73843.86343.98844.11344.23844.36344.48844.61344.73844.86344.89764.93174.96595.0000y = 1.0000 0 2.00001.0003 0.00012.00001.0005 0.00012.00001.0008 0.00022.00001.0011 0.00022.00001.0024 0.00052.00001.0038 0.00072.00001.0051 0.00102.00001.0064 0.00122.00001.0132 0.00252.00001.0199 0.00382.00001.0267 0.00502.00001.0335 0.00632.00001.0680 0.01292.00011.1030 0.01972.00021.1386 0.02682.00031.1749 0.03402.00051.3647 0.07392.00221.5677 0.11992.00521.7822 0.17242.00982.0058 0.2319 2.01612.4683 0.3717 2.03482.9334 0.5405 2.06323.3764 0.7379 2.10303.7737 0.9617 2.15604.3485 1.4740 2.3068 4.5636 2.0346 2.5252 4.4084 2.5980 2.8155 3.9436 3.1228 3.1744 3.3407 3.5396 3.5553 2.6429 3.8818 3.9796 1.9092 4.1418 4.4381 1.1789 4.3176 4.9215 0.4072 4.41635.4684 -0.3277 4.42106.0218 -1.0291 4.3359 6.5699 -1.7076 4.16477.1020 -2.3780 3.9094 7.6075 -3.0529 3.57008.0759 -3.7425 3.1454 8.4965 -4.4523 2.6335 8.8586 -5.1832 2.03169.1511-5.9286 1.3372 9.3626 -6.6747 0.5493 9.4815 -7.3993 -0.3307 9.4961 -8.0730 -1.2984 9.3953 -8.6589 -2.3452 9.1683 -9.1181 -3.4578 8.8061 -9.4112 -4.6179 8.3018 -9.5015 -5.8024 7.6508 -9.3604 -6.9837 6.8516 -8.9696 -8.1318 5.9062 -8.3235 -9.2154 4.8210 -7.4281 -10.2026 3.6063 -6.3005 -11.0630 2.2758 -4.9650 -11.7689 0.8471 -3.4512 -12.2965 -0.6591 -1.7921 -12.6257 -2.2190 -0.0200 -12.7401 -3.8067 1.8334 -12.6274 -5.39453.7383 -12.2793 -6.95364.2637 -12.1428 -7.37054.7902 -11.9882 -7.78255.3174 -11.8157 -8.1888 5.8445 -11.6252 -8.58907-7(1)建立函数文件function fx=mymin(x)fx=-(1+x.*x)./(1+x.*x.*x.*x);调用函数x=fmin('mymin',0,2)x =0.6436(2)建立函数文件function fx=mymin(x)fx=-(sin(x)+cos(x.*x));调用函数x=fmin('mymin',0,pi)x =0.7310。

第7章MATLAB解方程与函数极值

第7章MATLAB解方程与函数极值
7 MATLAB
7 MATLAB 7.1 7.2 7.3
7.
4 7.1 7.1.1 1
Ax=b
“\” x=A\b 7-1
A=[2,1,-5,
1;1,-5,0,7;0,2,1,-1;1,6,-1,-4];b=[13,-9,6,0]'';x=A\b2
LU QR Choles
ky Schur Hessenberg (1)LU LU
tol
tol=eps trace​
10
trace=0 7-8 f(x)=x-10x+2=0 x0=0.5
(1)
funx.m functionfx=funx(x)fx=x-10.^x+2;(2)
fzero z=fzero(''funx'',0.5)z=0.37587.2.2
F(X)=0 fsolve fsolve X=f
R R''R=X X
[R,p]=chol(X)
X
p=0 R
p X R q=p-1
R''R=X(1:q,1:q) Cholesky Ax=b R‘Rx=b x=R\(R’\b) 7-
4 Cholesky 7-1
A=[2,1,-5,1;1,-5,0,7;0,2,1,-1;
1,6,-1,-4];b=[13,-9,6,0]'';R=chol(A)???Errorusing==>cholMa
=epsx0=y;y=Gx0+f;n=n+1;end 7-6 Gauss-Serdel
0 10-6
gauseidel.m A=[10,-
1,0;-1,10,-2;0,-2,10];b=[9,7,6]'';[x,n]=gauseidel(A,b,[0பைடு நூலகம்0,0]'',1

用MATLAB软件求极值和最值

用MATLAB软件求极值和最值

运行结果: x_max =
2.8498
f2_min = -1.7452
flag = 1
f_max = 1.7452
输入命令: fplot(f1,[-5 5]) 可得函数的曲线如下:
小结
1. 解非线性方程(组)的命令, 调用格式是:
solve('eqn1','eqn2’ , ,... , 'பைடு நூலகம்qnN’ )
2. 求函数的极值的方法: 求驻点
3. 求函数在给定区间上的最小值, 命令调用格式:
x= fminbnd (y,x1,x2)
先来求函数的最小值. 输入以下命令: f1='(x^3+x^2-1)/(exp(x)+exp(-x))'; [x_min,f_min,flag]=fminbnd(f1,-5,5)
运行结果: x_min =
- 3.3112
f_min = - 0.9594
flag = 1
再来求函数的最大值. 输入以下命令: f2='-(x^3+x^2-1)/(exp(x)+exp(-x))'; [x_max,f2_min,flag]=fminbnd(f2,-5,5) f_max=-f2_min
为极值点.
解 输入下列命令: y='x^3+2*x^2-5*x+1'; dy=diff(y) x=solve(dy) x=double(x) y1=x.^3+2*x.^2-5*x+1
运行结果: dy = 3*x^2+4*x-5
作函数曲线: fplot(y, [-4,2])
x= [ -2/3+1/3*19^(1/2)] [ -2/3-1/3*19^(1/2)]

Matlab优化(求极值)

Matlab优化(求极值)

第七讲 Matlab 优化(求极值)理论介绍:算法介绍、软件求解.一.线性规划问题1.线性规划问题是在一组线性约束条件的限制下,求一线性目标函数最大或最小值的问题,Matlab 中规定线性规划的标准形式为min s.t.T xc x Ax b Aeq x beqlb x ub ≤⎧⎪⋅=⎨⎪≤≤⎩其中c 和x 为n 维列向量,A 、Aeq 为适当维数的矩阵,b 、beq 为适当维数的列向量。

注意:线性规划问题化为Matlab 规定中的标准形式。

求解线性规划问题的Matlab 函数形式为linprog(c,A,b),它返回向量x 的值,它的具体调用形式为:[x,fval]=linprog(c,A,b,Aeq,beq,LB,UB,x0,OPTIONS)这里fval 返回目标函数的值,LB 、UB 分别是变量x 的下界和上界,x0是x 的初始值,OPTIONS 是控制参数。

例1 求解线性规划问题123123123123123max 23572510s.t.312,,0z x x x x x x x x x x x x x x x =+-++=⎧⎪-+≥⎪⎨++≤⎪⎪≥⎩ 程序:c=[2;3;5];>> A=[-2,5,-1;1,3,1];b=[-10;12];>> Aeq=[1,1,1];beq=[7];>> LB=[0;0;0];(zeros(3,1))>> [x,fval]=linprog(c,A,b,Aeq,beq,LB,[])练习与思考:求解线性规划问题12312312123min 23+428s.t.3+26,,0z x x x x x x x x x x x =+++≥⎧⎪≥⎨⎪≥⎩ 注意:若没有不等式:b AX ≤存在,则令A=[ ],b=[ ]. 若没有等式约束, 则令Aeq=[ ], beq=[ ].2.可以转化为线性规划的问题规划问题12min||+||++||s.t.,n x x x Ax b ≤ 其中1=[],T n x x x ,A b 为相应维数的矩阵和向量。

MATLAB求函数零点与极值

MATLAB求函数零点与极值

MATLAB求函数零点与极值
1. roots函数
针对多项式求零点(详见MATLAB多项式及多项式拟合)
2. fzero函数
返回⼀元函数在某个区间内的的零点.
x0 = fzero(@(x)x.^2-3*x-4,[1,5]);
只能求区间⾥⾯的⼀个零点,并且要求在给定区间端点函数值异号,所以使⽤之前应该先作图,得出单个零点分布的区间,然后使⽤该函数求零点.若有多个零点,则需多次使⽤该函数.
如需求上例中的全部零点,先作图
fplot(@(x)x.^2-3*x-4,[-10,10]);
得知两个零点的分布区间,然后两次使⽤fzero函数求对应区间的零点.
x1 = fzero(@(x)x.^2-3*x-4,[-2,0]);
x2 = fzero(@(x)x.^2-3*x-4,[2,6]);
3. solve函数
求⼀元函数(⽅程)的零点.
x0 = solve('x^2-3*x-4=0','x');
注意⽅程需包含’=0’部分,另外,不建议直接将⽅程写在函数solve的参数部分,可以⽤符号运算的⽅法.
4. fminbnd函数
求⼀元函数在某个区间内的最⼩值和对应的最⼩值点.
[x0,fmin]=fminbnd(@(x)x+1/(x+1),-0.5,2);
求极值与极值点之前须估计极值点的区间,保证在该区间没有使得函数值趋于⽆穷的点.。

matlab求解非线性方程组及极值

matlab求解非线性方程组及极值

matlab求解非线性方程组及极值默认分类2010-05-18 15:46:13 阅读1012 评论2 字号:大中小订阅一、概述:求函数零点和极值点:Matlab中三种表示函数的方法: 1. 定义一个m函数文件, 2.使用函数句柄; 3.定义inline函数, 其中第一个要掌握简单函数编写, 二, 三中掌握一个。

函数的'常规'使用有了函数了, 我们怎么用呢, 一种是直接利用函数来计算, 例如: sin(pi), 还有我们提到的mysqr(3)...另一种是函数画图, 例如Plottools中提到的ezplot, ezsurf... 但是这也太小儿科了, 有没有想过定义函数后, 利用它来: 求解零点(即解f(x)=0方程), 最优化(求最值/极值点), 求定积分, 常微分方程求解等. 当然这里由于篇幅有限(空间快满了)以及这个只是'基础教程'的缘故, 只提及一些皮毛知识, 掌握这些后, 如果需要你可以进一步学习.解f(x)=0已知函数求解函数值=0所表示的方程, Matlab中有两个函数可以做到, fzero和fsolve前者只能解一元方程, 后者可以解多元方程组, 不过基本使用形式上差不多:解=fzero(函数, 初值, options)解=fsolve(函数, 初值, options)关于解: fzero给出的是x单值的解, fsolve给出的是解x可能处于的区间, 当然, 这个区间很窄.关于'函数', 还记得前面提到的三种表示方法吧, 在这里都可以用, 记住就是: 如果直接使用函数名, 要用单引号将它括起来, 而函数句柄, inline函数可以直接使用.关于'初值': 电脑比较笨, 它寻找解的办法是尝试不同地x值, 摸索解在哪里, 所以我们一开始就要给它指明从哪里开始下手, 初值这里, 可以只给它一个值, 让它在这个值附近找解, 也可以给它一个区间(区间用[下限,上限]这种方式表示), 它会在这个区间内找解.fzero的一些局限, 如果你给定的初值是区间, 而恰好函数在区间端点处同号, fzero会出错, 而如果你只给一个初值, fezro又有可能'走错方向', 例如给初值2让它解mysqr这个函数方程就出错了, FT!寻找函数极值/最值Matlab中也有两个函数可以做到, 是: fminbnd: 寻找一元函数极小值; fminsearch: 寻找多元函数极小值(当然一元也行). 别问我怎么没有找极大值的Matlab函数, 你把原函数取负数, 寻找它的极小值不就行了. 相关语法:x=fminbnd(函数, 区间起始值, 区间终止值)x=fminsearch(函数, 自变量初值)相关说明: fminbnd中指定要查找极小值的自变量区间, 好像不指定也行, 不过那样的话, 如果函数有多个极小值就可能比较难以预料结果了.fminsearch中要给定一个初值, 这个初值可以是自变量向量(将自变量依次排在一起组成向量)的初值, 也可以是表示向量初值区间的一个矩阵.函数: 那三种形式都适用, 但是记住, 直接使用函数名称需要加单引号!cite from:/qq529312840/blog/item/3687e4c7e7e2d6d9d0006049.html二、实例+讲解(1)非线性方程数值求解:1 单变量非线性方程求解在MATLAB中提供了一个fzero函数,可以用来求单变量非线性方程的根。

Matlab求解方程和函数极值.docx

Matlab求解方程和函数极值.docx

Mat lab求解方程和函数极值The fifth chapter, 22010-03-31 22:50Two. Matlab for solving equations and function extremumI. solving linear equations1. direct solutionThe direct solution to the use of the left division operatorFor linear equations Ax=b, we can use the left division operator to solve: X=A\bFor example, the following linear equations are solved by direct solution. The commands are as follows:A=[2, 1, -5, 1; 1; -5,0,7; 0,2, 1; -1; 1,6; -1; —4];B=[13, -9,6,0],;X=A\bSolving linear equations by the decomposition of matrixMatrix decomposition is the product of decomposing a matrix into several matrices according to certain principles・ Common matrix decomposition includes LU decomposition, QR decomposition, Cholesky decomposition, and Schur decomposition, Hessenberg decomposition, singular decomposition,and so on.(1)LU decompositionThe LU decomposition of a matrix means that a matrix is expressed as a product of a commutative lower triangular matrix and an upper triangular matrix・Linear algebra has proved that LU decomposition is always possible as long as the square A is nonsingular・\IATLAB provides the Lu function for LU decomposition of the matrix, the call format for:[L, U]二lu (X): produces an upper triangular array U and a transform form of lower triangular array L (row exchange) to satisfy X二LU. Note that the matrix X here must be square・[L, U, P]二lu (X): produces an upper triangular array U and a lower triangular matrix L, and a permutation matrix P, which satisfies PX=LU ・ Of course, the matrix X must also be square・After the LU decomposition, the solution of the linear equations Ax二b (L\b) or x二U\ (L\Pb), which can greatly improve the speed of operation x二U\・For example, LU is used to solve the linear equations in example 7-1. The commands are as follows:A二[2,1, -5, 1; 1; -5,0,7; 0,2, 1; T; 1,6; -1; -4];B二[13, -9, 6,0]';[L, U]二lu (A);X二U\ (L\b)Or using LU decomposition of the second formats, as follows:[L, U, P]二lu (A);X二U\ (L\P*b)(2)QR decompositionQR decomposition of the matrix X, is the decomposition of X into an orthogonal matrix Q and an upper triangular matrix R product form. QR decomposition can only be carried out by the opponent,s array. MATLAB function QR can be used for QR decomposition of the matrix, the call format for:[Q, R]=qr (X): produces an orthogonal matrix Q and an upper triangular matrix R so that it satisfies X二QR・[Q, R, E]=qr (X): produce an orthogonal matrix Q, an upper triangular matrix, R, and a permutation matrix E, so that it satisfies XE二QR.After the QR decomposition, the solution of the linear equation Ax二b is x二R\ (Q\b) or x二E (R\ (Q\b))・For example, QR is used to solve the linear equations in example 7-1.The commands are as follows:A二[2,1, -5, 1; 1; -5,0,7; 0,2, 1; T; 1,6; -1; -4];B二[13, -9, 6,0]';[Q, R]二qr (A);X二R\ (Q\b)Or using QR decomposition of the second formats, as follows:[Q, R, E] =qr (A):X二E* (R\ (Q\b))(3)Cholesky decompositionIf the matrix X is symmetric and positive definite, the Cholesky decomposition decomposes the matrix X into the product of a lower triangular matrix and upper triangular matrix・ Set the triangle matrix to R,Then the lower triangular matrix is transposed, that is, X二R' R・ The MATLAB function Choi (X) is used for Cholesky decompositionof the matrix X, and its call format is:R二chol (X): produces an upper triangular array R that makes R'R二X ・If the X is an asymmetric positive definite, an error message is output ・[R, p]二chol (X): this command format will not output error messages・ When X is symmetric positive definite, then p二0 and R are the same as those obtained in the above format: otherwise, P is a positive integer ・If X is a full rank matrix, then R is an upper triangular matrix of order q=p-l and satisfies R'R二X (l:q, l:q)・After the Cholesky decomposition, the linear equation group Ax二b becomes R 'Rx二b, so x二R\ (R, \b ')・Example 4 decomposes the system of linear equations in example 7-1 by Cholesky decomposition.The commands are as follows:A二[2,1, -5, 1; 1; -5, 0,7; 0,2, 1; T; 1,6; -1; -4];B 二[13, —9,6,0]';R二chol (A)Error using Chol =>???Matrix, must, be, positive, definiteWhen the command is executed, an error message appears indicating that the A is a non positive definite matrix・2. iteration methodIterative method is very suitable for solving large coefficient matrix equations・ In numerical analysis, the iterative methods mainly include Jacobi iterative method, Gauss-Serdel iterative method, over relaxationiterative method and two step iterative method・Jacobi iteration methodFor linear equations Ax二b, if A is a nonsingular square, that is, (i=l, 2,・・・(n), A can be decomposed into A 二D-L-U, where D is a diagonal matrix, and its elements are diagonal elements of A, L and U are lower triangular and upper triangular matrices of A, so Ax二b becomes・・:The corresponding iteration formula is:This is the Jacobi iteration formula・If the sequence converges to x, then x must be the solution of equation Ax二b・The MATLAB function file of the Jacobi iteration method Jacobi.m is as follows:Function, [y, n]二jacobi (A, B, xO, EPS)If nargin=3Eps=1.Oe-6;Elseif nargin〈3ErrorReturnEndD=diag (diag (A)) -% A diagonal matrixL=-tril (A, -1); the lower triangular array of% AU二-triu (A, 1); the upper triangular array of% AB二D\ (L+U);F二D\b;Y二B*xO+f:N二1;% iterationsWhile norm (y-xO) 〉=epsXO二y;Y二B*xO+f:N二n+1;EndExample 5 uses the Jacobi iterative method to solve the following linear equations・The initial value of iteration is 0, and the iteration accuracy is 10-6・Call the function file "Jacobi.nT in the command. The command is as follows:A二[10, -1,0; -1, 10; -2; 0; -2, 10];B二[9, 7,6]';[x, n]二jacobi (A, B, [0,0,0]', 1. Oe-6)Gauss-Serdel iteration methodIn the Jacobi iteration process, the calculations have been obtained and need not be reused, i.e., the original iterative formula Dx (k+1)二(L+U) x (k) +b can be improved to Dx (k+1) 二Lx (k+1) +Ux (k) +b and thus obtained:X (k+1)二(D-L) -lUx (k) + (D-L) TbThis formula is the Gauss-Serdel iterative formula・ Compared with the Jacobi iteration,The Gauss-Serdel iteration replaces the old components with new ones, with higher accuracy・The MATLAB function f订e of the Gauss-Serdel iteration method gauseidel.m is as follows:Function, [y, n]=gauseidel (A, B, xO, EPS)If nargin=3Eps二1. 0e-6;Elseif nargin<3ErrorReturnEndD=diag (diag (A)) -% A diagonal matrixL=-tril (A, -1); the lower triangular array of% AU=-triu (A, 1); the upper triangular array of% AG二(D-L) \U;F二(D-L) \b;Y二G*xO+f;N=l;% iterationsWhile norm (y-xO) >=epsXO二y;Y二G*xO+f:N二n+1;EndExample 6 uses the Gauss-Serdel iterative method to solve the followinglinear equations・The initial value of iteration is 0, and the iteration accuracy is 10-6・Call the function file z,gauseidel.m" in the command. The command is as follows:A二[10, -1,0; -1, 10; -2; 0; -2, 10];B二[9, 7,6]';[x, n]二gauseidel (A, B, [0,0,0]', 1.0e~6)Example 7, Jacobi iteration and Gauss-Serdel iteration method are used to solve the following linear equations, to see whether convergence・The commands are as follows:A二[1,2, -2; 1, 1, 1; 2, 2,11;B二[9; 7; 6];[x, n]=jacobi (a, B, [0; 0; 0])[x, n]=gauseidel (a, B, [0; 0; 0])Two. Numerical solution of nonlinear equations1 solving the single variable nonlinear equationIn MATLAB, a fzero function is provided that can be used to find the roots of a single variable nonlinear equation. The call format of this functionis: z二fzero ('fname', xO, tol, trace)Where fname is the root to be a function of the file name, xO as the search starting point・ A function may have more than one root, but the fzero function only gives the root nearest to the x0・ The relative accuracy of the TOL control results, by default, take tol二eps, trace, specify whether the iteration information is displayed in the operation, and when 1 is displayed, 0 is not displayed, and the trace=0 is taken by default・Example 8 ask for roots in the neighborhood.Steps are as follows:(1) establishment of function file funx・m.Function fx二funx (x)Fx二xTO. x+2;(2) fzero function call root.Z=fzero (' funx', 0. 5)二ZZero point three seven five eight2. solving nonlinear equationsFor nonlinear equations F (X) =0, the numerical solution is obtained by using the fsolve function. The call format of the fsolve function is:X二fsolve (' fun,, X0, option)Where X is the return of the solution, fun is used to define the demand for solutions of nonlinear equations function of the file name, X0 is the initial rooting process, option optimization toolbox options・ The Optimization Toolbox provides more than 20 options that users can display using the optimset command・If you want to change one of the options, you can call the optimset () function to complete it. For example, Display display option decision function calls intermediate results, in eluding 〃off〃does not show, 〃ITER〃said each show,'final5 shows only the final results・ Optimset ('Display', 'off') will set the Display option to 'off'.Example 9 find the numerical solution of the following nonlinear equations in (0.5,0.5) neighborhood・(1)establishment of function file myfun. m.Function q=myfun (P)X二p (1);Y二p (2);Q (1) =x-0・6*sin (x) -0.3*cos (Y);Q (2)二y-0・6*cos (x) +0. 3*sin (Y);(2)under the given initial value x0=0・5 and y0=0・5, call the fsolve function to find the root of the equation.X二fsolve C myfun,, [0.5,0. 5]', optimset ('Display'off'))二xZero point six three five fourZero point three seven three fourThe solution is returned to the original equation, and it can be checked whether the result is correct or not:Q二myfun (x)1.0e-009 *0. 2375, 0. 2957We can see the result of higher precision.Three・ Numerical solution of initial value problems for ordinary differential equations1. introduction of Runge Kutta method2., the realization of Runge Kutta methodBased on Runge Kutta method, MATLAB provides the function of finding numerical solutions of ordinary differential equations:[t, y]二ode23 C fname,, tspan, Y0)[t, y]二ode45 C fname,, tspan, Y0)Where fname is the function file name that defines f (T, y), and the function file must return a column vector・ The tspan form is [tO, tf], which represents the solution interva. 1. Y0 is the initial state column vector ・ The time vectors and corresponding state vectors are given by T and Y respectively.Example 10 has an initial value problem,Try to find the numerical solution and compare it with the exact solution (the exact solution is y (T)二).(1)establishment of function file funt. m.Function yp二funt (T, y)Yp= (y"2-t-2) /4/ (t+1);(2)solving differential equations・TOO; tf二10;¥0=2;[t, y]=ode23 ('funt', [tO, tf], Y0) ;% for numerical solutionYl=sqrt (t+1) +1;% refinement; exact solutionPlot (T, y, 'B・',t, Yl, ?)% are compared by graphThe numerical solution is represented by a blue dot, and the exact solution is expressed in red solid lines・ As shown. It can be seen that the two results approximate・ CloseFour. Function extremumMATLAB provides functions based on the simplex algorithm for solving extremal functions Fmin and fmins, which are used respectively for minimum values of univariate functions and multivariate functions:X二fmin (' fname,, xl, x2)X二fmins (' fname' , xO)The call formats of the two functions are similar・ Among them, the Fmin function is used to find the minimum point of a single variable function. Fname is the object function name that is minimized, and XI and X2 limit the range of arguments・ The fmins function is used to find the minimum point of a multivariable function, and xO is the initial value vector of the solution.MATLAB provides no special function to find the maximum function, but as long as the attention to -f (x) in the interval (a, b) is the minimum value of F (x) in (a, b) of the maximum value, so Fmin (F, xl, x2) f (x) function in the interval (xl the maximum value, X2)・Example 13 asks in [0,Minimum point in 5]・(1)establishment of function file mymin. m.Function fx二mymin (x)Fx=x.八3-2*x-5;(2)call the Fmin function to find the minimum point・Zero point eight one six fiveThree・Matlab numerical integration and differentiationI. numerical integration1.basic principles of numerical integrationNumerical methods for solving definite integration are various, such as simple trapezoidal method, Xin Pusheng (Simpson) method, Newton Cortes (Newton-Cotes) method, etc・,are often used・Their basic idea is to divide the whole integral interval [a and b] into n sub intervals [[, ], i=l, 2],・・・ N, in which,・ In this way, the problem of determining integral is decomposed into summation problem・2.realization method of numerical integrationVariable step symplectic methodBased on the variable step long Xin Pusheng method, MATLAB gives the quad function to find the definite integra 1. The call format of this function is:[I, n]二quad ('fname', a, B, tol, trace)Where fname is the product function name・A and B are the lower bound and upper bound of the definite integra 1. TOL is used to control the integration accuracy, and the tol=0.001 is taken by default・ Does the trace control show the integration process? If you take the non 0, it will show the integral process, take 0 instead of the default, and take the trace=0 bydefault・ Returns the parameter I, the fixed integral value, and the call number of n for the integrand・Finding definite integral(1)establish the integrand function file fesin.m.Function f二fesin (x)F二exp (一0.5*x)・ *sin (x+pi/6);(2)call the numerical integral function quad to find the definite integra1.[S, n]二quad ('fesin', 0, 3*pi)二SZero point nine Zero Zero eight二nSeventy-sevenThe Newton Cotes methodNewton Cotes method based on MATLAB, gives the quad8 function to find the definite integra 1. The call format of this functionis: [I, n]=quad8 C fname,, a, B, tol, trace)The meaning of the parameter is similar to that of the quad function, but only the default value of the tol. The function can more accurately calculate the value of the definite integral, and in general, the number of steps of the function call is less than the quad function, thus ensuring the higher efficiency to find the required integral value・Finding definite integral(1)the integrand function file fx. m・Function f二fx (x)F二x. *sin (x) / (1+cos (x)・*cos (x));(2)call the function quad8 to find the definite integral.I二quad8 (' fx' , 0, PI)二ITwo point four six seven fourExample 3 uses the quad function and the quad8 function respectively to find the approximate value of the integral, and compares the number of calls of the function under the same integral accuracy.Call the function quad to find the definite integral:Format long;Fx二inline ('exp (-x));[I, n]二quad ('FX', 1,2. 5, le-10)二IZero point two eight five seven nine four four four two fivefour seven six six二nSixty-fiveCall the function quad8 to find the definite integral:Format long;Fx二inline ('exp (-x));[I, n] =quad8 (FX, 1,2. 5, le-10)二IZero point two eight five seven nine four four four two fivefour seven five fourThirty-threeThe integrand is defined by a tableIn MATLAB, the problem of determining the function relations defined in tabular form is called trapz (X, Y) functions. The vector X, Y defines the function relation Y二f (X).Example 8-4 calculates definite integral with trapz function.The commands are as follows:X=l:0. 01:2.5:Y二exp (-X);% generated function relational data vectorTrapz (X, Y)二ansZero point two eight five seven nine six eight two four one six three nine threeNumerical solution of 3. double definite integralConsider the following double definite integral problem:By using the dblquad function provided by MATLAB, the numerical solution of the above double definite integral can be obtaineddirectly. The call format of this function is:I=dblquad (F, a, B, C, D, tol, trace)The function asks f (x, y) to double definite integral on the [a, b] * [c, d] regions・The parameter tol, trace is used exactly the same as function quad・Example 8~5 calculates the double definite integral(1)build a function file fxy.m:Function f二fxy (x, y)Global ki;Ki=ki+1:%ki is used to count the number of calls to the integrandF二exp (-x.八2/2). *sin (x. 2+y);(2)call the dblquad function to solve・Global ki; ki二0;I二dblquad (' fxy' , -2, 2, -1, 1)Ki1.57449318974494 (data format related)二kiOne thousand and thirty-eightTwo. Numerical differentiation1numerical difference and difference quotient2the realization of numerical differentiationIn MATLAB, there is no function that provides direct numerical derivatives・ Only the function diff, which calculates the forward difference, is called:DX二diff (X) : calculates the forward difference of vector X, DX (I), =X (i+1), -X (I), i二1,2,・・.N-l.DX二diff (X, n) : calculates the forward difference of the n order of X. For example, diff (X, 2)二diff (diff (X)).DX二diff (A, N, dim): calculates the n order difference of the matrix A, the dim=l (default state), calculates the difference by column, and dim=2 calculates the difference by line・6 cases of Vandermonde matrix generation based on vectorV= [ 1, 2, 3, 4, 5, 6], according to the column difference operation. The commands are as follows:V=vander (1:6)DV二diff (V)% calculates the first order difference of V 二V111111321684212438127931102425664164131256251252551777612962163661二DV31157310211 65 19 5 1 0781 175 37 7 1 02101 369 61 9 1 04651 671 91 11 1 0用不同的方法求函数f(X)的数值导数,并在同一个坐标系中做出f (X)的图像。

MATLAB解方程与函数极值(IV)

MATLAB解方程与函数极值(IV)
符号方程求解
使用Matlab的`syms`和`solve`函数求解符 号方程,例如:x^2-2=0。
函数极值实例
一元函数极值
使用Matlab的`fminbnd`函数求解一元函数的极小值,例如 :f(x)=x^2。
多元函数极值
使用Matlab的`fminsearch`函数求解多元函数的极小值,例 如:f(x,y)=(x-1)^2+(y-2)^2。
变量与数据类型
在MATLAB中,变量名必须以字母开头,可以 包含字母、数字和下划线。
01
数值型变量可以是标量、向量或矩阵,可 以进行各种数值运算。
03
02
MATLAB支持多种数据类型,包括数值型、 字符型、逻辑型和结构体等。
04
字符型变量用于存储文本数据,可以进行 字符串操作。
逻辑型变量用于存储布尔值,可以进行逻 辑运算。
MATLAB具有高效的数值计算能力,支持多种编程语言和操作系统。
Matlab编程基础
01
MATLAB是一种解释型语言,语法相对简单, 易于学习。
03
MATLAB提供了丰富的函数库,可以方便地实现各 种算法和数据处理。
02
MATLAB支持向量和矩阵运算,可以进行高效 的数值计算。
04
MATLAB的编程风格简洁明了,易于阅读和维护。
积分方程求解
数值积分
使用Matlab的数值积分函数,如 `quad`、`quadl`等,对函数进行积 分。这些函数返回积分的近似值。
符号积分
使用Matlab的符号计算工具箱进行符号 积分。例如,`syms x`和`int(f, x)`,其 中`f`是函数句柄,表示对函数进行积分。
03 函数极值
单变量函数极值
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

非线性方程数值求解
(1) LU分解 分解 矩阵的LU分解就是将一个矩阵表示为一个交换下三角矩阵 矩阵的 分解就是将一个矩阵表示为一个交换下三角矩阵 和一个上三角矩阵的乘积形式.线性代数中已经证明,只 和一个上三角矩阵的乘积形式.线性代数中已经证明, 要方阵A是非奇异的 是非奇异的, 分解总是可以进行的 分解总是可以进行的. 要方阵 是非奇异的,LU分解总是可以进行的. MATLAB提供的 函数用于对矩阵进行 分解,其调用格 提供的lu函数用于对矩阵进行 分解, 提供的 函数用于对矩阵进行LU分解 式为: 式为: [L,U]=lu(X):产生一个上三角阵 和一个变换形式的下三角 :产生一个上三角阵U和一个变换形式的下三角 行交换), 阵L(行交换 ,使之满足 行交换 使之满足X=LU.注意,这里的矩阵 必须 .注意,这里的矩阵X必须 是方阵. 是方阵. [L,U,P]=lu(X):产生一个上三角阵 和一个下三角阵 以及 和一个下三角阵L以及 :产生一个上三角阵U和一个下三角阵 一个置换矩阵P,使之满足PX=LU.当然矩阵 同样必须 一个置换矩阵 ,使之满足 .当然矩阵X同样必须 是方阵. 是方阵. 实现LU分解后 线性方程组Ax=b的解 分解后, 的解x=U\(L\b)或 实现 分解后,线性方程组 的解 或 x=U\(L\Pb),这样可以大大提高运算速度. ,这样可以大大提高运算速度.
迭代法求解下列线性方程组. 例7-5 用Jacobi迭代法求解下列线性方程组.设迭代初值为 , 迭代法求解下列线性方程组 设迭代初值为0, 迭代精度为10 迭代精度为 -6. 在命令中调用函数文件Jacobi.m,命令如下: 在命令中调用函数文件 ,命令如下: A=[10,-1,0;-1,10,-2;0,-2,10]; b=[9,7,6]'; [x,n]=jacobi(A,b,[0,0,0]',1.0e-6)
7.1.2 迭代解法 迭代解法非常适合求解大型系数矩阵的方程组. 迭代解法非常适合求解大型系数矩阵的方程组.在数值分析 迭代法, 中,迭代解法主要包括 Jacobi迭代法,Gauss-Serdel迭代 迭代法 迭代 超松弛迭代法和两步迭代法. 法,超松弛迭代法和两步迭代法. 1.Jacobi迭代法 . 迭代法 对于线性方程组Ax=b,如果 为非奇异方阵,即 为非奇异方阵, 对于线性方程组 ,如果A为非奇异方阵 aii≠0(i=1,2,…,n),则可将 分解为 分解为A=D-L-U,其中 为对 ,则可将A分解为 ,其中D为对 角阵,其元素为A的对角元素 的对角元素, 与 为 的下三角阵和上 角阵,其元素为 的对角元素,L与U为A的下三角阵和上 三角阵,于是Ax=b化为: 化为: 三角阵,于是 化为 x=D-1(L+U)x+D-1b 与之对应的迭代公式为: 与之对应的迭代公式为: x(k+1)=D-1(L+U)x(k)+D-1b 这就是Jacobi迭代公式.如果序列 迭代公式. 收敛于 ,则x必 收敛于 是方程Ax=b的解. 的解. 是方程 的解
第7章 MATLAB解方程与函数极值 章 解方程与函数极值 7.1 线性方程组求解 7.2 非线性方程数值求解 7.3 常微分方程初值问题的数值解法 7.4 函数极值
线性方程组求解
7.1 线性方程组求解 7.1.1 直接解法 1.利用左除运算符的直接解法 . 对于线性方程组Ax=b,可以利用左除运算符"\"求解: 对于线性方程组 ,可以利用左除运算符" "求解: x=A\b
Jacobi迭代法的 迭代法的MATLAB函数文件 函数文件Jacobi.m如下: 如下: 迭代法的 函数文件 如下 function [y,n]=jacobi(A,b,x0,eps) if nargin==3 eps=1.0e-6; elseif nargin<3 error return end D=diag(diag(A)); %求A的对角矩阵 求 的对角矩阵 L=-tril(A,-1); %求A的下三角阵 求 的下三角阵 U=-triu(A,1); %求A的上三角阵 求 的上三角阵 B=D\(L+U); f=D\b; y=B*x0+f; n=1; %迭代次数 迭代次数 while norm(y-x0)>=eps x0=y; y=B*x0+f; n=n+1; end
迭代法求解下列线性方程组. 例7-6 用Gauss-Serdel迭代法求解下列线性方程组.设迭代 迭代法求解下列线性方程组 初值为0,迭代精度为10 初值为 ,迭代精度为 -6. 在命令中调用函数文件gauseidel.m,命令如下: 在命令中调用函数文件 ,命令如下: A=[10,-1,0;-1,10,-2;0,-2,10]; b=[9,7,6]'; [x,n]=gauseidel(A,b,[0,0,0]',1.0e-6)
(3) Cholesky分解 分解 如果矩阵X是对称正定的 是对称正定的, 分解将矩阵X分解成 如果矩阵 是对称正定的,则Cholesky分解将矩阵 分解成 分解将矩阵 一个下三角矩阵和上三角矩阵的乘积.设上三角矩阵为R, 一个下三角矩阵和上三角矩阵的乘积.设上三角矩阵为 , 则下三角矩阵为其转置, 则下三角矩阵为其转置,即X=R'R.MATLAB函数 . 函数 chol(X)用于对矩阵 进行 用于对矩阵X进行 分解, 用于对矩阵 进行Cholesky分解,其调用格式为: 分解 其调用格式为: R=chol(X):产生一个上三角阵 ,使R'R=X.若X为非对称 :产生一个上三角阵R, . 为非对称 正定,则输出一个出错信息. 正定,则输出一个出错信息. [R,p]=chol(X):这个命令格式将不输出出错信息.当X为对 :这个命令格式将不输出出错信息. 为对 称正定的, 与上述格式得到的结果相同; 称正定的,则p=0,R与上述格式得到的结果相同;否则 , 与上述格式得到的结果相同 否则p 为一个正整数.如果X为满秩矩阵 为满秩矩阵, 为一个正整数.如果 为满秩矩阵,则R为一个阶数为 为一个阶数为 q=p-1的上三角阵,且满足 的上三角阵, 的上三角阵 且满足R'R=X(1:q,1:q). . 实现Cholesky分解后,线性方程组 分解后, 变成R' 实现 分解后 线性方程组Ax=b变成 'Rx=b,所 变成 , 以x=R\(R'\b). ' .
分解求解例7-1中的线性方程组 例7-2 用LU分解求解例 中的线性方程组. 分解求解例 中的线性方程组. 命令如下: 命令如下: A=[2,1,-5,1;1,-5,0,7;0,2,1,-1;1,6,-1,-4]; b=[13,-9,6,0]'; [L,U]=lu(A); x=U\(L\b) 或采用LU分解的第 种格式,命令如下: 分解的第2种格式 或采用 分解的第 种格式,命令如下: [L,U ,P]=lu(A); x=U\(L\P*b)
分别用Jacobi迭代和 迭代和Gauss-Serdel迭代法求解下列线性 例7-7 分别用 迭代和 迭代法求解下列线性 方程组,看是否收敛. 方程组,看是否收敛. 命令如下: 命令如下: a=[1,2,-2;1,1,1;2,2,1]; b=[9;7;6]; [x,n]=jacobi(a,b,[0;0;0]) [x,n]=gauseidel(a,b,[0;0;0])
分解求解例7-1中的线性方程组 例7-3 用QR分解求解例 中的线性方程组. 分解求解例 中的线性方程组. 命令如下: 命令如下: A=[2,1,-5,1;1,-5,0,7;0,2,1,-1;1,6,-1,-4]; b=[13,-9,6,0]'; [Q,R]=qr(A); x=R\(Q\b) 或采用QR分解的第 种格式,命令如下: 分解的第2种格式 或采用 分解的第 种格式,命令如下: [Q,R,E]=qr(A); x=E*(R\(Q\b))
分解求解例7-1中的线性方程组 例7-4 用Cholesky分解求解例 中的线性方程组. 分解求解例 中的线性方程组. 命令如下: 命令如下: A=[2,1,-5,1;1,-5,0,7;0,2,1,-1;1,6,-1,-4]; b=[13,-9,6,0]'; R=chol(A) ??? Error using ==> chol Matrix must be positive definite 命令执行时,出现错误信息,说明A为非正定矩阵. 命令执行时,出现错误信息,说明 为非正定矩阵. 为非正定矩阵
线性方程组求解
用直接解法求解下列线性方程组. 例7-1 用直接解法求解下列线性方程组. 命令如下: 命令如下: A=[2,1,-5,1;1,-5,0,7;0,2,1,-1;1,6,-1,-4]; b=[13,-9,6,0]'; x=A\b
非线性方程数值求解
2.利用矩阵的分解求解线性方程组 . 矩阵分解是指根据一定的原理用某种算法将一个矩阵分解成 若干个矩阵的乘积.常见的矩阵分解有LU分解,QR分解, 若干个矩阵的乘积.常见的矩阵分解有 分解, 分解, 分解 分解 Cholesky分解,以及 分解, 分解, 分解, 分解 以及Schur分解,Hessenberg分解,奇异 分解 分解 分解等. 分解等.
2.Gauss-Serdel迭代法 . 迭代法 迭代过程中, 在Jacobi迭代过程中,计算时,已经得到,不必再用,即原 迭代过程中 计算时,已经得到,不必再用, 来的迭代公式Dx(k+1)=(L+U)x(k)+b可以改进为 来的迭代公式 可以改进为 Dx(k+1)=Lx(k+1)+Ux(k)+b,于是得到: ,于是得到: x(k+1)=(D-L)-1Ux(k)+(D-L)-1b 该式即为Gauss-Serdel迭代公式.和Jacobi迭代相比, 迭代公式. 迭代相比, 该式即为 迭代公式 迭代相比 Gauss-Serdel迭代用新分量代替旧分量,精度会高些. 迭代用新分量代替旧分量, 迭代用新分量代替旧分量 精度会高些.
相关文档
最新文档