add two functions and plot it

6 visualizzazioni (ultimi 30 giorni)
clowen
clowen il 3 Mar 2016
Risposto: Image Analyst il 3 Mar 2016
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

Risposte (2)

Image Analyst
Image Analyst il 3 Mar 2016
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 il 3 Mar 2016
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.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by