作业帮 > 数学 > 作业

用matlab求解:12*x1-x2=0; x2-[x1/30]*360-x3=0; x4-[(x3-x1)/30]*3

来源:学生作业帮 编辑:拍题作业网作业帮 分类:数学作业 时间:2024/05/02 04:52:54
用matlab求解:12*x1-x2=0; x2-[x1/30]*360-x3=0; x4-[(x3-x1)/30]*360-x1=0; 12*x3-x4=0; 其中[ ]为取整
很明显这是一个非线性的方程组问题,用matlab中的fsolve函数求解,其中函数取整有好多种,如向上取整、向下取整、四舍五入取整,不知你这里指的是哪一种?
m文件(这里的取整函数用的是floor,当然根据你的具体情况也有其他相应的取整函数)
function f=ff(x)
f=[12*x(1)-x(2);x(2)-floor(x(1)/30)*360-x(3);x(4)-floor((x(3)-x(1))/30)*360-x(1);12*x(3)-x(4)];
命令窗口:
optimset.Display='iter';optimset.TolX=1e-10;optimset.Tolfun=1e-10;
[x,y,c,d]=fsolve('ff',100*rand(1,4),optimset)%100*rand(1,4)为随机给的四个变量的初始值
结果:
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 5 400626 6.77e+003 1
1 10 385664 1 6.64e+003 1
2 15 349536 2.5 6.31e+003 2.5
3 20 267209 6.25 5.5e+003 6.25
4 25 111328 15.625 3.45e+003 15.6
5 30 5432 39.0625 65.9 39.1
6 31 5432 79.0792 65.9 97.7
7 36 3124.87 19.7698 104 19.8
8 41 87.9944 49.4245 8.29 49.4
9 42 87.9944 10.1088 8.29 124
10 47 50.6786 2.52719 13.2 2.53
11 52 1.38185 6.31799 1.04 6.32
12 57 5.52667e-017 1.26741 127 15.8
13 62 0 5.25674e-009 0 15.8
Optimization terminated:first-order optimality is less than options.TolFun.
x =
0 0 0 0
y =
0
0
0
0
c =
1
d =
iterations:13
funcCount:62
algorithm:'trust-region dogleg'
firstorderopt:0
message:'Optimization terminated:first-order optimality is less than options.TolFun.'
多运行几次(多试几个初值)其中x=(0,0,0,0)是方程的解的一个解,你也可以自己给一些初值试试,毕竟这是非线性的方程,到底有几个解谁也说不准.这里需要注意的是,运行结果中的y这个列向量的值是非常重要的参考,如果这个列向量不为0那么说明这个解是有误差的,一般要求这个列向量的每个值都小于10^(-10),越小越好!