MATLAB Answers

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 view (last 30 days)
Derek Paul
Derek Paul on 12 Mar 2017
Answered: Star Strider on 12 Mar 2017
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

Sign in to comment.

Answers (1)

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

Sign in to comment.

Sign in to answer this question.