please help me for , create a plot of the two functions sin(1.5x) and cos(2x) from 0 to 4pi

11 次查看(过去 30 天)
On the same figure, create a plot of the two functions sin(1.5x) and cos(2x) from 0 to 4pi i will show you what i did but it still telling me that i have an error
x=0:4.*pi;
y1=sind(1.5x);
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
y2=cosd(2x);
plot(x,y1);
hold on;
plot(x,y2);

采纳的回答

Walter Roberson
Walter Roberson 2022-9-24
编辑:Walter Roberson 2022-9-24
y2=cosd(2x);
There are absolutely no places in MATLAB that permit implicit multiplication. If you want to multiply two things you must use .* (or sometimes * ) such as 1.5.*x
  3 个评论
Image Analyst
Image Analyst 2022-9-24
Great, then you probably did this:
x = linspace(0, 4 * pi, 1000);
y1 = sin(1.5 * x);
y2 = cos(2 * x);
% Display graph
plot(x, y1, 'b-', 'LineWidth',2);
hold on;
grid on;
plot(x, y2, 'r-', 'LineWidth',2);
fontSize = 14;
title("Trig functions", 'FontSize',fontSize)
xlabel("x", 'FontSize',fontSize)
ylabel("y", 'FontSize',fontSize)
legend('y1 = sin(1.5 * x)', 'y2 = cos(2 * x)')
so please click the "Accept this answer" link since Walter helped you realize you needed a * between the number and the x.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by