2011-07-10 30 views
-1

解決使用「解決」命令16個變量我一直在試圖得到一個溶液與16個方程(線性)與解決命令16個變量。求解方程16同時在MATLAB

下面我粘貼我的代碼

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); 

我使用的解決命令,如上所示。最初,我只能得到2個變量x11和x44的值。那個時候精度是默認的32位數。正如我降低了精度和使用「VPA」命令啓動,如圖中的代碼我有兩個以上值X22和X33。最後我得到的解決方案只有4個變量16,並將其所有4可變元素

4 * 4矩陣對角線元素我需要讓他們的全部16。任何幫助將不勝感激。由於ANKIT

+3

請使用反碼或高亮顯示代碼並選擇「{}」圖標將代碼格式化爲代碼。 – PengOne

+1

@ ankitm511:請只發布相關的代碼。在開始處理圖像的部分與以後的方程式無關。 – Amro

回答

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; 
+0

@Amro:好的...圖像部分正在被用於稍後使用的代碼的下一部分。無論如何,我已經編輯它。 – ankitm511

+0

jonas:謝謝你的建議。但是在這裏我不知道係數A,B,C,D等。所有的方程都是通過用16個不同的變量部分地對一個方程進行16次微分而得到的。 MATLAB自己在表達式中找到變量,並在我使用'solve'命令時解決它們 – ankitm511

+0

@pengOne:對不起,我是新手!我已經格式化代碼 – ankitm511