Assignment No 2
Assignment No 2
Assignment No 2
MATLAB code for Velocity Potential (Phi) Value for a rectangular plate
clear all
clc
% Taking user input
prompt = 'The farthest vertex of the rectangle [x y]:'
x3 = input(prompt);
prompt = 'Specify any point outside the rectangle [x y z]'
q = input(prompt);
x1 = [0 0];
x2 = [x3(1) 0];
x4 = [0 x3(2)];
% Displaying the rectangle
rectangle('Position',[0 0 x3(1) x3(2)]);
X = 0:1:x3(1);
Y = 0:1:x3(2);
% User input for unit normal vector components
prompt = 'Specify i component value of the unit normal vector'
nx = input(prompt);
prompt = 'Specify j component value of the unit normal vector'
ny = input(prompt);
prompt = 'Specify k component value of the unit normal vector'
nz = input(prompt);
% Mesh and 1/ri loop
ri = zeros(1,60);
v = zeros(1,60);
m = 1;
I = 0;
for i = X(1) : X(x3(1))
for j = Y(1) : Y(x3(2))
rectangle('Position',[i j 1 1]);
xn = (i+i+1)/2;
Cx(i+1) = xn;
yn = (j+j+1)/2;
Cy(j+1) = yn;
ri(m) = sqrt((q(1)-xn)^2 + (q(2)-yn)^2 + (q(3)^2));
v(m) = 1/ri(m);
I = I + v(m);
m = m + 1;
end
end
% BI values
BIt(1) = I;
m = 1;
for g = 2 : 60
I = I - v(m);
BIt(g) = I;
m = m + 1;
end
BI = reshape(BIt,[60,1]);
display(BI);
% AI values - for all rectangular panels unit normal is 1 in kth direction
AI = zeros(60,60);
for i = 1 : 10
for j = 1 : 6
CX(i,j) = Cx(i);
CY(i,j) = Cy(j);
end
end
CXX = reshape(CX,[60,1]);
CYY = reshape(CY,[60,1]);
CZZ = zeros(60,1);
%Here CZZ = 0
for m = 1 : 60
for n = 1 : 60
if m == n
AI(m,n) = 0.5;
else
AI(m,n) = ((CXX(n)-CXX(m))*nx)+((CYY(n)-CYY(m))*ny)+((CZZ(n)-
CZZ(m))*nz)/(((CXX(n)-CXX(m)).^2)+((CYY(n)-CYY(m)).^2)+((CZZ(n)-CZZ(m)).^2))^1.5;
end
end
end
display(AI);
phi = linsolve(AI,BI);
display(phi);
clear all
clc
% Taking user input
prompt = 'The farthest vertex of the rectangle [x y]:'
x3 = input(prompt);
prompt = 'Specify any point outside the rectangle [x y z]'
q = input(prompt);
x1 = [0 0];
x2 = [x3(1) 0];
x4 = [0 x3(2)];
% Displaying the rectangle
rectangle('Position',[0 0 x3(1) x3(2)]);
X = 0:1:x3(1);
Y = 0:1:x3(2);
% User input for unit normal vector components
prompt = 'Specify i component value of the unit normal vector'
nx = input(prompt);
prompt = 'Specify j component value of the unit normal vector'
ny = input(prompt);
prompt = 'Specify k component value of the unit normal vector'
nz = input(prompt);
% Mesh and 1/ri loop
ri = zeros(1,60);
v = zeros(1,60);
m = 1;
I = 0;
for i = X(1) : X(x3(1))
for j = Y(1) : Y(x3(2))
rectangle('Position',[i j 1 1]);
xn = (i+i+1)/2;
Cx(i+1) = xn;
yn = (j+j+1)/2;
Cy(j+1) = yn;
ri(m) = sqrt((q(1)-xn)^2 + (q(2)-yn)^2 + (q(3)^2));
v(m) = 1/ri(m);
I = I + v(m);
m = m + 1;
end
end
% BI values
BIt(1) = I;
m = 1;
for g = 2 : 60
I = I - v(m);
BIt(g) = I;
m = m + 1;
end
BI = reshape(BIt,[60,1]);
display(BI);
BI = 60×1
0.9971
0.9806
0.9640
0.9475
0.9310
0.9144
0.8979
0.8814
0.8648
0.8482
⋮
AI = 60×60
0.5000 0 0 0 0 0 0 ⋯
0 0.5000 0 0 0 0 0
0 0 0.5000 0 0 0 0
0 0 0 0.5000 0 0 0
0 0 0 0 0.5000 0 0
0 0 0 0 0 0.5000 0
0 0 0 0 0 0 0.5000
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
⋮
phi = linsolve(AI,BI);
display(phi);
phi = 60×1
1.9942
1.9611
1.9281
1.8950
1.8620
1.8289
1.7958
1.7627
1.7296
1.6965
⋮
The following are the Phi values obtained:
phi =
1.9942
1.9611
1.9281
1.8950
1.8620
1.8289
1.7958
1.7627
1.7296
1.6965
1.6634
1.6302
1.5971
1.5639
1.5308
1.4976
1.4644
1.4312
1.3980
1.3648
1.3316
1.2984
1.2652
1.2319
1.1987
1.1655
1.1322
1.0990
1.0657
1.0324
0.9991
0.9659
0.9326
0.8993
0.8660
0.8327
0.7994
0.7662
0.7329
0.6996
0.6662
0.6329
0.5996
0.5663
0.5330
0.4997
0.4664
0.4330
0.3997
0.3664
0.3331
0.2998
0.2665
0.2332
0.1998
0.1666
0.1333
0.1000
0.0666
0.0333