-1

我一直在尝试使用solve命令获得16个方程(线性)的16个变量的解。

下面我粘贴我的代码

syms x11 x12 x13 x14 x21 x22 x23 x24 x31 x32 x33 x34 x41 x42 x43 x44;
 %defining symbolic variables

x=[x11 x12 x13 x14; x21 x22 x23 x24; x31 x32 x33 x34; x41 x42 x43 x44]; % putting all those variables in matrix form

N4=[-1 3 -3 1;3 -6 3 0;-3 3 0 0;1 0 0 0]; % 4*4 control matrix 
digits(4);% setting precision to 4 digits instead of default 32 
syms sx;% defining a variable sx 
for i=1:8 
    for j=1:8 
        u=(i-1)/7; 
        w=(i-1)/7; 
        sx(i,j)= [u^3 u^2 u 1]*N4*x*N4'[w^3;w^2;w;1]; % this gives me 8*8 matrix
    end
end

for a=1:8 
    for b=1:8 
        kx(a,b)=b; % the x coordinates of 64 points of the image 
    end
end

ex=0 % defining variable ex which is the error function. 

for i=1:8 
    for j=1:8 
        ex= ex+ (sx(i,j)-kx(i,j))^2;
    end
end

diff_x11=vpa(diff(ex,x11)); % I want to find values of x11,x12... 
diff_x12=vpa(diff(ex,x12)); % for which the error ex is minimum
diff_x13=vpa(diff(ex,x13)); % so I differentiate ex with all 16 
diff_x14=vpa(diff(ex,x14)); % variables and get 16 equations
diff_x21=vpa(diff(ex,x21));% and then try to solve them 
diff_x22=vpa(diff(ex,x22)); 
diff_x23=vpa(diff(ex,x23)); 
diff_x24=vpa(diff(ex,x24)); 
diff_x31=vpa(diff(ex,x31)); 
diff_x32=vpa(diff(ex,x32)); 
diff_x33=vpa(diff(ex,x33)); 
diff_x34=vpa(diff(ex,x34)); 
diff_x41=vpa(diff(ex,x41)); 
diff_x42=vpa(diff(ex,x42)); 
diff_x43=vpa(diff(ex,x43)); 
diff_x44=vpa(diff(ex,x44)); 
    qx=solve(diff_x11,diff_x12,diff_x13,diff_x14,diff_x21,diff_x22,diff_x23,diff_x24,diff_x31,diff_x32,diff_x33,diff_x34,diff_x41,diff_x42,diff_x43,diff_x44,x11,x12,x13,x14,x21,x22,x23,x24,x31,x32,x33,x34,x41,x42,x43,x44);

我使用了如上图所示的求解命令。最初我只得到变量 x11 和 x44 的 2 个值。那时精度是默认的 32 位。当我降低精度并开始使用代码中所示的“vpa”命令时,我又得到了两个值 x22 和 x33。最后,我得到了 16 个变量中只有 4 个变量的解决方案,所有 4 个变量都是 4*4 矩阵的对角元素,具有可变元素

我需要得到所有16个。任何帮助将不胜感激。感谢 Ankit

4

1 回答 1

0

如果您正在求解线性方程,为什么要以如此复杂的方式进行呢?

例如,如果要求解线性方程组

Ax+By=C
Dx+Ey=F
Gx+Hy=I

即你想知道最适合三个方程的数值[x;y](在最小二乘意义上),你写

%# A,B, etc are numbers, or arbitrarily complex functions
%# that evaluate to a numerical value at the time the equations are solved. 
matrixA = [A,B;D,E;G,H];
matrixB = [C;F;I];

xyVector = matrixA \ matrixB;
于 2011-07-10T12:56:52.270 回答