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)
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')

Respuestas (1)

Star Strider
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.

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!

Translated by