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)
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 12 Mar 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 Comments
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!