Numerical integration of a subfunction
古いコメントを表示
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 件)
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
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!