I want to plot x(t) = cos(200*pi*t*u(t)) and define u(t) seprately and then plot x(-t),x(t/3)
i wrote this
x = @(t) cos(200*pi*t*u(t));
t = linspace(-1, 1);
figure(1)
plot(t, x(t))
grid
function y = u(x)
y=0;
if x>=0
y=1;
end
end

 Réponse acceptée

Star Strider
Star Strider le 19 Oct 2019

0 votes

This should get you started:
u = @(t) t>=0;
x = @(t,u) cos(200*pi*t.*u(t));
t = linspace(-1, 1);
figure(1)
plot(t, x(t,u))
grid
Extending that:
u = @(t) t>=0;
x = @(t,u) cos(200*pi*t.*u(t));
t = linspace(-1, 1);
figure(1)
plot(t, x(t,u))
hold on
plot(t, x(-t,u))
plot(t, x(t/3,u))
hold off
grid
Experiment to get different results.

8 commentaires

Mohammadreza kalantari
Mohammadreza kalantari le 19 Oct 2019
thanks a lot
whats about 1/x(t,u) & x(1/t,u)
I think the eror is devided by zero
how can i solve it?
Star Strider
Star Strider le 19 Oct 2019
My pleasure.
Add: 1E-14 (or some similar small value) to whatever is in the denominator. That will still result in a very large number, however not Inf or NaN.
Note that in those instances, you need to use element-wise division, ./. See the documentation section on Array vs. Matrix Operations for a fulll discussion.
Mohammadreza kalantari
Mohammadreza kalantari le 26 Oct 2019
ok
now i want to plot A*exp(j*2*pi*t)
which A is a constant variable and j is an imaginary unit
Try this:
A = 42; % Universal Answer (HHGTTG)
y = @(t) A*exp(1j*2*pi*t)
t = linspace(-1, 1);
figure
plot(t, real(y(t)),'-b', t, imag(y(t)), '--')
grid
legend('\Re', '\Im')
Experiment to get the result you want.
Mohammadreza kalantari
Mohammadreza kalantari le 31 Oct 2019
Modifié(e) : Mohammadreza kalantari le 31 Oct 2019
Thanks.
i want to stem y[n]=y[n-2]+x[n]+2x[n-1] which is recursive and y[0]=1,y[-1]=5, x[n]=(1.5.^n).*u[n]
delta = @(d) d==0;
and also stem conv(y,delta)
can you help me?
Star Strider
Star Strider le 31 Oct 2019
This should be posted as a new Question.
Mohammadreza kalantari
Mohammadreza kalantari le 31 Oct 2019
Modifié(e) : Mohammadreza kalantari le 31 Oct 2019
I asked in that way too.
Star Strider
Star Strider le 31 Oct 2019
I will delete this Comment in a few minutes, then.

Connectez-vous pour commenter.

Plus de réponses (1)

Asif
Asif le 4 Avr 2024

0 votes

t=0:0.01:5; %Time from 0 to 5 seconds with a step size of 0.01 seconds
%Define the continous signal ( for example, a sinusoidal signal)
% Frequency=2; %Frequency of the sinusoid in HZ
Amplitude=1; % Amplitude of the sinusoid
Phase = pi/4; %phase of the sinusoid ( in radians)
signal = Amplitude*sin(2*pi*Frequency*t+Phase);
% plot the continuous signal
plot(t, signal,'b','Linewidth',6);
xlabel('xTime(s)X');
ylabel('Ampltitude');
title('Continuous Sinusoidal signal');
grid on

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by