Plotting Multiple Functions on the same graph
2 次查看(过去 30 天)
显示 更早的评论
Trying to plot this fourier sin series with n=1,n=5 and n=15 all on the same graph. Im not sure how. I tried using the hold on function but that didnt work. Here is what i have:
z = 0:0.001:1;
n = 1;
ysin = fsin(z,n);
plot(z,ysin),grid
xlabel('z'),ylabel('sin function')
% Define functions
function f = fsin(z,n)
f = zeros(1,numel(z));
for i = 1:n
an = (-6/(i*pi))*(cos(i*pi)-cos((i*pi)/2));
f = an*sin(n*pi*z)
end
end
0 个评论
采纳的回答
KSSV
2021-3-4
z = 0:0.001:1;
figure
hold on
for n = 1:5:15
ysin = fsin(z,n);
plot(z,ysin)
end
grid
xlabel('z'),ylabel('sin function')
legend('n=1','n=5','n=15')
% Define functions
function f = fsin(z,n)
f = zeros(1,numel(z));
for i = 1:n
an = (-6/(i*pi))*(cos(i*pi)-cos((i*pi)/2));
f = an*sin(n*pi*z) ;
end
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!