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 Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by