Matlab結果を小数で表示

912 ワード

1、一般状況format long format short
format long
a=2*pi

format short
b=2*pi

2、符号を用いた計算 vpa
clear
clc
syms X1 X2 X3 X4
b=[4,4,4,4;%1
    1,1,1,1;%2
    8,8,8,8;%3
    6,6,6,6;%4
    3,7,3,7;%5
    ];
a=b'
c=[0.1;0.2;0.2;0.4;0.4];
S1=(X1-a(1,1)).^2+(X2-a(2,1)).^2+(X3-a(3,1)).^2+(X4-a(4,1)).^2+c(1);
S2=(X1-a(1,2)).^2+(X2-a(2,2)).^2+(X3-a(3,2)).^2+(X4-a(4,2)).^2+c(2);
S3=(X1-a(1,3)).^2+(X2-a(2,3)).^2+(X3-a(3,3)).^2+(X4-a(4,3)).^2+c(3);
S4=(X1-a(1,4)).^2+(X2-a(2,4)).^2+(X3-a(3,4)).^2+(X4-a(4,4)).^2+c(4);
S5=(X1-a(1,5)).^2+(X2-a(2,5)).^2+(X3-a(3,5)).^2+(X4-a(4,5)).^2+c(5);
f1x=-(1./S1+1./S2+1./S3+1./S4+1./S5);
df1=gradient(f1x);
---------------------------------------------
%              ,   
--------------------------------------------
f1=vpa(subs(f1x,{X1,X2,X3,X4},{4,4,4,4}))
df1=vpa(subs(df1,{X1,X2,X3,X4},{4,4,4,4}))