Borrar filtros
Borrar filtros

Graphs Not Showing Up

2 visualizaciones (últimos 30 días)
Kevin Lee
Kevin Lee el 17 de Oct. de 2016
Editada: Massimo Zanetti el 17 de Oct. de 2016
clear all;
close all;
clc;
x = linspace(0,2);
for t = [0 1 2 3 4]
n = 2;
Cn = 32;
Dn = 0;
u2 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 4;
Cn = 32;
Dn = 0;
u4 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 5;
Cn = 32;
Dn = 0;
u5 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 6;
Cn = 32;
Dn = 0;
u6 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 12;
Cn = 32;
Dn = 0;
u12 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
u = u2 + u4 + u5 + u6 + u12
plot(x,u)
hold on
grid on
legend('0', '1', '2', '3', '4')
title('u(x,t)')
xlabel('x')
ylabel('u(x,t)')
end
This is my code to plot multiple graphs for a PDE, however no graphs actually show up for t = 0, 1 and 2. What's weird though is when I just have
t = 0
the plot comes up. Would anyone be able to help me as to why it is not working when trying to plot for multiple t?

Respuestas (2)

KSSV
KSSV el 17 de Oct. de 2016
It is showing up for all the time steps....But it is taking same values. so you are able to see only few curves. Check the below code:
clear all;
close all;
clc;
x = linspace(0,2);
mark = {'*r','.k','Og','dc','sm'} ;
T = [0 1 2 3 4] ;
for i = 1:length(T)
t = T(i) ;
n = 2;
Cn = 32;
Dn = 0;
u2 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 4;
Cn = 32;
Dn = 0;
u4 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 5;
Cn = 32;
Dn = 0;
u5 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 6;
Cn = 32;
Dn = 0;
u6 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
n = 12;
Cn = 32;
Dn = 0;
u12 = (sin((n*pi*x)/2))*(Cn*cos(5*n*pi*t)+Dn*sin(5*n*pi*t));
u = u2 + u4 + u5 + u6 + u12 ;
plot(x,u,mark{i})
hold on
grid on
legend('0', '1', '2', '3', '4')
title('u(x,t)')
xlabel('x')
ylabel('u(x,t)')
end

Massimo Zanetti
Massimo Zanetti el 17 de Oct. de 2016
Editada: Massimo Zanetti el 17 de Oct. de 2016
You just see the last two ('3' and '4') because the values are the same, so curve are superimposed and you just see the last one which is printed. A comment about your code, put legend and labels outside the for loop:
for t = [0 1 2 3 4]
%...... your code
plot(x,u)
hold on
end
grid on
legend('0', '1', '2', '3', '4')
title('u(x,t)')
xlabel('x')
ylabel('u(x,t)')
hold off
and add hold off

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by