Using symbolic gradient with another function
3 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
Ameer Hamza
2020 年 11 月 4 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!