HOW I COULD DRAW THIS FUNCTION

2 次查看(过去 30 天)
IMG_20181203_165117.jpg
  2 个评论
madhan ravi
madhan ravi 2018-12-7
upload the code that you tried
HADIMARGO
HADIMARGO 2018-12-7
x=0:1:50;
syms n;
y=((2/pi)*((-1)^n+1)*(sin(pi*x)))/n;
symsum(y,n,1,inf);
figure(1);
plot(x,y)
i should say that i am a beginner.

请先登录,再进行评论。

采纳的回答

HADIMARGO
HADIMARGO 2018-12-13
final answer by myself!!
x=linspace(-5,5,1000);
s=0;
for n=1:1:10000
p=((-1)^(n+1)*sin(n*pi*x))/n;
s=s+p;
end
f=(2/pi)*s;
plot(x,f)
final.jpg

更多回答(3 个)

madhan ravi
madhan ravi 2018-12-7
编辑:madhan ravi 2018-12-7
Use cumsum() to define the behaviour of the alternating series:
x=linspace(0,50,10000);
n=1:10000;
y=(2/pi).*cumsum((((-1).^n+1).*(sin(pi.*x)))./n);
figure(1);
plot(x,y)
  2 个评论
HADIMARGO
HADIMARGO 2018-12-7
编辑:HADIMARGO 2018-12-7
so tnx madhan ravi. i will send this answer to my teacher. if it correct i will get 1 score of 20 .
madhan ravi
madhan ravi 2018-12-7
编辑:madhan ravi 2018-12-7
Anytime :) , read more about cumsum() and linspace()

请先登录,再进行评论。


HADIMARGO
HADIMARGO 2018-12-8
my teacher say it isnot correct. you should put it in a loop.
  1 个评论
Walter Roberson
Walter Roberson 2018-12-8
If you have TheResult = cumsum(SomeVector) then you can recode that in a loop as
TheResult(1) = SomeVector(1);
for LoopVariable = 2 : length(SomeVector)
TheResult(LoopVariable) = TheResult(LoopVariable-1) + SomeVector(LoopVariable);
end
... Approximately.

请先登录,再进行评论。


HADIMARGO
HADIMARGO 2018-12-8
can anyone write complete answer with loop?

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by