add two functions and plot it

18 visualizaciones (últimos 30 días)
clowen
clowen el 3 de Mzo. de 2016
Respondida: Image Analyst el 3 de Mzo. de 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
  1 comentario
Image Analyst
Image Analyst el 3 de Mzo. de 2016
Now, what values of t do you want to plot over?

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 3 de Mzo. de 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 el 3 de Mzo. de 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.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by