Warning: Matrix is singular to working precision in one line
    10 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
The code seems working perfectly fine but one line it gives an error and does not produce a graph as it should be, could someone explain the error in line 54
% 2-D Source Panel Method
% Reads panel points from a text file and calculates flow around the body.
% Clear workspace and command window
clear;
clc;
% Read panel points from a text file
filename = 'panel_points.txt';
panel_points = load(filename);
% Number of panels
N = size(panel_points, 1) - 1;
% Panel coordinates
x = panel_points(:, 1);
y = panel_points(:, 2);
% Prompt user for flow conditions
U_inf = input('Enter the free stream velocity (U_inf): ');
alpha = input('Enter the angle of attack (alpha in degrees): ');
alpha = deg2rad(alpha);
% Initialize matrices
A = zeros(N+1, N+1);
RHS = zeros(N+1, 1);
% Calculate panel lengths and angles
for i = 1:N
    x_mid(i) = 0.5 * (x(i) + x(i+1));
    y_mid(i) = 0.5 * (y(i) + y(i+1));
    s(i) = sqrt((x(i+1) - x(i))^2 + (y(i+1) - y(i))^2);
    theta(i) = atan2(y(i+1) - y(i), x(i+1) - x(i));
end
% Populate influence coefficient matrix
for i = 1:N
    for j = 1:N
        if i == j
            A(i,j) = 0.5;
        else
            A(i,j) = (1 / (2 * pi)) * log(sqrt((x_mid(i) - x(j))^2 + (y_mid(i) - y(j))^2) / sqrt((x_mid(i) - x(j+1))^2 + (y_mid(i) - y(j+1))^2));
        end
    end
    RHS(i) = -U_inf * cos(theta(i) - alpha);
end
% Apply Kutta condition
A(N+1,1) = 1;
A(N+1,N) = -1;
RHS(N+1) = 0;
% Solve for source strengths
LINE54 sigma = A \ RHS;
% Calculate tangential velocity and pressure coefficient
for i = 1:N
    V_t(i) = U_inf * sin(theta(i) - alpha) + sigma(i) - sigma(i+1);
    Cp(i) = 1 - (V_t(i) / U_inf)^2;
end
% Plotting the pressure coefficient distribution
figure;
plot(x_mid, Cp, '-o');
xlabel('x');
ylabel('C_p');
title('Pressure Coefficient Distribution');
set(gca, 'YDir', 'reverse');
grid on;
disp('Computation complete. Pressure coefficient distribution plotted.');
Enter the free stream velocity (U_inf): 30
Enter the angle of attack (alpha in degrees): 0
54  sigma = A \ RHS;
Warning: Matrix is singular to working precision. 
> In untitled (line 54)
 this is what I got and a blank graph
1 comentario
Respuestas (1)
  Matt Butts
      
 el 15 de Mayo de 2024
        When the matrix is singular, the output of line 54 is an array of NaN values. Thus by the time you get to your plot, you have a bunch of NaNs which show up as blank since they don't contain any real values.
Address the issue with your matrix being singular and you should get a plot.
0 comentarios
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


