how can i compute Aij?

3 visualizaciones (últimos 30 días)
Gurpreet
Gurpreet el 12 de Feb. de 2024
Comentada: Les Beckham el 12 de Feb. de 2024
this is the question i have. my instructor is not really helpful with this and i need help.
  4 comentarios
Torsten
Torsten el 12 de Feb. de 2024
Works for me (at least up to k=10) (see above).
Gurpreet
Gurpreet el 12 de Feb. de 2024
Movida: Torsten el 12 de Feb. de 2024
this is what im getting:
In untitled2 (line 32)
condition_numbers_A(k) = cond(A);
In untitled2 (line 33)
condition_numbers_B(k) = cond(B);
i ran it four times and then came to answers :(

Iniciar sesión para comentar.

Respuesta aceptada

Les Beckham
Les Beckham el 12 de Feb. de 2024
It appears to work. I ran it for only 2 values of k as it was timing out here in Answers when running with 20 values of k.
What do you mean "it doesn't run"? What are you seeing? Are you getting an error message? If so, cut and paste it here (all of the red or orange text in the command window.
% Function to generate n x n matrix with pseudo-random entries between 0 and 1
generateMatrix = @(n) rand(n);
% Parameters
delta_n = 200;
k_values = 1:2; % was 1:20
% Initialize arrays to store condition numbers
condition_numbers_A = zeros(size(k_values));
condition_numbers_B = zeros(size(k_values));
condition_numbers_C = zeros(size(k_values));
condition_numbers_D = zeros(size(k_values));
% Loop over k values
for k = k_values
n = k * delta_n;
% Generate matrix A
A = generateMatrix(n);
% Generate matrices B, C, D based on the rules
B = A;
C = A;
D = A;
% Modify elements based on rules
for i = 1:n
B(i, i) = 10;
C(i, i) = 20;
D(i, i) = 100;
end
% Calculate condition numbers
condition_numbers_A(k) = cond(A);
condition_numbers_B(k) = cond(B);
condition_numbers_C(k) = cond(C);
condition_numbers_D(k) = cond(D);
end
% Plot results using semilogy
figure;
semilogy(k_values * delta_n, condition_numbers_A, 'b', 'LineWidth', 2, 'DisplayName', 'A');
hold on;
semilogy(k_values * delta_n, condition_numbers_B, 'g', 'LineWidth', 2, 'DisplayName', 'B');
semilogy(k_values * delta_n, condition_numbers_C, 'r', 'LineWidth', 2, 'DisplayName', 'C');
semilogy(k_values * delta_n, condition_numbers_D, 'm', 'LineWidth', 2, 'DisplayName', 'D');
xlabel('Matrix Size (nk)');
ylabel('Condition Number (log scale)');
title('Condition Numbers of Matrices A, B, C, D');
legend('Location', 'Best');
grid on;
hold off;
  2 comentarios
Gurpreet
Gurpreet el 12 de Feb. de 2024
i tried on a different computer and it ran!!!
thank you all for your help :)
Les Beckham
Les Beckham el 12 de Feb. de 2024
You are quite welcome.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by