Hi
c0 must be numeric, but my symbolic functions can not work correctly?
Where is my mistake?
Thx
clear all
clc
syms x1 x2
F=x1^2+x2^2-4*x1-2*x1*x2;
gradx1=gradient(F,x1);
gradx2=gradient(F,x2);
c=[gradx1; gradx2];
fun_x0=@(x1,x2) F;
fun_c1_x0=@(x1,x2) gradx1;
fun_c2_x0=@(x1,x2) gradx2;
x0=[1,1];
c_x0_1=fun_c1_x0(x0(1),x0(2));
c_x0_2= fun_c2_x0(x0(1),x0(2));
c0=[c_x0_1; c_x0_2];
c0=c0';

 採用された回答

madhan ravi
madhan ravi 2018 年 12 月 22 日
編集済み: madhan ravi 2018 年 12 月 22 日

0 投票

Because you mixed function handle in place of subs()/matlabFunction().
Try this:
syms x1 x2
F=x1^2+x2^2-4*x1-2*x1*x2;
gradx1=gradient(F,x1);
gradx2=gradient(F,x2);
c=[gradx1; gradx2];
fun_x0= F;
fun_c1_x0=gradx1
fun_c2_x0=gradx2
x0=[1,1];
c_x0_1=subs(fun_c1_x0,{x1,x2},{x0(1),x0(2)});
c_x0_2=subs(fun_c2_x0,{x1,x2},{x0(1),x0(2)});
c0=[c_x0_1; c_x0_2];
c0=c0.'

2 件のコメント

Thanks a lot
madhan ravi
madhan ravi 2018 年 12 月 22 日
編集済み: madhan ravi 2018 年 12 月 22 日
Anytime :) , here is another simple way:
syms x1 x2
F=x1^2+x2^2-4*x1-2*x1*x2;
gradx1=gradient(F,x1);
gradx2=gradient(F,x2);
c=[gradx1; gradx2];
fun_x0= F;
fun_c1_x0(x1,x2)=gradx1;
fun_c2_x0(x1,x2)=gradx2;
x0=[1,1];
c_x0_1=fun_c1_x0(x0(1),x0(2));
c_x0_2= fun_c2_x0(x0(1),x0(2));
c0=[c_x0_1; c_x0_2];
c0=c0.'

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by