# Help in optimizing code: numerical methods

1. Sep 22, 2004

### enigma

Staff Emeritus
Hi all,

Hopefully someone can point my nose in the right direction.

I have some MATLAB code (fairly long) attached in a zip file. It is working. I get results. It's just not working very well, and I'm wondering if someone has any ideas to get better results.

Usage (both files need to be in MATLAB's working path):

>>sensorgeom(NACA,points);

or

>>sensorgeom(NACA)

NACA is a 4 digit number which designates the shape of an airfoil using the standard NACA geometry code found here. Try 2412, 0012, 4614, etc.
points is the number of divisions the airfoil geometry is broken up to. Default is 500. Lower decreases precision but increases program stability.

What I need to extract (among other things) is the slope of the airfoil's surface with respect to chord. This would be trivial, except the algorithm to generate the shape results in a non-differentiable equation. What I do to get around this is to use MATLAB's 'polyfit' equation to apply a polynomial approximation to the curve. This is where my optimization problem lies.

The curvature of the airfoil near the leading edge is really large, particularly with highly cambered airfoils (5xxx+) or highly thick airfoils (xx16+). This results in the code needing extremely large polynomials to fit within the tolerances I would like (~.1%-.5% of the chord length). If I try to do a run with large values for camber or thickness and keeping the number of points greater than 100, the routine hangs as it attempts to polyfit within the error bounds up to 100+ degree polynomials. You can try this by commenting out lines 35-41, which I put in to ensure it would work for a preliminary presentation to my advisor.

By lowering the numbers of points, the geometry of the sensors I'm placing on the wing which are weighted like sin(dy/dx) (right 2 plots of figure 2) become really choppy, with rather large and sporadic jumps in slope. Since I'm going to need to cut the sensors precisely, that's not going to be a good solution.

Another thing I tried was to break up the curvature into four seperate sections: One polynomial for the half prior to the max/min point on the top/bottom of the wing, and one for the half after the max/min point. This ended up being even worse because the polynomials it picked were curving away (in opposite directions) from the fit to the curve at the max/min point resulting in a 10+ degree difference in the curvature as it jumped from leading half to trailing half polynomial. I still have the code which does this and can post it if someone wants to take a look at it.

Optimally, I'd like a smooth distribution (large numbers of points). I absolutely cannot have ten degree jumps in slope. I cannot see a way to do both.

Basically, I'm making a shot in the dark and hoping for the best here. Am I overlooking a simple solution to this problem? Has anyone found a solution to a similar problem? Anyone have any advice on how to improve this, even if it'll take some serious coding?

Hopefully, I've described the problem adequately that those without MATLAB can understand the problem.

Overall Algorithm:
1) Generate X & Y (chord and thickness) coordinates for airfoil based on NACA designation
2) Apply curve-fits to the surfaces.
2A) Ensure convergence is within tolerances else increase degree of polynomial and repeat.
3) Find derivatives of the polynomial curve-fits
4) Generate sensor geometry from slopes

Thanks!

File size:
2.9 KB
Views:
76