Fixing Error using plot Invalid first data argument - new to matlab
Show older comments
I am trying to plot the function y=cos(x)*sin(x^2) and its derivative from -pi to pi. Here is my code. Why do I keep getting errors? At first I tried linespace but that didn't work. What do I do? I am new to matlab.
x=-pi:100:pi;
y=cos(x)*sin(x^2);
dy=2*x*cos(x^2)*(cos(x))-sin(x^2)*sin(x);
clf
hold on
plot(x,y, 'r', 'LineWidth', 3);
xlabel('x');
ylabel('y');
hold on
grid on
plot(x,dy, 'b', 'o--', 'LineWidth', 1);
title(['Graph of y=sin(x^2)cos(x) and y' by Jay Gersten'])
legend('cos(x)*sin(x.^2)','2*x*cos(x.^2)*cos(x)-sin(x.^2)*sin(x)')
dbstop if error
Accepted Answer
More Answers (0)
Categories
Find more on Annotations 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!