用matlab画出该函数表达式的图 其中N=1:64,n=1,2,4时g(n)

1个回答

  • 将以下程序放在一个m文件里运行,即可得到你要的结果.标注什么的根据自己的需要更改.

    function []=myhelp_plot()

    nn = [1 2 4];

    for ii = 1:length(nn)

    n = nn(ii);

    for N = 1:64

    mysum = 0;

    for i = 1:n

    temp = (nchoosek(32,i)*(i^n+my_sum1(i,n)))/(32^n);

    temp = temp*(i*(N-n)/32);

    mysum = mysum+temp;

    end

    gn(N) = n+mysum;

    end

    GN(:,ii) = gn;

    end

    N = 1:64;

    plot(N,GN(:,1),'r',N,GN(:,2),'g',N,GN(:,3),'b')

    legend('n=1','n=2','n=4');

    xlabel('N');ylabel('g(n)');

    title('my help plot copyright cxd1301')

    function output = my_sum1(i,n)

    my_sum = 0;

    for k = 1:(i-1)

    temp = (-1)^k*nchoosek(i,k)*(i-k)^n;

    my_sum = my_sum+temp;

    end

    output = my_sum;

    如有问题欢迎追问,觉得可以请给采纳.

    copyright cxd1301