这是一道关于Matlab的题,write the MATLAB program to calculate the values of the functionfor at intervals of .Do this twice,once using loops and branches,and once using vectorized code.这是那个函数
来源:学生作业帮助网 编辑:作业帮 时间:2024/05/25 22:21:02
这是一道关于Matlab的题,write the MATLAB program to calculate the values of the functionfor at intervals of .Do this twice,once using loops and branches,and once using vectorized code.这是那个函数
这是一道关于Matlab的题,
write the MATLAB program to calculate the values of the function
for at intervals of .Do this twice,once using loops and branches,and once using vectorized code.
这是那个函数
这是一道关于Matlab的题,write the MATLAB program to calculate the values of the functionfor at intervals of .Do this twice,once using loops and branches,and once using vectorized code.这是那个函数
你的题目问题不完整,你的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);
需要什么解释可以给我留言!