Resolver en Matlab:
Código:
% Definir los coeficientes para los tres casos
coefficients_k3 = [1 4 3];
coefficients_k4 = [1 4 4];
coefficients_k40 = [1 4 40];
% Encontrar las raíces para k = 3
roots_k3 = roots(coefficients_k3);
disp('Para k = 3, las raíces son:');
disp(roots_k3.');
% Encontrar las raíces para k = 4
roots_k4 = roots(coefficients_k4);
disp('Para k = 4, las raíces son:');
disp(roots_k4.');
% Encontrar las raíces para k = 40
roots_k40 = roots(coefficients_k40);
disp('Para k = 40, las raíces son:');
disp(roots_k40.');
resultado:
Para k = 3, las raíces son:
-3 -1
Para k = 4, las raíces son:
-2 -2
Para k = 40, las raíces son:
-2.0000 + 6.0000i -2.0000 - 6.0000i
Segundo ejercicio
Código:
% Define symbolic variables
syms y(t)
% Define the differential equation and initial conditions
Dy = diff(y, t);
D2y = diff(y, t, 2);
% Case (a) k = 3
k = 3;
eqn = D2y + 4*Dy + k*y == 0;
cond1 = y(0) == 3;
cond2 = Dy(0) == -7;
y_0_k3 = dsolve(eqn, cond1, cond2);
disp('Para k = 3, la respuesta a entrada cero es:');
disp(y_0_k3);
% Case (b) k = 4
k = 4;
eqn = D2y + 4*Dy + k*y == 0;
cond1 = y(0) == 3;
cond2 = Dy(0) == -7;
y_0_k4 = dsolve(eqn, cond1, cond2);
disp('Para k = 4, la respuesta a entrada cero es:');
disp(y_0_k4);
% Case (c) k = 40
k = 40;
eqn = D2y + 4*Dy + k*y == 0;
cond1 = y(0) == 3;
cond2 = Dy(0) == -7;
y_0_k40 = dsolve(eqn, cond1, cond2);
disp('Para k = 40, la respuesta a entrada cero es:');
disp(y_0_k40);
respuesta:
Para k = 3, la respuesta a entrada cero es:
exp(-t) + 2*exp(-3*t)
Para k = 4, la respuesta a entrada cero es:
-exp(-2*t)*(t - 3)
Para k = 40, la respuesta a entrada cero es:
(exp(-2*t)*(18*cos(6*t) - sin(6*t)))/6
Graficas:
% Definir el rango de t
t = 0:0.01:5; % Desde 0 hasta 5 con incrementos de 0.01
% Definir la función x(t) = e^(-t)
x_t = exp(-t);
% Crear la gráfica
figure;
plot(t, x_t, 'LineWidth', 2); % Gráfica con línea de grosor 2
xlabel('t'); % Etiqueta del eje x
ylabel('x(t)'); % Etiqueta del eje y
title('x(t) = e^{-t}'); % Título del gráfico
grid on; % Mostrar cuadrícula
% Ajustar los límites de los ejes
xlim([0 5]); % Limitar el eje x de 0 a 5
ylim([0 1]); % Limitar el eje y de 0 a 1
% Añadir texto en la gráfica
text(1, exp(-1), 'e^{-t}', 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');
% Añadir anotación de punto inicial
hold on;
plot(0, 1, 'ko', 'MarkerFaceColor', 'k'); % Punto en t=0 y x(t)=1
text(0, 1, ' 1', 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'left');
hold off;
grafica 2:
Código:
% Define the time variable t from 0 to 2 with a small step size
t = linspace(0, 2, 1000);
% Define the function h(t) = e^(-2t)
h = exp(-2 * t);
% Create the plot
figure;
plot(t, h, 'LineWidth', 1.5);
% Add labels and title
xlabel('t');
ylabel('h(t)');
title('Plot of h(t) = e^{-2t}');
grid on;
Grafica 3:
% Define the time variable t from 0 to 2 with a small step size
t = linspace(0, 2, 1000);
% Define the functions
y = exp(-t) - exp(-2 * t);
f1 = exp(-t);
f2 = exp(-2 * t);
% Create the plot
figure;
plot(t, y, 'k', 'LineWidth', 2); % y(t) with a solid black line
hold on;
plot(t, f1, 'k--', 'LineWidth', 1); % e^{-t} with a dashed black line
plot(t, f2, 'k--', 'LineWidth', 1); % e^{-2t} with a dashed black line
hold off;
% Add labels and title
xlabel('t');
ylabel('y(t)');
title('Plot of y(t) = e^{-t} - e^{-2t}, e^{-t}, and e^{-2t}');
grid on;
% Add annotations for better clarity
text(1, exp(-1), 'e^{-t}', 'HorizontalAlignment', 'left');
text(1, exp(-2), 'e^{-2t}', 'HorizontalAlignment', 'left');
text(0.5, exp(-0.5) - exp(-1), 'e^{-t} - e^{-2t}', 'HorizontalAlignment', 'right');
% Set the axis limits to better match the original graph
xlim([0 2]);
ylim([-1 1]);