Why doesn't my code work correctly?
Show older comments
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';
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!