从向量到标量的函数梯度

时间:2015-04-22 22:48:12

标签: matlab vector gradient scalar

我需要编写一个标量函数来获取长度未知的向量。我举了一个例子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    android:longClickable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false">


    <TextView
        android:id="@+id/listelement_weekoverview_tv_mo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_weight="1"
        android:background="@drawable/weeklylist_rndrectangle"
        android:gravity="center_horizontal"
        android:singleLine="false"
        android:textColor="@color/appcolor_red_base" />

        ...
</LinearLayout>

apt-cache show mawk

但是当我尝试计算此函数的渐变时,我得到0例如:

%gets vector and returns x1^1 + x2^2 + ... + xn^n
function [ output ] = func2( x )
u=0;
for j = 1 : length(x)
     u = u + x(j)^j;
end
output = u;
end

但是

%gets vector and returns sin(x1) + sin(x2) + ... + sin(xn)
function func = func1( x )
    func = sum(sin(x));
end

我正在寻找一种方法来实现渐变(func1,x)并获得cos(x(1))cos(x(2))...(cos(x(n))所以在上面的例子中它假设是:

func1([1,2,3]) = -0.865837027279448

有人能提出解决此问题的最佳方法吗?

0 个答案:

没有答案