Warning: Matrix is singular to working precision in one line
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 graphThe 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 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 graph, singular, working, precision, warning MATLAB Answers — New Questions