Add 2 trigonometric functions, with conditions
1 次查看(过去 30 天)
显示 更早的评论
Greeting to all,
I am trying to add graphically 2 trigonometric functions:
- f(x)=a*sin(k*x), graphicaly displayed only for positive value (≥0)
- g(x)=b*cos(m*x+d), graphicaly displayed only for negative value (≤0)
Thanks
0 个评论
采纳的回答
Sam Chak
2022-9-22
编辑:Sam Chak
2022-9-26
Are you trying to plot the addition of two sinusoidal functions, even when there are discontinuities?
x = linspace(-1, 1, 2001);
a = 1;
b = 1;
k = pi;
m = pi;
d = 0;
f = sin(k*x);
g = cos(m*x + d);
fp = f.*(f > 0);
gn = g.*(g < 0);
% Plot
subplot(221)
plot(x, f), grid on, ylim([-1.5 1.5]), title({'$f(x)$'}, 'interpreter', 'latex')
subplot(223)
plot(x, g), grid on, ylim([-1.5 1.5]), title({'$g(x)$'}, 'interpreter', 'latex')
xlabel({'$x$'}, 'interpreter', 'latex')
subplot(222)
plot(x, fp, x, gn), grid on, ylim([-1.5 1.5]), title({'$f^{+}(x)$ and $g^{-}(x)$'}, 'interpreter', 'latex')
legend({'$f^{+}(x)$', '$g^{-}(x)$'}, 'interpreter', 'latex', 'location', 'northwest')
subplot(224)
plot(x, fp + gn), grid on, ylim([-1.5 1.5]), title({'$f^{+}(x) + g^{-}(x)$'}, 'interpreter', 'latex')
xlabel({'$x$'}, 'interpreter', 'latex')
0 个评论
更多回答(2 个)
Panagiotis Arvanitis
2022-9-26
1 个评论
Sam Chak
2022-9-26
I have fixed the code in my Answer.
Please check if that that is the signal desired.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!