这是一道关于Matlab的题,write the MATLAB program to calculate the val

1个回答

  • 你的题目问题不完整,你的interval没有给出具体的值,就是那个“at intervals of .”这里没有东西.我假设这里是interval = pie/100,然后给你一个参考.我的t取值范围是 -pie 到 pie,自己可以改成任意pie的取值范围.

    t = -pi:pi/100:pi;

    n = size(t,2);

    f = zeros(1,n);

    % using loops to calculate the values of the function

    for i = 1:n

    if t(i)>0

    f(i) = sin(t(i));

    else

    f(i) = 0;

    end

    end

    % using vectorized code to calculate the values of the function

    tl = t>0;

    t = t.*tl;

    f = sin(t);

    需要什么解释可以给我留言!