Numerical integration of a subfunction

2 vues (au cours des 30 derniers jours)
Nimrod Daniel
Nimrod Daniel le 3 Jan 2014
Modifié(e) : Patrik Ek le 7 Jan 2014
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 commentaire
Nimrod Daniel
Nimrod Daniel le 4 Jan 2014
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

Connectez-vous pour commenter.

Réponses (1)

Patrik Ek
Patrik Ek le 7 Jan 2014
Modifié(e) : Patrik Ek le 7 Jan 2014
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

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by