Use of eig(A) for eigenvectors
Hi, I try to call the eigenvectors of the respective eigenvalue, but that part in the code gives an error:
"Unrecognize function or variable ‘eigvecs_theta’
I tried eig and eigvec instead of eigvecs_theta, but nothing works. What did I miss here? Thanks
% Discretization parameters
theta_min = 0;
theta_max = pi;
M = 100; % Number of grid points
theta = linspace(theta_min, theta_max, M);
dtheta = theta(2) – theta(1);
% Initialize the Theta(theta) vector
Theta = zeros(M, 1);
% Set up the finite difference matrix
B = zeros(M, M);
for j = 3:M-2
B(j, j-2) = -1 / (2 * dtheta^3);
B(j, j-1) = 2 / (dtheta^3);
B(j, j) = -2 / (dtheta^3) + l * (l + 1);
B(j, j+1) = 2 / (dtheta^3);
B(j, j+2) = -1 / (2 * dtheta^3);
end
% Apply boundary conditions (example: Theta(0) = 0 and Theta(pi) = 0)
B(1,1) = 1;
B(M,M) = 1;
% Solve the eigenvalue problem
[~, D_theta] = eig(B);
% The eigenvalues are the diagonal elements of D_theta
eigenvalues_theta = diag(D_theta);
% The solution Theta(theta) corresponds to the eigenvector with the desired eigenvalue
Theta = eig(:, idx);
% Plot the solution
plot(theta, Theta);
xlabel(‘theta’);
ylabel(‘Theta(theta)’);
title(‘Angular Wavefunction’);
endHi, I try to call the eigenvectors of the respective eigenvalue, but that part in the code gives an error:
"Unrecognize function or variable ‘eigvecs_theta’
I tried eig and eigvec instead of eigvecs_theta, but nothing works. What did I miss here? Thanks
% Discretization parameters
theta_min = 0;
theta_max = pi;
M = 100; % Number of grid points
theta = linspace(theta_min, theta_max, M);
dtheta = theta(2) – theta(1);
% Initialize the Theta(theta) vector
Theta = zeros(M, 1);
% Set up the finite difference matrix
B = zeros(M, M);
for j = 3:M-2
B(j, j-2) = -1 / (2 * dtheta^3);
B(j, j-1) = 2 / (dtheta^3);
B(j, j) = -2 / (dtheta^3) + l * (l + 1);
B(j, j+1) = 2 / (dtheta^3);
B(j, j+2) = -1 / (2 * dtheta^3);
end
% Apply boundary conditions (example: Theta(0) = 0 and Theta(pi) = 0)
B(1,1) = 1;
B(M,M) = 1;
% Solve the eigenvalue problem
[~, D_theta] = eig(B);
% The eigenvalues are the diagonal elements of D_theta
eigenvalues_theta = diag(D_theta);
% The solution Theta(theta) corresponds to the eigenvector with the desired eigenvalue
Theta = eig(:, idx);
% Plot the solution
plot(theta, Theta);
xlabel(‘theta’);
ylabel(‘Theta(theta)’);
title(‘Angular Wavefunction’);
end Hi, I try to call the eigenvectors of the respective eigenvalue, but that part in the code gives an error:
"Unrecognize function or variable ‘eigvecs_theta’
I tried eig and eigvec instead of eigvecs_theta, but nothing works. What did I miss here? Thanks
% Discretization parameters
theta_min = 0;
theta_max = pi;
M = 100; % Number of grid points
theta = linspace(theta_min, theta_max, M);
dtheta = theta(2) – theta(1);
% Initialize the Theta(theta) vector
Theta = zeros(M, 1);
% Set up the finite difference matrix
B = zeros(M, M);
for j = 3:M-2
B(j, j-2) = -1 / (2 * dtheta^3);
B(j, j-1) = 2 / (dtheta^3);
B(j, j) = -2 / (dtheta^3) + l * (l + 1);
B(j, j+1) = 2 / (dtheta^3);
B(j, j+2) = -1 / (2 * dtheta^3);
end
% Apply boundary conditions (example: Theta(0) = 0 and Theta(pi) = 0)
B(1,1) = 1;
B(M,M) = 1;
% Solve the eigenvalue problem
[~, D_theta] = eig(B);
% The eigenvalues are the diagonal elements of D_theta
eigenvalues_theta = diag(D_theta);
% The solution Theta(theta) corresponds to the eigenvector with the desired eigenvalue
Theta = eig(:, idx);
% Plot the solution
plot(theta, Theta);
xlabel(‘theta’);
ylabel(‘Theta(theta)’);
title(‘Angular Wavefunction’);
end eigenvalues, eigenvectors MATLAB Answers — New Questions