Please help. why is this not graph not working. I'm trying to print the graph of y'' + y' + y = 0 and y'' + y' + y = cos(x)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
x = linspace(0,10,100)
y = exp(-x/2)*cos((3^(1/2)*x)/2) + exp(-x/2)*sin((3^(1/2)*x)/2)
y1 = exp(-x/2)*cos((3^(1/2)*x)/2) + exp(-x/2)*sin((3^(1/2)*x)/2) + sin(x)
plot(x, y, 'o', 'MarkerEdgeColor', 'k', ...
'MarkerFaceColor', 'g', ...
'MarkerSize', 4)
hold on
plot(x, y1)
title('exp(-x/2)*cos((3^(1/2)*x)/2) + exp(-x/2)*sin((3^(1/2)*x)/2) + sin(x)')
legend('homogeneous','inhomogeneous')
xlabel('x')
ylabel('y')
0 comentarios
Respuestas (1)
Star Strider
el 12 de Mzo. de 2017
You need to vectorise your equations.
Also in the plot title, you need to enclose the values in curly brackets ‘{}’ that you want included in special operations, here exponents.
This works:
x = linspace(0,10,100);
y = exp(-x/2).*cos((3^(1/2).*x)/2) + exp(-x/2).*sin((3^(1/2)*x)/2)
y1 = exp(-x/2).*cos((3^(1/2)*x)/2) + exp(-x/2).*sin((3^(1/2)*x)/2) + sin(x)
plot(x, y, 'o', 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'g', 'MarkerSize', 4)
hold on
plot(x, y1)
title('exp(-x/2)*cos((3^{1/2}*x)/2) + exp(-x/2)*sin((3^{1/2}*x)/2) + sin(x)')
legend('homogeneous','inhomogeneous')
xlabel('x')
ylabel('y')
For more information on vectorising your code, see the documentation for Array vs. Matrix Operations.
0 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!