add two functions and plot it

6 次查看(过去 30 天)
clowen
clowen 2016-3-3
my program is
w=2*pi*1.0E+5;
s1=@(t) cos(t/2).*cos(w*t) .*((0 <= t) & (t <= pi));
s12=@(t) sin(t/2).*cos(w*t) .*((0 <= t) & (t<= pi));
z=s1+s12;
plot(t,z);
i am able to add s1 and s12,
i want to plot z with respect to t which is sum of above functions

回答(2 个)

Image Analyst
Image Analyst 2016-3-3
Try this:
w=2*pi*1.0E+5;
s1=@(t) cos(t/2).*cos(w*t) .*((0 <= t) & (t <= pi));
s12=@(t) sin(t/2).*cos(w*t) .*((0 <= t) & (t<= pi));
% Plot 500 points between -.2 and 4.
t = linspace(-.2, 4, 500);
z = s1(t) + s12(t);
plot(t,z, 'b*-', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', 12);
ylabel('z', 'FontSize', 12);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')

Star Strider
Star Strider 2016-3-3
Since ‘s1’ and ‘s12’ are functions, you have to call them with an argument:
z=s1(t)+s12(t);
That should work, although you have to define ‘t’ first.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by