2014-05-10 4 views
1

Matlab에서 선형 방정식 시스템을 풀고 싶습니다. 문제는이 시스템이 일반적으로 비 고유 솔루션을 갖기 때문에 (Nullspace가 중요하지 않음)이 시스템이 매개 변수 베타 (0이 아닌 값)에 의존한다는 것입니다. 따라서이 매개 변수와 관련하여 솔루션을 갖고 싶습니다. MATLAB은 이것을 할 수 있습니까? 어떤 식으로 방정식과 매개 변수를 입력해야하고 Matlab이 모든 솔루션을 제공 할 수 있도록 어떤 명령을 사용해야합니까?Matlab에서 방정식을 풀어 냄

답변

1

희망이 도움이됩니다. 그것은 최적이되는 것을 의미하지 않습니다. 그것은 약간 matlab에 약간 다른 구문 분석 규칙을 가지고 옥타브에서 테스트되었습니다, 나는 일반적으로 옥타브와 matlab의 공유 구문 내에서 유지하지만 좋은 경고를 제공하는 것이 좋습니다.

function x=solver(A,y,freeVars) 
    % 
    % x=solver(A,y,freeVars) 
    % 
    % Solve system of equations Ax=y for x. 
    % Use elements of freeVars to fill undetermined ranks and produce 
    % a unique solution. 
    % 
    % Typically this is of form 
    % 
    % f_1(t_1) * x_1 + f_2(t_1) * x_2 ... + f_n(t_1) * x_n = y_1 
    % 
    % f_1(t_2) * x_1 + f_2(t_2) * x_2 ... + f_n(t_2) * x_n = y_2 
    % . 
    % . 
    % . 
    % f_1(t_m) * x_1 + f_2(t_m) * x_2 ... + f_n(t_m) * x_n = y_m 
    % 
    % A= [ f_1(t_1) , f_2(t_1) , ... f_n(t_1) ; 
    %  f_1(t_2) , f_2(t_2) , ... f_n(t_2) ; 
    %  ... 
    %  f_1(t_m) , f_2(t_m) , ... f_n(t_m) ]; 
    % 
    % For example a first order linear fit would be 
    % f_1(t) = 1 
    % f_2(t) = t 
    % 
    % 
    % If the problem is overdetermined this would be a least squares problem 
    % that is not going to be addressed here. 
    % 
    % Assuming fully determined, one solution would be 
    % Given:Ax=y 
    % [U,S,V]= svd(a) 
    % such that U*S*V'*x = y 
    %    S*V'*x = U'*y 
    % for fully determined case S is invertable. 
    % for less than fully determined case rank(S) < n, 
    % Let [ S_r | 0 ] represent the non-zero and zero columns of S. 
    % and [ V_r | 0 ] represent the columns of V that are used vs. 
    %     ones multiplied by zeros of S. 
    %    [ S_r | 0 ] * [ V_r |0 ]' * x = [ U_r | 0 ]' * y 
    % 
    % V_r is in some sense a projection of your x coordinates into rank(S) 
    % subspace that is fully determined. That portion can be solved 
    % but requires additional parameters to fully determine X. 
    % 
    %     x = V * [ inv(S_r) U_r' * y ; alpha ] 
    % 
    % where alpha's are free parameters filling the extra degrees or freedom. 
    % 
    % The columns of V that aren't included in V_r are (were temporarily 
    % temporarily replace by zeros determine which of the x parameters are 
    % impacted by each of the free parameters. 
    % 
    % Rather than use freevariables as I do here I presume one could set 
    % some x's that were influenced by those freevars to desired values 
    % and backsolve what values of free vars would produce those x's and 
    % then obtain values for the remaining undetermined x's from the computed 
    % free vars. 
    % 
    % 
    [U,S,V]=svd(A) 
    s=diag(S); 
    % 
    % Default rank tolerance taken from help page on rank. 
    % 
    r=sum(s>max(size(A)) * max(s)* eps) 
    % 
    % 
    U_r=U(:,1:r) 
    S_r=S(1:r,1:r) 
    % 
    alpha = freeVars(1:(size(y,1)-r) ,1) 
    % 
    invS_r = diag(diag(S_r).^-1) 
    x = V * [ invS_r * U_r' * y ; alpha ]; 
    % 
    % aka: 
    % x = V_r * S_r^(-1) * U_r' *y + V_n * alpha 

간단한 테스트 케이스

% Fully determined case: 
    % mt+b = y x=[b;m]=[1;2] evaluated at t=0, t=1 
    % 
    t=[ 0 ; 1] 
    % 
    % A = [ 1 , t ] 
    % 
    A=[ ones(2,1) , t] 
    % 
    % 
    xd=[ 1 ; 2 ] 
    y = xd(1) + xd(2)* t 

    x=solver(A,y,[1;2;3;4;5]) 
    xerr=xd-x 
    yerr=A*x-y 

    % under determined case: 
    % mt+b = y w/ x=[b;m]=[1;2] evaluated at t=0, t=0 
    % 
    t=[ 0 ; 0] 
    % 
    % A = [ 1 , t ] 
    % 
    A=[ ones(2,1) , t] 
    % 
    % 
    xd=[ 1 ; 2 ] 
    y = xd(1) + xd(2)* t 

    x=solver(A,y,[1;2;3;4;5]) 
    xerr=xd-x 
    yerr=A*x-y 
0

맥시마 [1]는 (예컨대 사용자가 한 바와 같이 beta 같이) 심볼 변수를 포함하는 방정식을 해결하고, 용액이 고유하지 않은 경우, 더미 변수를 소개 이러한 그 해법은 모든 더미의 값에 유효합니다. 예를 들어 : 여기서 %r2

(%i5) solve ([3 * x + beta * y = 5, -6 * x - 2*beta * y = -10], [x, y]); 
solve: dependent equations eliminated: (2) 
           %r2 beta - 5 
(%o5)     [[x = - ------------, y = %r2]] 
            3 

는 더미 변수이고, 상기 용액의 임의의 값 %r2 작동.

그러나 Maxima의 상징적 인 해결사는 많은 메모리를 사용하며 처리 할 수있는 문제의 크기에 상대적으로 낮은 한계를 둘 수 있습니다. 얼마나 많은 방정식을 가지고 있고 얼마나 많은 변수가 있습니까? 어쩌면 여기 방정식 시스템을 게시 할 수 있습니다.

미안하지만 나는 Matlab에서이 문제를 해결하는 방법을 모른다.

[1] http://maxima.sourceforge.net, http://sourceforge.net/p/maxima

관련 문제