Partial diffrentiation not working

1 回表示 (過去 30 日間)
Anshuman S
Anshuman S 2018 年 11 月 10 日
コメント済み: madhan ravi 2018 年 11 月 10 日
This is the following code has an error as :
" Error using sym/diff (line 69)
The second argument must be a variable or a nonnegative integer specifying the number of differentiations.
Error in quiz21 (line 36)
J(j,1)=diff(g,var(j)); % partial derivative matrix
"
The code is given below :
function var1= quiz21()
syms x1 x2 x3 x4 lm
var=[ x1 x2 x3 x4 ]'; % variables matrix , showing number of variables
f(1,1) = (x4)^3 - (204 +2.4*x2 + 0.02*x2*x1 - 1.5*x1) ; % governing equation
f(2,1) = x3 - 1.2*(x4)^2 ; % 3 constraint equations f(2,1), f(3,1) ,f(4,1)
f(3,1) = x4 - ( -5 - x2 )*10*( 1 - exp(-7.621/10)) ;
f(4,1) = x3 - ( x1 - 30 )*19.2*( 1 - exp(-13.31/19.2)) ;
numeq=length(f); % f1+f2+f3+f4
J = sym('A',[numeq 1]); % Column matrix J
p = 10;
g= (f(1,1)- p*( f(2,1) + f(3,1) + f(4,1))); % new equation; containing g.e. + constraints with 'p' weight.
disp(g);
for j=1:numeq % rows of J
J(j,1)=diff(g,var(j)); % partial derivative matrix
end
disp(J)

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 11 月 10 日
You have
var=[ x1 x2 x3 x4 ]';
But' is conjugate transpose. You need .' instead of '
  1 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 10 日
+1 useful

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by