Question

Write a MatLab function J = Jcb(f, x) that computes the jacobian of the vector f...

Write a MatLab function J = Jcb(f, x) that computes the jacobian of the vector f of functions of x. Input f is the vector of functions [f1(x1, x2, x3...); f2(x1, x2, x3...); ...] and inout x is a vector of unkown x [x1; x2; x3;...]. Output J is the jacobian square matrix of vector f.

Homework Answers

Answer #1

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]

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a MatLab code J = Jcb(X) that computes the jacobian of a nonlinear vector of...
Write a MatLab code J = Jcb(X) that computes the jacobian of a nonlinear vector of functions of X. Input X is a vector of unkown functions of X and output J is the jacobian of the nonlinear vector function of X.
Create a function x=backsub(U,y) in matlab that accepts as input arguments a nxn matrix U and...
Create a function x=backsub(U,y) in matlab that accepts as input arguments a nxn matrix U and n-vector y, and returns as output a column vector x consisting of the values of the unknowns x1; x2; : : : ; xn.
Write a function called sum_half that takes as input a square matrix A and computes the...
Write a function called sum_half that takes as input a square matrix A and computes the sum of its elements that are in the upper right triangular part of A, that is, elements in the diagonal and elements that are to the right of it. For example, if the input is [1 2 3; 4 5 6; 7 8 9], then the function would return 26. (That is, 1+2+3+5+6+9) Note, the function triu is not allowed. Please write as you...
Write a function in Matlab that takes as input the number of iterations k, the size...
Write a function in Matlab that takes as input the number of iterations k, the size n, and a sparse matrix A. Have this function run the Power method for k iterations on an initial guess the vector of 1’s and output the dominant eigenvalue and its corresponding eigenvector. Use only basic programming. Write out or print out your function.
IN MATLAB: Write a function file that takes a vector as an input and returns another...
IN MATLAB: Write a function file that takes a vector as an input and returns another vector with all repeated elements of the original vector. For example, the vector [3 4 1 0 4 -5 7 3] would return the vector [3 4]. Do not use the built-in function "repelem."
Write a MATLAB function function [ AvgPos, AvgNeg ] = PosNegAverage ( X ) that calculates...
Write a MATLAB function function [ AvgPos, AvgNeg ] = PosNegAverage ( X ) that calculates average of positive, AvgPos, and negative, AvgNeg, elements of array X, using the for‐end loop and if‐elseif‐else‐end selection structure. Do not use build‐in MATLAN functions in calculations. Apply the developed function for the following vector X = [ ‐7, 1, 0, 0, 12, 6, 33.2, ‐7.5 ];
Write a function find square root(x) that takes as input a number x and as output...
Write a function find square root(x) that takes as input a number x and as output returns the square root of x. Your results should converge to at least 6 decimal places. matlab question
Write a function custom sort(v) that takes as input a vector v and as output returns...
Write a function custom sort(v) that takes as input a vector v and as output returns the vector w sorted into increasing order. For example, if the input is [−2 1 3 1 5], the output should be [−2 1 1 3 5]. Don’t use the built-in ”sort” function or anything similar. matlab question
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an n-by-n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note that...
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its...
MATLAB: Write a function called matrix_problem1 that takes a matrix A of positive integers as its sole input. If the assumption is wrong, the function returns an empty matrix. Otherwise, the function doubles every odd element of A and returns the resulting matrix. Notice that the output matrix will have all even elements. For example, the call B = matrix_problem([1 4; 5 2; 3 1], will make B equal to [2 4; 10 2; 6 2]. The function should work...