HOW SHOULD DRAW THIS IN LOOP FORM? WHERE IS THE PROBLEM IN MY CODE?
1 次查看(过去 30 天)
显示 更早的评论
my code:
s=0;
for n=1:0.01:10
s=s+(-1^n+1*sin(n*pi*x));
end
f=(2/pi)*s;
plot(x,f)
Where is wrong in my code?
4 个评论
Walter Roberson
2018-12-13
You are defining x to have only 11 points, to exist only at the integers. Your required plot is clearly defined much denser than that.
采纳的回答
更多回答(1 个)
madhan ravi
2018-12-13
x=linspace(-5,5,10000);
s=0;
for n=1:0.01:10
s=s+(-1^n+1*sin(n*pi*x));
end
f=(2/pi)*s;
plot(x,f)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!