How to code equation
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cesar Cardenas
le 24 Jan 2023
Réponse apportée : Nisar
le 15 Mai 2024
Hello, just wondering if this equation could be coded like this:
Any feedback will be greatly appreciated. Thanks
m = 10e-3
a = 0.05
c = 0.1
x(t) = m/a e^-(c/a)t
0 commentaires
Réponse acceptée
Sulaymon Eshkabilov
le 24 Jan 2023
A couple of small errors have been corrected:
m = 10e-3;
a = 0.05;
c = 0.1;
x = @(t)(m/a)*exp(-(c/a)*t);
t = linspace(0,1.3);
plot(t, x(t))
xlabel('t')
ylabel('x(t)')
grid on
1 commentaire
Plus de réponses (3)
Sulaymon Eshkabilov
le 27 Jan 2023
Put both functions in plot() command or use hold on:
m = 10e-3;
a = 0.05;
c = 0.1;
x1 = @(t)(m/a)*exp(-(c/a)*t);
x2 = @(t)(m/a)*1-exp(-(a/m)*t);
t = linspace(0,1.5);
plot(t, x1(t), 'r-', t, x2(t), 'b-.', 'linewidth', 2)
xlabel('$t$', 'Interpreter', 'latex')
ylabel('$x(t)$', 'Interpreter', 'latex')
legend('$x_1(t)$', '$x_2(t)$','Interpreter', 'latex', 'location', 'SE')
grid on
%% Alternative solution:
m = 10e-3;
a = 0.05;
c = 0.1;
x1 = @(t)(m/a)*exp(-(c/a)*t);
x2 = @(t)(m/a)*1-exp(-(a/m)*t);
figure
fplot(x1, [0, 1.5], 'r-', 'linewidth', 2)
hold on
fplot(x2, [0, 1.5], 'b-.', 'linewidth', 2)
xlabel('$t$', 'Interpreter', 'latex')
ylabel('$x(t)$', 'Interpreter', 'latex')
legend('$x_1(t)$', '$x_2(t)$','Interpreter', 'latex', 'location', 'SE')
grid on
Nisar
le 15 Mai 2024
clc;
T=10;
Fs=1;
t=-2*T:1/(10*Fs):2*T;
rect_pulse_fft = fftshift(fft(rect_pulse));
L=length(t);
f=Fs*(-L/2:(L/2-1))/L;
rect_pulse_fft=fftshift(fft(rect_pulse));
subplot(2,1,1);
plot(t,rect_pulse);
xlabel('Time(s)');
ylabel('Amplitude');
title('time Domain Representation of Rectangular pulse');
subplot(2,1,2);
plot(f,abs(rect_pulse_fft));
xlabel('frequency(Hz)');
ylabel('Magnitude');
title('frequemcy domain representation of rectangular pulse');
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!