Question about reformulating a difference equation as a matrix equation
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The difference equation and the boundary value are:
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/746124/image.png)
I know how to solve for y(n) with eigen vector to obtain homogeneous solution and particular solution, and solve the coeffeicient using the boundary value. However, I donot know how to reformulate the whole difference equation into a matrix equation. Can anyone help?
0 commentaires
Réponses (1)
MULI
le 22 Mai 2024
Hi William,
I understand that you are asking about the reformulation of difference equation into a matrix equation.
Here I am providing the MATLAB code that solves a specific linear difference equation with given boundary conditions by reformulating the problem into a matrix equation.
% Define the parameters
N = 101; % Number of equations for n=0 to n=100
A = zeros(N, N); % Initialize A matrix
b = -1.35 * (0:N-1)'; % Correctly initialize b vector with -1.35n for n=0 to n=100
% Populate the A matrix based on the difference equation
A(1,1) = 1; % First equation only involves y(0) because y(-1) and y(-2) do not exist
for n = 2:N
A(n, n) = 1; % y(n) coefficient
A(n, n-1) = -10.1; % y(n-1) coefficient
if n > 2
A(n, n-2) = -10.1; % y(n-2) coefficient, valid from n=2 onwards
end
end
% Adjust for boundary conditions
b(N) = 101/6; % Adjust the last value of b for y(100) = 101/6
% Solve the system Ay = b for y
y = A\b;
% Display specific values of y(n)
disp(['y(0) = ', num2str(y(1))]);
disp(['y(50) = ', num2str(y(51))]);
disp(['y(100) = ', num2str(y(101))]);
In summary, the code efficiently translates a linear difference equation with boundary conditions into a solvable matrix equation.
0 commentaires
Voir également
Catégories
En savoir plus sur Discrete Math 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!