add two functions and plot it

조회 수: 6 (최근 30일)
clowen
clowen 2016년 3월 3일
답변: Image Analyst 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
  댓글 수: 1
Image Analyst
Image Analyst 2016년 3월 3일
Now, what values of t do you want to plot over?

댓글을 달려면 로그인하십시오.

답변 (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