以上内容没有1000字,自己再展开下吧
function tonglunsyms x1 x2 x3 x4
F=[-cos(x1)+cos(x2)-cos(x3)+cos(x4)-0.6
-cos(5*x1)+cos(5*x2)-cos(5*x3)+cos(5*x4)
-cos(7*x1)+cos(7*x2)-cos(7*x3)+cos(7*x4)
-cos(11*x1)+cos(11*x2)-cos(11*x3)+cos(11*x4)]
var = sym(symvar(findsym(F)))%var is string 要变换下
dF = jacobian(F,var)
x0=[0.39 0.65 0.91 1.18]'
Fx = subs(F,findsym(F),x0)
N=1400
h=1/N
b=-h*Fx
for i=1:N
A=subs(dF,var,x0)
k1=inv(A)*b
A=subs(dF,var,x0+0.5*k1)
k2=inv(A)*b
A=subs(dF,var,x0+0.5*k2)
k3=inv(A)*b
A=subs(dF,var,x0+0.5*k3)
k4=inv(A)*b
x0=x0+(k1+2*k2+2*k3+k4)/6
end
x=x0
disp('The Solution is:')
disp('x=')disp(x)
subs(F,findsym(F),x)
=======================
The Solution is:
x=
-5.9548
-5.8381
-1.6512
-0.9719
ans =
1.0e-003 *
0.0040
-0.1540
-0.1043
0.5477
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)