MATLAB Script:
close all
clear
clc
syms x1 x2 x3 x4
f1(x1,x2,x3,x4) = 1*x1 + 2*x2 + 3*x3 + 4*x4;
f2(x1,x2,x3,x4) = 2*x1 + 3*x2 + 4*x3 + 5*x4;
f3(x1,x2,x3,x4) = 3*x1 + 4*x2 + 5*x3 + 6*x4;
f = [f1; f2; f3]
x = [x1; x2; x3; x4]
J = Jcb(f, x)
function J = Jcb(f, x)
J = [];
for i = 1:length(x)
J = [J diff(f, x(i))];
end
end
Sample Output:
f(x1, x2, x3, x4) =
x1 + 2*x2 + 3*x3 + 4*x4
2*x1 + 3*x2 + 4*x3 + 5*x4
3*x1 + 4*x2 + 5*x3 + 6*x4
x =
x1
x2
x3
x4
J(x1, x2, x3, x4) =
[ 1, 2, 3, 4]
[ 2, 3, 4, 5]
[ 3, 4, 5, 6]
Get Answers For Free
Most questions answered within 1 hours.