[QUOTE=pretend my name is witty]
I understand that it’s coming up with a problem adding them because I’ve ended up with two different sizes of matrices somehow.
But I can’t see how I’ve done it, they should be ok to add together (at least I think).
[/QUOTE]
Your code computes y_c_t by looping
for x_c=0:inc:1
...
end
and yc_c by looping
for i=0:inc:x1
...
end
for i=x1+inc:inc:1
...
end
Obviously this will only work (giving the same sizes to y_c_t and yc_c) if 0 <= x1 <= 1 – otherwise one of the loops will be too large and the other will be empty. This range for x1 is what you want, but when you define maxc_pos (which is later used to set x1) you define it as
maxc_pos=str2num(section_shape(2)).*1;
so x1 will be an integer from 0 to 9 (instead of a value from 0.0, 0.1, …, 0.9, which is what you want for the camber distance in the 4-digit NACA code). This is just a typo. (Note that you don’t need to use the .* and ./ operators when the right-hand operand is a scalar; you could just write
max_cam=str2num(section_shape(1))/100;
for example.)
A more subtle potential problem is that your values for yc_c are only evaluated at the same x positions as those for y_c_t if x1=maxc_pos is divisible by the x spacing inc. In your case it always is, but you might consider modifying your code to work correctly for arbitrary inc.
Finally, I’d like to note that to really use Matlab well, you need to learn to vectorize code. Matlab is an interpreted language. Every time it encounters a line of code when running an M-file it has to parse that line – even within a loop where the line of code is seen many times. For simple expressions, parsing the line may take much longer than actually performing the operations it specifies. It is usually much faster to use Matlab’s vector arithmetic where possible than writing a loop to iterate over each value. For example, rewriting your first loop
for x_c=0:inc:1,
counti=counti+1;
% Thickness distribution equation
y_c_t(counti)=5.*t.*((0.29690.*(x_c.^0.5))-(0.12600.*x_c)-(0.35160.*(x_c^2))+(0.28430.*(x_c.^3))-(0.10150.*(x_c^4)));
end
as
x_c=0:inc:1;
y_c_t=5.*t.*((0.29690.*(x_c.^0.5))-(0.12600.*x_c)-(0.35160.*(x_c.^2))+(0.28430.*(x_c.^3))-(0.10150.*(x_c.^4)));
takes about 1/30 the time on my machine. (I had to change two of your ^ operators to .^ to make this work. Your use of op versus .op is somewhat sporadic; think about which one you want to use.) You can vectorize the calculation of yc_c similarly, using expressions like (x_c <= maxc_pos) and Matlab’s FIND function.