Plotting Multiple Functions on the same graph

15 visualizaciones (últimos 30 días)
Will Jeter
Will Jeter el 4 de Mzo. de 2021
Respondida: KSSV el 4 de Mzo. de 2021
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

Respuesta aceptada

KSSV
KSSV el 4 de Mzo. de 2021
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

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by