How can I plot my function?
1 view (last 30 days)
Show older comments
H. Anil Devrimsel
on 25 Nov 2020
Answered: David Hill
on 25 Nov 2020
I am trying to use Matlab but I don't remember basic functions. Could anyone help why Matlab couldn't plot this code?
for n=1:20
for i=-1000:1000
x=i/1000;
u=(((2*(-1)^n))/(n*pi))*((6/((n^2*pi^2)^3))-1)*sin(n*pi*x);
hold on
plot (x,u);
end
end
0 Comments
Accepted Answer
Walter Roberson
on 25 Nov 2020
You are plotting with scalar u and scalar x. Remember that you need to plot() with at least two adjacent real-valued coordinates in a single call in order for MATLAB to draw a line.
for n=1:20
i=-1000:1000;
x=i/1000;
u = (((2*(-1)^n))/(n*pi))*((6/((n^2*pi^2)^3))-1)*sin(n*pi*x);
hold on
plot (x,u, '-*');
end
0 Comments
More Answers (1)
David Hill
on 25 Nov 2020
hold on
i=-1000:1000;
x=i/1000;
for n=1:20
u=(((2*(-1)^n))/(n*pi))*((6/((n^2*pi^2)^3))-1)*sin(n*pi*x);
plot(x,u);
end
0 Comments
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!