Linsolve outputting funky matrices

This thing has been bugging me for a few days, and i can't figure out what is wrong. I know its something simple, but I just can't get it to work. This code is meant to decrease the thickness of an airfoil from given airfoil coordinates passed to the function. It should work by taking two points, drawing a line between them, and then creating a parallel line. It does this for the next two points, and then at the intercept of these two lines, it creates a new point of the resized airfoil. The problem I am having is linsolve seems to be outputting a 2x2 matrix, although it should be a 1x2, since these are linear equations and they should not have more than one solution.
here is the main code:
clc
clear all;
scale = 0.95;
area_Sum = 0;
ybarA_Sum = 0;
area_Mom = 0;
thickness = 1; %airfoil thickness in mm
fid = fopen('NACAM22.txt');
air_Coord = textscan(fid, '%f%f');
x_c = cell2mat(air_Coord(1,1));
y_c = cell2mat(air_Coord(1,2));
%create inner airfoil shape
new_airfoil = shell(x_c, y_c, 0.5);
and here is the function:
function [inner_Airfoil] = shell(outer_Airfoilx, outer_Airfoily, thickness)
[iter, null] = size(outer_Airfoilx);
for i = 1:(iter + 1)
if i == 1
index_Prev = iter;
else
index_Prev = i-1;
end
if i == (iter + 1)
index = 1;
else
index = i;
end
pt1x = outer_Airfoilx(index_Prev);
pt1y = outer_Airfoily(index_Prev);
pt2x = outer_Airfoilx(index);
pt2y = outer_Airfoily(index);
ABx = pt2x - pt1x;
ABy = pt2y - pt1y;
if i<17 || i == iter+1
normx = ABy;
normy = -ABx;
else
normx = -ABy;
normy = ABx;
end
o_Mag = sqrt((ABx^2)+(ABy^2));
push_Vectx = normx*(thickness/o_Mag);
push_Vecty = normy*(thickness/o_Mag);
new_pt1x = pt1x + push_Vectx;
new_pt1y = pt1y + push_Vecty;
new_pt2x = pt2x + push_Vectx;
new_pt2y = pt2y + push_Vecty;
if i>1 && i<=iter
m = ((new_pt2y-new_pt1y)/(new_pt2x-new_pt1x));
yint = new_pt1y - (m*pt1x);
syms y x
eqn1 = y == (m*x) + yint;
end
if i>2
[A, B] = equationsToMatrix([eqn1, eqn2], [x, y]);
[solx, soly] = (linsolve(A, B))
inner_Airfoil(1, (i-1)) = solx;
inner_Airfoil(2, (i-1)) = soly;
end
%on second iteration solve with a vertical intercept
if i==2 | i==(iter+1)
solx = outer_Airfoilx(1) - thickness;
soly = linsolve(eqn1, solx);
inner_Airfoil(1, (i-1)) = solx;
inner_Airfoil(2, (i-1)) = soly;
end
if i>1
eqn2 = eqn1;
end
end
end

Risposte (0)

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by