Assuming I have a function where is a vector. Is there a method that I can use system equation to obtain

답변 (1개)

KSSV
KSSV 2021년 5월 18일

1 개 추천

Let b be your N*1 vector and f be your function values evealuated and of size N*1.
df = gradient(f,b) ; % first derivative
d2f = gradient(df,b) ; % second order gradient
The above is one method. Also you can evaluate the second derivative of f w.r.t. b and then you can substitute the values of b at the end.
Example:
syms b
f = 3*b^2+2*b+5 ;
d2f = diff(f,b,2)

댓글 수: 7

Kevin Zhu
Kevin Zhu 2021년 5월 18일
However, df here is a vector due to b is a vector, gradient(df,b) is not applicable I think.
KSSV
KSSV 2021년 5월 18일
It is very much applicable.
Kevin Zhu
Kevin Zhu 2021년 5월 18일
KSSV
KSSV 2021년 5월 18일
Show us the whole code...
Kevin Zhu
Kevin Zhu 2021년 5월 18일
clear all
close all
clc
rng(10,'twister')
N = 4;
S = 2;
F = dftmtx(N)./sqrt(N);
D = 3;
F_SUB = F(:,1:S);
syms b [N 1];
A_var = diag(b)*F_SUB;
W_var = ((A_var'*A_var) + (A_var'*A_var)')./2;
fobj = trace(inv(W_var));
g = gradient(fobj, b);
gg = gradient(g, b);
KSSV
KSSV 2021년 5월 18일
The variable g is 4*1. Run gradient i.e. gg for each element.
gg = gradient(g(1), b);
Kevin Zhu
Kevin Zhu 2021년 5월 18일
Actually I'm wondering if there is way to directly get the second order gradient of it. If that cannot be done, then it would be fine.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2021년 5월 18일

댓글:

2021년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by