Plotting Multiple Functions on the same graph

14 次查看(过去 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

采纳的回答

KSSV
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 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by