how to get the gradient of fucntion from vectors to scalars by matlab?

조회 수: 1 (최근 30일)
DARAN XU
DARAN XU 2018년 9월 23일
답변: Arun Mathamkode 2018년 9월 26일
here is the question: f:R^600 -> R f(x)=(Ax-b)^2 where A is a 400*600 matrix and b is 400*1 and both of them are given. how can I get the gradieint(f) at some given x0 by matlab ?
m=400
n=600
A=randn(m,n)
b=randn(m,1)
syms x
f= 0.5*norm(A*x-b)^2
gradient(f,x)
however it does not work because it seems it regard x as scalar, not a vector.

답변 (1개)

Arun Mathamkode
Arun Mathamkode 2018년 9월 26일
I assume you are referring to the gradient of L2 norm squared. You can directly apply the closed form expression of the gradient. The gradient of f at some given x0 will be A'*A*x0-A'*b.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by