2014-01-15 60 views
0

我想解決一個符號向量的方程組。等式包含參數。運行附加的代碼給了我許多不正確的解決方案。我猜的功能aussumes第二輸入是公式,太:用Matlab動態矢量解參數方程組

Warning: 4 equations in 3 variables. 

ans = 

    a_tilde2: [1x1 sym] 
    a_tilde3: [1x1 sym] 
      p1: [1x1 sym] 

我可以通過單獨上市的a_tilde_sym(iRange)條目解決這個問題,如:

solve(bounday_conditions, a_tilde_sym(iRange(1)), a_tilde_sym(iRange(2)), etc.) 

但由於這個長度矢量是依賴於函數輸入,我不能動態地做到這一點。有什麼建議麼?

%function variation_polynomial (sysord, reldeg) 
sysord = 2; 
reldeg = 1; % e.g. 

% setting up symbolic variables 
disp('calculating variation from desired trajectory'); 
fprintf('N =%3.0f, R =%3.0f\n', sysord, reldeg); 

iRange = reldeg+1:2*reldeg+1; 
jRange = 1:sysord-reldeg; 
syms T_sym real % maneuver time 
syms t_sym real % time 
p_sym = sym('p', [sysord-reldeg, 1]); % parameters of polynom 
assume(p_sym, 'real'); 
a_tilde_sym = sym('a_tilde', [iRange(end), 1]); % parameters of polynom 
assume(a_tilde_sym, 'real'); 
y_tilde = sym('derivatives', [reldeg+1, 1]); 

% setting up system of equations 
i_polynomial_sum = 0; 
for iIdx = iRange 
    i_polynomial_sum = i_polynomial_sum + a_tilde_sym(iIdx)*(t_sym/T_sym)^iIdx; 
end 

j_polynomial_sum = 0; 
for jIdx = jRange 
    j_polynomial_sum = j_polynomial_sum + p_sym(jIdx)*(t_sym/T_sym)^(jIdx + 2*reldeg + 1); 
end 

y_tilde(1) = i_polynomial_sum + j_polynomial_sum; 
for rIdx = 1:reldeg 
    y_tilde(rIdx+1) = diff(y_tilde(1), t_sym, rIdx); 
end 

% solving 
bounday_conditions = subs(y_tilde, t_sym, T_sym); 
for runIdx = 1:reldeg+1 
    bounday_conditions(runIdx) = bounday_conditions(runIdx) == 0; 
end 
bounday_conditions = simplify(bounday_conditions); 

solve(bounday_conditions, a_tilde_sym(iRange)) 

回答

0

是,solve需要你的第二輸入,a_tilde_sym(iRange)是一組方程而不是變量(多個)需要解決的。這有一個很好的理由。前兩個公式(bounday_conditions(原文如此))是以標量變量a_tilde2a_tilde3而不是矢量[a_tilde2;a_tilde3]

s = solve(bounday_conditions, a_tilde_sym(2), a_tilde_sym(3)) 

[a_tilde2,a_tilde3] = solve(bounday_conditions, a_tilde_sym(2), a_tilde_sym(3)) 
:您可以通過顯式地說明你的變量解決這個問題