HOW I COULD DRAW THIS FUNCTION

2 visualizzazioni (ultimi 30 giorni)
HADIMARGO
HADIMARGO il 7 Dic 2018
Risposto: HADIMARGO il 13 Dic 2018
IMG_20181203_165117.jpg
  2 Commenti
madhan ravi
madhan ravi il 7 Dic 2018
upload the code that you tried
HADIMARGO
HADIMARGO il 7 Dic 2018
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.

Accedi per commentare.

Risposta accettata

HADIMARGO
HADIMARGO il 13 Dic 2018
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

Più risposte (3)

madhan ravi
madhan ravi il 7 Dic 2018
Modificato: madhan ravi il 7 Dic 2018
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 Commenti
HADIMARGO
HADIMARGO il 7 Dic 2018
Modificato: HADIMARGO il 7 Dic 2018
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 il 7 Dic 2018
Modificato: madhan ravi il 7 Dic 2018
Anytime :) , read more about cumsum() and linspace()

Accedi per commentare.


HADIMARGO
HADIMARGO il 8 Dic 2018
my teacher say it isnot correct. you should put it in a loop.
  1 Commento
Walter Roberson
Walter Roberson il 8 Dic 2018
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.

Accedi per commentare.


HADIMARGO
HADIMARGO il 8 Dic 2018
can anyone write complete answer with loop?

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by