How to write sym sum $i^\text{th}$ in $\text{MATLAB}$?

129 Views Asked by At

How to write the function below in MATLAB?

Having hard time to express $i^\text{th}$ in sym sum. Trying to minimize $x$ for the optimization, so $f(x)$ is the objective function. $$ f_0(x)=\sum_{i=1}^nx_i\log(x_i). $$

1

There are 1 best solutions below

2
On

Vectorised operations in MATLAB are a really good practise if you want to evaluate that sum fast.

Let $x$ denote the vector $(x_1,x_2,\dots,x_n)$. You can do it as follows

f0 = sum(x.*log(x))