Numerical integration of a subfunction

조회 수: 3 (최근 30일)
Nimrod Daniel
Nimrod Daniel 2014년 1월 3일
편집: Patrik Ek 2014년 1월 7일
Hello,
I'm trying to do a numerical integration of a function (which is defined in another function), and I'm getting some errors, what I get wrong here ? Thanks. Nimrod Daniel.
function [C_l]=lift_coefficient(a,b)
% the function calculates the lift coeeficient of a wing
if nargin<2 %default input
%wing parameters:
h=1.4;
t=2.1;
chord=8.6;
%defining camber-line paramets:
a=h/t^2; % a before normalization
a=a/chord;
b=(1-2*t)/(t^2); % b before normalization
b=b/chord;
end;
C_l=quad(@camber,x,-0.9999,0.9999) %numerical integration of f
function f=camber(x)
y_c=a/2*(1-x.^2)/(2+b*(x+1)); %camber-line function
dyc_dx=diff(y_c,x,1)% first derivative of y_c
f=-2*sqrt((1+x)/(1-x))*dyc_dx % integrand
end
end
  댓글 수: 1
Nimrod Daniel
Nimrod Daniel 2014년 1월 4일
I solved the problem in another approach. I had the points on the function, so I implemented the trapezoidal rule, though I'd like to know what I should have fixed in the code (more cleaner now).
function [C_l]=lift_coefficient(a,b) % the function calculates the lift coeeficient of a wing's cross-sections %inputs - vectors a and b are defining the cross-sectional parameters
if nargin<2 a=[0.3 0.5 0.7]; b=[-0.7 -0.8 -0.9]; end;
C_l=quad(@camber,-0.9999,0.9999) %numerical integration of f
function f=camber(x) y_c=a./2*(1-x.^2)./(2+b.*(x+1)); %camber-line function dyc_dx=diff(y_c,x)% first derivative of y_c f=-2*sqrt((1+x)./(1-x))*dyc_dx % integrand end
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Patrik Ek
Patrik Ek 2014년 1월 7일
편집: Patrik Ek 2014년 1월 7일
Where does the error occur? Also I see a number of errors, that you have done. Firstly, you need to use points before all the operators that may want to do a pointwise multiplication of two vectors. This since quad will recursively input a vector to the function.
Secondly, matlab uses simpsons quadraure in quad, it is not a symbolic operation. This means that the variable x is not necessary in the function call of quad, which is why the syntax is only
quad(@fun,a,b) You can check this up on the internet.
Good luck and please accept the answer if this solves the issue! BR/ Patrik

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by