Borrar filtros
Borrar filtros

Using symbolic gradient with another function

4 visualizaciones (últimos 30 días)
Braden Kerr
Braden Kerr el 4 de Nov. de 2020
Comentada: Walter Roberson el 4 de Nov. de 2020
Hello,
I have a question regarding the use of symbolic gradient.
I have an initial function, shown below, that is a function of two variables, x(1) and x(2).
fun = @(x) -9*x(1) -10*x(2) + theta*(-log(100-x(1)-x(2))-log(x(1))-log(x(2)) - log(50-x(1)+x(2)));
This function takes in x, which is a 2x1 matrix. What I am hoping to do is taking the symbolic gradient of fun and get the output as another 2x1 matrix with the associated equations. Is this possible?
I would like to get a vector that is the following
[%gradient(fun) for x(1); %gradient of fun for x(2)]
I am currently attempting to use the line of code:
grad_fun = @(x) gradient(x,[x(1),x(2)]);
But it returns an error
I will clarify anthing necessary.
Thank you

Respuestas (1)

Ameer Hamza
Ameer Hamza el 4 de Nov. de 2020
Symbolic gradient require that you define it as a symbolic expression
syms x [1 2]
syms theta
fun = -9*x(1) -10*x(2) + theta*(-log(100-x(1)-x(2))-log(x(1))-log(x(2)) - log(50-x(1)+x(2)));
d_fun = gradient(fun, x)
Result
>> d_fun
d_fun =
- theta*(1/(x1 + x2 - 100) - 1/(x2 - x1 + 50) + 1/x1) - 9
- theta*(1/(x2 - x1 + 50) + 1/(x1 + x2 - 100) + 1/x2) - 10
  2 comentarios
Braden Kerr
Braden Kerr el 4 de Nov. de 2020
Is your result, d_fun, a 2x1 matrix or just an output?
Walter Roberson
Walter Roberson el 4 de Nov. de 2020
2x1 symbolic matrix

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by